B4J Tutorial [ABMaterial] Enabling Users to get their lost passwords via email

Discussion in 'B4J Tutorials' started by Mashiane, May 3, 2017.

  1. Mashiane

    Mashiane Expert Licensed User

    Hi there...

    I wanted users to be able to get their lost passwords via email. This does not reset their passwords but just sends them their passwords to their registered email addresses.

    To enable reseting user passwords by the App administrator, you can see my previous article here. For the app to send the emails, I have used SMTP, you can follow this article here.

    In my Sign In page, in the navigation bar, I have added a link that when selected, will check if the email address is entered, if not prompt a user for one. Once the user email address is entered, the app reads the email account settings that store the SMTP server settings to use, reads the user profile based on the provided email address and then sends the Sign In details for that user.

    ForgotPasswordShow.png

    Top Nav Bar Items are trapped using the Page_NavigationBarClicked event..

    Code:
    Sub Page_NavigationbarClicked(Action As String, Value As String)
        
    page.SaveNavigationBarPosition
        
    If Action = "LogOff" Then
            ABMShared.LogOff(
    page)
            
    Return
        
    End If
        
    Select Case Action.ToLowerCase
        
    Case "signin"
            ExecuteSignIn
            
    Return
        
    Case "forgotpassword"
            ExecuteForgotPassword
            
    Return
        
    Case "goback"
            ExecuteGoBack
            
    Return
        
    End Select
        ABMShared.NavigateToPage(ws, ABMPageId, Value)
    End Sub
    This then runs this code..

    Code:
    Private Sub ForgotPasswordProcess() As Boolean
        
    'define a map to hold the form contents
        Dim m As Map
        
    'read the form contents to a map
        m = GetContents
        
    Dim email As String
        
    email = m.get("email")
        
    If email = "null" Then email = ""
        
    If email.Length = 0 Then
            ABMShared.ShowMsgBox(
    page,"Email cannot be blank. Please enter a value.")
            
    Return False
        
    End If
        
    'the form contents are ok, send login credentials to user
        'define the search criteria, fields must equal
        Dim w As Map
        
    Dim nk As String
        w.Initialize
        nk = 
    "email="
        w.put(nk, 
    email)
        
    'Get connection from current pool if MySQL/MSSQL
        Dim jSQL As SQL = ABMShared.SQLGet
        
    Dim UserMap As Map = ABMShared.SQLSelectRecordWhereMap(jSQL,"drpw_users", w)
        
    If UserMap.IsInitialized = False Then
            ABMShared.ShowMsgBox(
    page,"The Email specified could not be found in our records, please specify the correct email.")
            
    Return False
        
    End If
        
    'The email has been found, send the details to the user
        Dim username As String
        username = UserMap.get(
    "username")
        
    Dim password As String
        password = UserMap.get(
    "password")
        
    Try
            
    ' start smtp to send the emails
            Dim sbody As String = "Good Day||Someone or you requested your Sign In credentials.||Your UserName is: " & username & "||Your Password is: " & password & "||Development Team|"
            sbody = ABMShared.Replace(sbody,
    "|",CRLF)
            SendEmail(jSQL,
    smtp,email"DRPW: Sign In Credentials", sbody)
            
    'Close the connection to the database
            ABMShared.SQLClose(jSQL)
            
    Return True
        
    Catch
            myToastId = myToastId + 
    1
            
    page.ShowToast("toast" & myToastId, "toastred""Email could not be sent, please try again."3000)
            
    Return False
        
    End Try
    End Sub
    The code also enables users to Sign In in your app, check and assign their permissions as discussed in this article.

    That's all for now.
     
    jmon, ihabsharaf, clarionero and 2 others like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice