Imports System.Web.Security
Imports ASPNET.StarterKit.TimeTracker.BusinessLogicLayer

Namespace ASPNET.StarterKit.TimeTracker.Mobile
    Public Class SignIn
        Inherits System.Web.UI.MobileControls.MobilePage
        Protected WithEvents Stylesheet1 As System.Web.UI.MobileControls.StyleSheet
        Protected WithEvents LabelSignInTitle As System.Web.UI.MobileControls.Label
        Protected WithEvents Label5 As System.Web.UI.MobileControls.Label
        Protected WithEvents eMailText As System.Web.UI.MobileControls.TextBox
        Protected WithEvents RequiredFieldValidatorEmail As System.Web.UI.MobileControls.RequiredFieldValidator
        Protected WithEvents RegularExpressionValidator1 As System.Web.UI.MobileControls.RegularExpressionValidator
        Protected WithEvents password As System.Web.UI.MobileControls.Label
        Protected WithEvents passwordText As System.Web.UI.MobileControls.TextBox
        Protected WithEvents RequiredfieldvalidatorPassword As System.Web.UI.MobileControls.RequiredFieldValidator
        Protected WithEvents SignIn As System.Web.UI.MobileControls.Command
        Protected WithEvents signInMsg As System.Web.UI.MobileControls.Label
        Protected WithEvents FormSignIn As System.Web.UI.MobileControls.Form

#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

        Private Sub SignIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SignIn.Click
            Dim accountSystem As New TTUser()
            Dim userId As String = accountSystem.Login(eMailText.Text, TTSecurity.Encrypt(passwordText.Text))

            If Not (userId Is Nothing) And userId <> "" Then
                ' Use security system to set the UserID within a client-side Cookie
                FormsAuthentication.SetAuthCookie(eMailText.Text, False)
                ' Redirect browser back to originating page
                RedirectToMobilePage("TimeSheet.aspx")
            Else
                signInMsg.Text = "Login Failed!"
            End If
        End Sub
    End Class
End Namespace