Listing J
Imports System.Web.Security
 
 
Public Class LoginForm
    Inherits System.Web.UI.Page
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents btnBack As System.Web.UI.WebControls.Button
    Protected WithEvents Label3 As System.Web.UI.WebControls.Label
    Protected WithEvents txtUserName As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtPassword As System.Web.UI.WebControls.TextBox
    Protected WithEvents btnLogin As System.Web.UI.WebControls.Button
    Protected WithEvents btnNewUser As System.Web.UI.WebControls.Button
    Protected WithEvents rfvUserName As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents rfvPassword As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents lblResult As System.Web.UI.WebControls.Label
    Protected WithEvents Label2 As System.Web.UI.WebControls.Label
 
 
#Region " Web Form Designer Generated Code "
 
 
    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
 
 
    End Sub
 
 
    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub
 
 
#End Region
 
 
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
    End Sub
 
 
 
 
    '#########################################################################################################################
    ' Provide a link for new users to signup if they don't have an account
    '#########################################################################################################################
    Private Sub btnNewUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewUser.Click
        Server.Transfer(WebPageNames.CREATE_CUSTOMER)
    End Sub
 
 
 
 
    '#########################################################################################################################
    ' Upon login, the customer info is verified. If they came to this login page by requesting a secured page, they are
    ' redirected to the page they tried to access, otherwise they are taken to the default view cart page
    '#########################################################################################################################
    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        Try
            ' Validate the login credentials
            Dim CustObj As New CustomerServices()
            Dim CustDs As DataSet = CustObj.CustomerExists(Me.txtUserName.Text, Me.txtPassword.Text)
 
 
            If Not CustDs Is Nothing Then
                ' Place their Pk into the session for later usage
                Dim SessionObj As ClientSession = CType(Session.Item(ClientSession.CLIENT_SESSION_REF), ClientSession)
                SessionObj.CustomerId = Convert.ToInt32(CustDs.Tables(0).Rows(0).Item(CustomerDb.FIELD_CUSTOMER_ID))
                SessionObj.FirstName = CustDs.Tables(0).Rows(0).Item(CustomerDb.FIELD_FIRST_NAME).ToString()
                SessionObj.LastName = CustDs.Tables(0).Rows(0).Item(CustomerDb.FIELD_LAST_NAME).ToString()
                SessionObj.Email = CustDs.Tables(0).Rows(0).Item(CustomerDb.FIELD_EMAIL).ToString()
 
 
                ' If the user came from the public area
                If FormsAuthentication.GetRedirectUrl(SessionObj.CustomerId, False).ToLower().EndsWith("default.aspx") Then
                    FormsAuthentication.SetAuthCookie(SessionObj.CustomerId, False)
                   Response.Redirect(WebPageNames.VIEW_CART, False)
                Else
                    ' Redirect them to the private page they were trying to access
                    FormsAuthentication.RedirectFromLoginPage(SessionObj.CustomerId, False)
               End If
            Else
                Me.lblResult.Visible = True
                Me.lblResult.Text = "Invalid login information"
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
End Class