-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathReset.bas
85 lines (73 loc) · 2.31 KB
/
Reset.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Activity
Version=7.3
@EndOfDesignText@
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: False
#End Region
Sub Process_Globals
End Sub
Sub Globals
Private txtEmail As EditText
Dim strEmail As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("frmReset")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnSubmit_Click
strEmail = txtEmail.Text.Trim
If strEmail = "" Then
Msgbox("Please enter Email", "Error")
Return
End If
If Validate_Email(strEmail) = False Then
Msgbox("Email format is incorrect", "Error")
Return
End If
Dim Job5 As HttpJob
Job5.Initialize("ResetPassword", Me)
Job5.Download2(Main.strURL & "reset-password.php", _
Array As String("Action", "RequestPasswordReset", _
"Mail", strEmail))
ProgressDialogShow("Connecting to server...")
End Sub
Sub JobDone (Job As HttpJob)
ProgressDialogHide
If Job.Success Then
Dim res As String, action As String
res = Job.GetString
Dim parser As JSONParser
parser.Initialize(res)
Select Job.JobName
Case "ResetPassword"
action = parser.NextValue
If action = "ValidEmail" Then
Msgbox("An email was sent to " & strEmail & " to reset your password.", "Reset Password")
Else If action = "InvalidEmail" Then
Msgbox("The email is not registered in our database.", "Reset Password")
End If
End Select
Else
'Log("Error: " & Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
' // Source: http://www.b4x.com/android/forum/threads/validate-a-correctly-formatted-email-address.39803/
Sub Validate_Email(EmailAddress As String) As Boolean
Dim MatchEmail As Matcher = Regex.Matcher("^(?i)[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])$", EmailAddress)
If MatchEmail.Find = True Then
'Log(MatchEmail.Match)
Return True
Else
'Log("Oops, please double check your email address...")
Return False
End If
End Sub