Untitled
unknown
vbscript
a year ago
4.4 kB
7
Indexable
<HttpPost>
Public Function SendOTP(ByVal phoneNumber As String, ByVal mailstr As String, ByVal channel As String) As JsonResult
Dim accountSid As String = ConfigurationManager.AppSettings("TwilioAccountSID")
Dim authToken As String = ConfigurationManager.AppSettings("TwilioAuthToken")
Dim serviceSid As String = ConfigurationManager.AppSettings("TwilioVerifyServiceSID")
Dim _db As New passusEntitieslocal
Dim tempPhoneNumber = Replace(Replace(Replace(phoneNumber, "-", ""), "(", ""), ")", "")
Dim phoneNumberPrefix = chkPhoneNumber(tempPhoneNumber, "")
Dim db = "", fdid = "", usrwebPhone = "", phoneToSend = ""
Dim usr As List(Of usrweb) = _db.usrweb.Where(Function(u) u.email = mailstr).ToList
If usr.Count = 0 Then
Return Json(New With {.status = "failed", .message = "Failed to send OTP."}, JsonRequestBehavior.AllowGet)
End If
For Each oneUsrweb In usr
usrwebPhone = chkPhoneNumber(oneUsrweb.PhoneNum, oneUsrweb.EmailToText)
If phoneNumberPrefix = usrwebPhone Then
db = oneUsrweb.dname
fdid = oneUsrweb.fdid
phoneToSend = usrwebPhone
End If
Next
If phoneToSend = "" Then
Return Json(New With {.status = "failed", .message = "Failed to send OTP."}, JsonRequestBehavior.AllowGet)
End If
TwilioClient.Init(accountSid, authToken)
Try
Dim verification = VerificationResource.Create(
to:=IIf(channel = "sms", phoneToSend, mailstr),
channel:=IIf(channel = "sms", "sms", "email"),
pathServiceSid:=serviceSid
)
If verification.Status = "pending" Then
logSMS(db, fdid, "Your FireWorks verification code is: SECRET_CODE. This code will expire in 10 minutes.", IIf(channel = "sms", phoneToSend, mailstr), "Request OTP Twilio Verify")
Return Json(New With {.status = "success", .message = "OTP sent successfully."}, JsonRequestBehavior.AllowGet)
Else
Return Json(New With {.status = "failed", .message = "Failed to send OTP."}, JsonRequestBehavior.AllowGet)
End If
Catch ex As Exception
If ex.Message = "Max send attempts reached" Then
Return Json(New With {.status = "success", .message = ex.Message}, JsonRequestBehavior.AllowGet)
End If
Return Json(New With {.status = "error", .message = ex.Message}, JsonRequestBehavior.AllowGet)
End Try
End Function
<HttpPost>
Public Function VerifyOTP(ByVal phoneNumber As String, ByVal mailstr As String, ByVal channel As String, ByVal code As String) As ActionResult
Dim accountSid As String = ConfigurationManager.AppSettings("TwilioAccountSID")
Dim authToken As String = ConfigurationManager.AppSettings("TwilioAuthToken")
Dim serviceSid As String = ConfigurationManager.AppSettings("TwilioVerifyServiceSID")
Dim _db As New passusEntitieslocal
Dim tempPhoneNumber = Replace(Replace(Replace(phoneNumber, "-", ""), "(", ""), ")", "")
Dim phoneNumberPrefix = chkPhoneNumber(tempPhoneNumber, "")
Dim db = "", fdid = "", usrwebPhone = "", phoneToSend = ""
Dim usr As List(Of usrweb) = _db.usrweb.Where(Function(u) u.email = mailstr).ToList
If usr.Count = 0 Then
Return Json(New With {.status = "failed", .message = "Failed to send OTP."}, JsonRequestBehavior.AllowGet)
End If
TwilioClient.Init(accountSid, authToken)
Try
Dim verificationCheck = VerificationCheckResource.Create(
to:=IIf(channel = "sms", phoneNumberPrefix, mailstr),
code:=code,
pathServiceSid:=serviceSid
)
If verificationCheck.Status = "approved" Then
For Each oneUsrweb In usr
usrwebPhone = chkPhoneNumber(oneUsrweb.PhoneNum, oneUsrweb.EmailToText)
oneUsrweb.tempPass = MD5Hash(CStr(code))
oneUsrweb.dtforpass = Now()
Next
_db.SaveChanges()
Dim log As New login With {.usernameotp = mailstr, .passotp = code, .remme = "on"}
Return RedirectToAction("IndexV3", log)
Else
Return Json(New With {.status = "failed", .message = "Verification failed."}, JsonRequestBehavior.AllowGet)
End If
Catch ex As Exception
Return Json(New With {.status = "error", .message = ex.Message}, JsonRequestBehavior.AllowGet)
End Try
End FunctionEditor is loading...
Leave a Comment