home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / login.aspx.vb < prev    next >
Text File  |  2012-02-04  |  9KB  |  316 lines

  1. Imports System.Data
  2. Imports System.Data.Common
  3. Imports System.Xml
  4. Imports System.IO
  5. Imports System.Data.OleDb
  6.  
  7. '
  8. ' ASP.NET code-behind class (Page)
  9. '
  10.  
  11. Partial Class _login
  12.     Inherits AspNetMaker7_tfpssnet
  13.  
  14.     ' Page object
  15.     Public login As clogin
  16.  
  17.     '
  18.     ' Page Class
  19.     '
  20.     Class clogin
  21.         Inherits AspNetMakerPage
  22.         Implements IDisposable        
  23.  
  24.         ' Used by system generated functions
  25.         Private RsWrk As Object, sSqlWrk As String, sWhereWrk As String
  26.  
  27.         Private arwrk As Object
  28.  
  29.         Private armultiwrk() As String        
  30.  
  31.         ' Page URL
  32.         Public ReadOnly Property PageUrl() As String
  33.             Get
  34.                 Dim Url As String = ew_CurrentPage() & "?"
  35.                 Return Url    
  36.             End Get
  37.         End Property
  38.  
  39.         ' Validate page request
  40.         Public Function IsPageRequest() As Boolean
  41.             Return True            
  42.         End Function    
  43.  
  44.         ' tblEmployees
  45.         Public Property tblEmployees() As ctblEmployees
  46.             Get                
  47.                 Return ParentPage.tblEmployees
  48.             End Get
  49.             Set(ByVal v As ctblEmployees)
  50.                 ParentPage.tblEmployees = v    
  51.             End Set    
  52.         End Property    
  53.  
  54.         '
  55.         '  Constructor
  56.         '  - init objects
  57.         '  - open connection
  58.         '
  59.         Public Sub New(ByRef APage As AspNetMaker7_tfpssnet)                
  60.             m_ParentPage = APage
  61.             m_Page = Me    
  62.             m_PageID = "login"
  63.             m_PageObjName = "login"
  64.             m_PageObjTypeName = "clogin"
  65.  
  66.             ' Initialize table object
  67.             tblEmployees = New ctblEmployees(Me)
  68.  
  69.             ' Connect to database
  70.             Conn = New cConnection()
  71.         End Sub
  72.  
  73.         '
  74.         '  Subroutine Page_Init
  75.         '  - called before page main
  76.         '  - check Security
  77.         '  - set up response header
  78.         '  - call page load events
  79.         '
  80.         Public Sub Page_Init()
  81.             Security = New cAdvancedSecurity(Me)
  82.  
  83.             ' Global page loading event (in ewglobal*.vb)
  84.             ParentPage.Page_Loading()
  85.  
  86.             ' Page load event, used in current page
  87.             Page_Load()
  88.         End Sub
  89.  
  90.         '
  91.         '  Class terminate
  92.         '  - clean up page object
  93.         '
  94.         Public Sub Dispose() Implements IDisposable.Dispose
  95.             Page_Terminate("")
  96.         End Sub
  97.  
  98.         '
  99.         '  Sub Page_Terminate
  100.         '  - called when exit page
  101.         '  - clean up connection and objects
  102.         '  - if URL specified, redirect to URL
  103.         '
  104.         Sub Page_Terminate(url As String)
  105.  
  106.             ' Page unload event, used in current page
  107.             Page_Unload()
  108.  
  109.             ' Global page unloaded event (in ewglobal*.vb)
  110.             ParentPage.Page_Unloaded()
  111.  
  112.             ' Close connection
  113.             Conn.Dispose()
  114.             Security = Nothing
  115.             tblEmployees.Dispose()
  116.  
  117.             ' Go to URL if specified
  118.             If url <> "" Then
  119.                 HttpContext.Current.Response.Clear()
  120.                 HttpContext.Current.Response.Redirect(url)
  121.             End If
  122.         End Sub
  123.  
  124.     Public sUsername As String
  125.  
  126.     Public sLoginType As String
  127.  
  128.     '
  129.     ' Page main processing
  130.     '
  131.     Sub Page_Main()
  132.         Dim bValidate As Boolean, bValidPwd As Boolean
  133.         Dim sPassword As String
  134.         Dim sLastUrl As String = Security.LastUrl ' Get last URL
  135.         If ew_Empty(sLastUrl) Then sLastUrl = "default.aspx"
  136.         If Not Security.IsLoggedIn() Then Security.AutoLogin()
  137.         Security.LoadUserLevel() ' Load user level
  138.         If HttpContext.Current.Request.RequestType = "POST" Then
  139.  
  140.             ' Setup variables
  141.                 sUsername = ew_Post("Username")
  142.                 If IsNumeric(sUsername) Then
  143.                     Dim sb As New AspNetMaker7_tfpssnet
  144.                     sUsername = sb.tlcGetEmployeeUsername(CLng(sUsername))
  145.                 End If
  146.             sPassword = ew_Post("Password")
  147.             sLoginType = ew_Post("rememberme").ToLower()
  148.             bValidate = ValidateForm(sUsername, sPassword)
  149.             If Not bValidate Then
  150.                 Message = ParentPage.gsFormError
  151.             End If
  152.         Else
  153.             If Security.IsLoggedIn() Then
  154.                 If Message = "" Then Page_Terminate(sLastUrl) ' Return to last accessed page
  155.             End If
  156.             bValidate = False
  157.  
  158.             ' Restore settings
  159.             sUsername = ew_Cookie("username")
  160.             If ew_Cookie("autologin") = "autologin" Then
  161.                 sLoginType = "a"
  162.             ElseIf ew_Cookie("autologin") = "rememberusername" Then
  163.                 sLoginType = "u"
  164.             Else
  165.                 sLoginType = ""
  166.             End If
  167.         End If
  168.         If bValidate Then
  169.             bValidPwd = False
  170.  
  171.             ' loggin in event
  172.             bValidate = User_LoggingIn(sUsername, sPassword)
  173.             If bValidate Then
  174.                 bValidPwd = Security.ValidateUser(sUsername, sPassword)
  175.                 If Not bValidPwd Then Message = "Incorrect user ID or password" ' Invalid user id/password
  176.             Else
  177.                 If Message = "" Then Message = "Login cancelled" ' Login cancelled
  178.             End If
  179.  
  180.             ' Write cookies
  181.             If bValidPwd Then
  182.                 If sLoginType = "a" Then ' Auto login
  183.                     ew_Cookie("autologin") = "autologin" ' Set up autologin cookies
  184.                     ew_Cookie("username") = sUsername ' Set up user name cookies
  185.                     ew_Cookie("password") = cTEA.Encrypt(sPassword, EW_RANDOM_KEY) ' Set up password cookies
  186.                     HttpContext.Current.Response.Cookies(EW_PROJECT_NAME).Expires = DateAdd("d", 365, Today()) ' Change the expiry date of the cookies here
  187.                 ElseIf sLoginType = "u" Then ' Remember user name
  188.                     ew_Cookie("autologin") = "rememberusername" ' Set up remember user name cookies
  189.                     ew_Cookie("username") = sUsername ' Set up user name cookies
  190.                     HttpContext.Current.Response.Cookies(EW_PROJECT_NAME).Expires = DateAdd("d", 365, Today()) ' Change the expiry date of the cookies here
  191.                 Else
  192.                     ew_Cookie("autologin") = "" ' Clear autologin cookies
  193.                 End If
  194.  
  195.                 ' User_LoggedIn event
  196.                 User_LoggedIn(sUsername)
  197.                     '    Page_Terminate(sLastUrl) ' Return to last accessed url
  198.                     If ew_Session("tfpssnet_Status_UserLevel") = -1 Then
  199.                         Page_Terminate("tblSchedulelist.aspx?t=tblSchedule&z_schDate=%3E%3D&x_schDate=" & Today & "&v_schDate=AND&w_schDate=%3C%3D&y_schDate=" & Today & "&z_schEvtID=%3D&x_schEvtID=&z_schLocID=%3D&x_schLocID=&z_schEmpID=%3D&x_schEmpID=&z_schStatus=%3D&x_schStatus=&Submit=Submit")
  200.                     Else
  201.                         Dim tlcsub As New AspNetMaker7_tfpssnet
  202.                         If tlcsub.tlcGetUnRecCount(sUsername) > 0 Then
  203.                             Message = "You have Un-confirmed shifts.  Please Confirm your Unconfirmed shifts."
  204.                             Page_Terminate("viewScheduleList.aspx?t=viewSchedule&z_schDate=%3E%3D&x_schDate=" & Today & "&v_schDate=AND&w_schDate=%3C%3D&y_schDate=&z_schEvtID=%3D&x_schEvtID=&z_schLocID=%3D&x_schLocID=&z_schEmpID=%3D&x_schEmpID=38&z_schStatus=%3D&x_schStatus=2&Submit=Submit")
  205.                         Else
  206.                             Page_Terminate("viewClockInOutlist.aspx")
  207.                         End If
  208.  
  209.                     End If
  210.                 Else
  211.  
  212.                     ' user login error event
  213.                     User_LoginError(sUsername, sPassword)
  214.                 End If
  215.             End If
  216.     End Sub
  217.  
  218.     '
  219.     ' Validate form
  220.     '
  221.     Function ValidateForm(usr As String, pwd As String) As Boolean
  222.  
  223.         ' Initialize
  224.         ParentPage.gsFormError = ""
  225.  
  226.         ' Check if validation required
  227.         If Not EW_SERVER_VALIDATE Then Return True ' Skip
  228.         If usr = "" Then
  229.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  230.             ParentPage.gsFormError = ParentPage.gsFormError & "Please enter user ID"
  231.         End If
  232.         If pwd = "" Then
  233.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  234.             ParentPage.gsFormError = ParentPage.gsFormError & "Please enter password"
  235.         End If
  236.  
  237.         ' Return validate result
  238.         ValidateForm = (ParentPage.gsFormError = "")
  239.  
  240.         ' Form_CustomValidate event
  241.         Dim sFormCustomError As String = ""
  242.         ValidateForm = ValidateForm And Form_CustomValidate(sFormCustomError)
  243.         If sFormCustomError <> "" Then
  244.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  245.             ParentPage.gsFormError = ParentPage.gsFormError & sFormCustomError
  246.         End If
  247.     End Function
  248.  
  249.         ' Page Load event
  250.         Public Sub Page_Load()
  251.  
  252.             'HttpContext.Current.Response.Write("Page Load")
  253.         End Sub
  254.  
  255.         ' Page Unload event
  256.         Public Sub Page_Unload()
  257.  
  258.             'HttpContext.Current.Response.Write("Page Unload")
  259.         End Sub
  260.  
  261.     ' User Logging In event
  262.     Public Function User_LoggingIn(usr As String, pwd As String) As Boolean
  263.  
  264.         ' Enter your code here
  265.         ' To cancel, set return value to False
  266.  
  267.         Return True
  268.     End Function
  269.  
  270.     ' User Logged In event
  271.     Public Sub User_LoggedIn(usr As String)
  272.  
  273.         'HttpContext.Current.Response.Write("User Logged In")
  274.     End Sub
  275.  
  276.     ' User Login Error event
  277.     Public Sub User_LoginError(usr As String, pwd As String)
  278.  
  279.         'HttpContext.Current.Response.Write("User Login Error")
  280.     End Sub
  281.  
  282.     ' Form Custom Validate event
  283.     Public Function Form_CustomValidate(ByRef CustomError As String) As Boolean
  284.  
  285.         'Return error message in CustomError
  286.         Return True
  287.     End Function
  288.     End Class
  289.  
  290.     '
  291.     ' ASP.NET Page_Load event
  292.     '
  293.  
  294.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  295.         Response.Buffer = EW_RESPONSE_BUFFER
  296.         Response.Cache.SetCacheability(HttpCacheability.NoCache)
  297.  
  298.         ' Page init
  299.         login = New clogin(Me)        
  300.         login.Page_Init()
  301.  
  302.         ' Page main processing
  303.         login.Page_Main()
  304.     End Sub
  305.  
  306.     '
  307.     ' ASP.NET Page_Unload event
  308.     '
  309.  
  310.     Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
  311.  
  312.         ' Dispose page object
  313.         If login IsNot Nothing Then login.Dispose()
  314.     End Sub
  315. End Class
  316.