'' asp code Generated by Basic Processor
'' Original Page Name: C:\gmTestBed\FMStocks\src\FMSWeb\ASP\default.asp

Imports System.Web
NameSpace FMSWeb
Public Partial class _default : Inherits System.Web.UI.Page
   Public _t_head1 As FMSWeb._t_head

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      _t_head1 = New FMSWeb._t_head()
   End Sub
   Public msg As String = ""
   Public email As String = ""
   Public password As String = ""
   Public Sub ProcessLogin()
      ' By default, show the page with the default login test account "ta" and password "ta1"
      ' Otherwise, show what the user most recently typed in.
      email = Strings.Trim(HttpContext.Current.Request("login"))
      password = Strings.Trim(HttpContext.Current.Request("password"))
      If (String.IsNullOrEmpty(email)) Then
         VBMath.Randomize()
         email = "ta" & CStr(CInt(VBMath.Rnd() * 1000) + 1)
      End If
      If (String.IsNullOrEmpty(password)) Then
         password = "ta"
      End If
      ' Are we trying to log in?
      If (Not String.IsNullOrEmpty(HttpContext.Current.Request("LoginButton"))) Then
         ' We're on this page because the Login button was pressed.
         ' Attempt to login
         On Error Resume Next
         Dim objAccount As FMStocks_Bus.Account = Nothing
         Dim AccountID As Integer = 0
         Dim FullName As String = ""
         Dim bIsValid As Boolean = False
         objAccount = New FMStocks_Bus.Account
         ' Common deployment error: this error handling block catches the common
         ' case where the FMStocks_Bus component isn't registered on the app server.
         If (Err.Number <> 0) Then
            _t_head1.BuildErrorMessage()
            msg = "<div class=error>" & FMSWeb._strings.CREATE_OBJECT_FAILED & "</div>"
            Exit Sub
         End If
         bIsValid = objAccount.VerifyLogin(email,password,FullName,AccountID)
         objAccount = Nothing
         ' Common database error: if the DSN is incorrect, or the database is down or
         ' not reachable, this is the first place
         If (Err.Number <> 0) Then
            _t_head1.BuildErrorMessage()
            msg = "<div class=error>" & FMSWeb._strings.DATABASE_ERROR & "<p>" & _t_head1.g_strError & "</div>"
            Exit Sub
         End If
         If (bIsValid) Then
            ' Login was successful. Pass back the AccountID in a cookie for later.
            HttpContext.Current.Response.Cookies("Account").Value = Convert.ToString(AccountID)
            HttpContext.Current.Response.Redirect("home.aspx")
         Else
            msg = "<span class=error>" & FMSWeb._strings.LOGIN_PASSWORD_FAILED & "</span><br>"
         End If
      End If
      ' Setup the default message if we're here because a new account was just created
      If (HttpContext.Current.Request("NewAccount") = 1) Then
         msg = "<span class=info>" & FMSWeb._strings.LOGIN_NEWACCOUNT_CREATED & "</span><br>"
         password = ""
      End If
   End Sub
End Class
End Namespace
