home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / changepwd.aspx.vb < prev    next >
Text File  |  2010-08-24  |  8KB  |  290 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 _changepwd
  12.     Inherits AspNetMaker7_tfpssnet
  13.  
  14.     ' Page object
  15.     Public changepwd As cchangepwd
  16.  
  17.     '
  18.     ' Page Class
  19.     '
  20.     Class cchangepwd
  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 = "changepwd"
  63.             m_PageObjName = "changepwd"
  64.             m_PageObjTypeName = "cchangepwd"
  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.             If Not Security.IsLoggedIn() Then Call Security.AutoLogin()
  83.             If Not Security.IsLoggedIn() Or Security.IsSysAdmin() Then Call Page_Terminate("login.aspx")
  84.             Call Security.LoadCurrentUserLevel("tblEmployees")
  85.  
  86.             ' Global page loading event (in ewglobal*.vb)
  87.             ParentPage.Page_Loading()
  88.  
  89.             ' Page load event, used in current page
  90.             Page_Load()
  91.         End Sub
  92.  
  93.         '
  94.         '  Class terminate
  95.         '  - clean up page object
  96.         '
  97.         Public Sub Dispose() Implements IDisposable.Dispose
  98.             Page_Terminate("")
  99.         End Sub
  100.  
  101.         '
  102.         '  Sub Page_Terminate
  103.         '  - called when exit page
  104.         '  - clean up connection and objects
  105.         '  - if URL specified, redirect to URL
  106.         '
  107.         Sub Page_Terminate(url As String)
  108.  
  109.             ' Page unload event, used in current page
  110.             Page_Unload()
  111.  
  112.             ' Global page unloaded event (in ewglobal*.vb)
  113.             ParentPage.Page_Unloaded()
  114.  
  115.             ' Close connection
  116.             Conn.Dispose()
  117.             Security = Nothing
  118.             tblEmployees.Dispose()
  119.  
  120.             ' Go to URL if specified
  121.             If url <> "" Then
  122.                 HttpContext.Current.Response.Clear()
  123.                 HttpContext.Current.Response.Redirect(url)
  124.             End If
  125.         End Sub
  126.  
  127.     '
  128.     ' Page main processing
  129.     '
  130.     Sub Page_Main()
  131.         If HttpContext.Current.Request.RequestType = "POST" Then
  132.             Dim bPwdUpdated As Boolean = False
  133.             Dim bValidPwd As Boolean
  134.             Dim sEmail As String = ""
  135.  
  136.             ' Setup variables
  137.             Dim sUsername As String = Security.CurrentUserName()
  138.             Dim sOPwd As String = ew_Post("opwd")
  139.             Dim sNPwd As String = ew_Post("npwd")
  140.             Dim sCPwd As String = ew_Post("cpwd")
  141.             If ValidateForm(sOPwd, sNPwd, sCPwd) Then
  142.                 Dim sFilter As String = "(empUsername = '" & ew_AdjustSql(sUsername) & "')"
  143.  
  144.                 ' Set up filter (SQL WHERE clause)
  145.                 ' SQL constructor in tblEmployees class, tblEmployeesinfo.aspx
  146.  
  147.                 tblEmployees.CurrentFilter = sFilter
  148.                 Dim sSql As String = tblEmployees.SQL
  149.                 Dim RsUser As OleDbDataReader = Conn.GetTempDataReader(sSql)
  150.                 Dim RsPwd As New OrderedDictionary
  151.                 If RsUser.Read() Then
  152.                     If EW_CASE_SENSITIVE_PASSWORD Then
  153.                         If EW_MD5_PASSWORD Then
  154.                             bValidPwd = ew_SameStr(MD5(sOPwd), RsUser("empUserPass"))
  155.                         Else
  156.                             bValidPwd = ew_SameStr(sOPwd, RsUser("empUserPass"))
  157.                         End If
  158.                     Else
  159.                         If EW_MD5_PASSWORD Then
  160.                             bValidPwd = ew_SameStr(MD5(sOPwd.ToLower()), RsUser("empUserPass"))
  161.                         Else
  162.                             bValidPwd = ew_SameText(sOPwd.ToLower(), RsUser("empUserPass"))
  163.                         End If
  164.                     End If
  165.                     If bValidPwd Then
  166.                         If Not EW_CASE_SENSITIVE_PASSWORD Then sNPwd = sNPwd.ToLower()                        
  167.                         RsPwd.Add("empUserPass", sNPwd) ' Change Password
  168.                         sEmail = Convert.ToString(RsUser("empEmail"))
  169.                         tblEmployees.Update(RsPwd)
  170.                         bPwdUpdated = True
  171.                     Else
  172.                         Message = "Invalid Password"
  173.                     End If
  174.                 End If
  175.                 If bPwdUpdated Then
  176.  
  177.                     ' Send Email
  178.                     Dim Email As New cEmail
  179.                     Email.Load(HttpContext.Current.Server.MapPath("txt/changepwd.txt"))
  180.                     Email.ReplaceSender(EW_SENDER_EMAIL) ' Replace Sender
  181.                     Email.ReplaceRecipient(sEmail) ' Replace Recipient
  182.                     Email.ReplaceContent("<!--$Password-->", sNPwd)
  183.                     RsPwd = Conn.GetRow(RsUser) ' Get the whole row
  184.                     RsPwd("empUserPass") = sNPwd ' Provide the new readable password for email sending
  185.                     Dim EventArgs As New Hashtable
  186.                     EventArgs.Add("Rs", RsPwd)
  187.                     If Email_Sending(Email, EventArgs) Then
  188.                         Email.Send()
  189.                     End If
  190.                     Message = "Password Changed" ' Set up message
  191.                 Page_Terminate("default.aspx") ' Exit page and clean up
  192.                 End If
  193.                 Conn.CloseTempDataReader()
  194.             Else
  195.                 Message = ParentPage.gsFormError
  196.             End If
  197.         End If
  198.     End Sub
  199.  
  200.     '
  201.     ' Validate form
  202.     '
  203.     Function ValidateForm(opwd As String, npwd As String, cpwd As String) As Boolean
  204.  
  205.         ' Initialize
  206.         ParentPage.gsFormError = ""
  207.  
  208.         ' Check if validation required
  209.         If Not EW_SERVER_VALIDATE Then Return True
  210.         If opwd = "" Then
  211.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  212.             ParentPage.gsFormError = ParentPage.gsFormError & "Please enter old password"
  213.         End If
  214.         If npwd = "" Then
  215.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  216.             ParentPage.gsFormError = ParentPage.gsFormError & "Please enter new password"
  217.         End If
  218.         If npwd <> cpwd Then
  219.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  220.             ParentPage.gsFormError = ParentPage.gsFormError & "Mismatch Password"
  221.         End If
  222.  
  223.         ' Return validate result
  224.         ValidateForm = (ParentPage.gsFormError = "")
  225.  
  226.         ' Form_CustomValidate event
  227.         Dim sFormCustomError As String = ""
  228.         ValidateForm = ValidateForm And Form_CustomValidate(sFormCustomError)
  229.         If sFormCustomError <> "" Then
  230.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  231.             ParentPage.gsFormError = ParentPage.gsFormError & sFormCustomError
  232.         End If
  233.     End Function
  234.  
  235.         ' Page Load event
  236.         Public Sub Page_Load()
  237.  
  238.             'HttpContext.Current.Response.Write("Page Load")
  239.         End Sub
  240.  
  241.         ' Page Unload event
  242.         Public Sub Page_Unload()
  243.  
  244.             'HttpContext.Current.Response.Write("Page Unload")
  245.         End Sub
  246.  
  247.     ' Email Sending event
  248.     Public Function Email_Sending(ByRef Email As cEmail, Args As Hashtable) As Boolean
  249.  
  250.         'HttpContext.Current.Response.Write(Email.AsString())
  251.         'HttpContext.Current.Response.End()
  252.  
  253.         Return True
  254.     End Function
  255.  
  256.     ' Form Custom Validate event
  257.     Public Function Form_CustomValidate(ByRef CustomError As String) As Boolean
  258.  
  259.         'Return error message in CustomError
  260.         Return True
  261.     End Function
  262.     End Class
  263.  
  264.     '
  265.     ' ASP.NET Page_Load event
  266.     '
  267.  
  268.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  269.         Response.Buffer = EW_RESPONSE_BUFFER
  270.         Response.Cache.SetCacheability(HttpCacheability.NoCache)
  271.  
  272.         ' Page init
  273.         changepwd = New cchangepwd(Me)        
  274.         changepwd.Page_Init()
  275.  
  276.         ' Page main processing
  277.         changepwd.Page_Main()
  278.     End Sub
  279.  
  280.     '
  281.     ' ASP.NET Page_Unload event
  282.     '
  283.  
  284.     Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
  285.  
  286.         ' Dispose page object
  287.         If changepwd IsNot Nothing Then changepwd.Dispose()
  288.     End Sub
  289. End Class
  290.