diff --git a/assets/css/login.css b/assets/css/login.css index 70d1c30..45e83c2 100644 --- a/assets/css/login.css +++ b/assets/css/login.css @@ -278,4 +278,17 @@ body { .conformPassword { margin-top: 30px; +} +.error-warning{ + font-weight:700 ; + color: white; + margin-right: 5px; +} +div#div_ValidationSummary { + background: #ce1717; + color: white; + +} +.p-2{ + padding: 5px; } \ No newline at end of file diff --git a/assets/js/forgotpassword.js b/assets/js/forgotpassword.js index 6bef005..788a028 100644 --- a/assets/js/forgotpassword.js +++ b/assets/js/forgotpassword.js @@ -1,12 +1,147 @@ -function showOtpBox() { - document.getElementById('div_ForgotPswd').style.display = 'none'; - document.getElementById('modal_Otp').style.display = 'block'; +const serverUrl = 'http://localhost:3088/'; +let otpid; +let sendotp; +let unibaseid; +async function showOtpBox() { + let inputdetails = document.getElementById('txt_PhoneorMail').value; + + let sendnumber = await fetch(serverUrl + 'account/getuserbyphoneormail/'+inputdetails+'/'+inputdetails) + let textdata = await sendnumber.json(); + if(textdata.result != null){ + unibaseid = textdata.result.unibaseId; + var myHeaders = new Headers(); + myHeaders.append("Content-Type", "application/json"); + + var raw = JSON.stringify({ + "FirstName": "", + "LastName": "", + "ContactNumber": "", + "Email": "", + "TenantName": "", + "ContactOrEmail": inputdetails, + "IsSignup": false, + "IsRegisterUser": false, + "IsForgotPswd": true, + "UnibaseId": unibaseid, + "OtpId": 0, + "UserOtp": "" + }); + + var requestOptions = { + method: 'POST', + headers: myHeaders, + body: raw, + redirect: 'follow' + }; + + fetch(serverUrl + 'account/sendotp', requestOptions) + .then(response => response.text()) + .then(function(result){ + optid = result; + document.getElementById('div_ForgotPswd').style.display = 'none'; + document.getElementById('modal_Otp').style.display = 'block'; + document.getElementById('div_ValidationSummary').innerHTML = ""; + }) + .catch(error => console.log('error', error)); + } + else{ + let html = '
Error ! Email/Phonenumber does not exist
' ; + document.getElementById('div_ValidationSummary').innerHTML = ""; + let error = document.getElementById('div_ValidationSummary'); + error.insertAdjacentHTML('beforeend',html); + } } -function showPasswordBox() { - document.getElementById('modal_Otp').style.display = 'none'; - document.getElementById('div_ResetPswd').style.display = 'block'; + +/*verify otp*/ + async function showPasswordBox() { + let inputdetails = document.getElementById('txt_Code').value; + if(inputdetails.length > 0){ + var myHeaders = new Headers(); + myHeaders.append("Content-Type", "application/json"); + var raw = JSON.stringify({ + "FirstName": "", + "LastName": "", + "ContactNumber": "", + "Email": "", + "TenantName": "", + "ContactOrEmail": "", + "IsForgotPswd": false, + "IsRegisterUser": false, + "IsSignup": true, + "UnibaseId": "", + "OtpId": optid, + "UserOtp": inputdetails + }); + + var requestOptions = { + method: 'POST', + headers: myHeaders, + body: raw, + redirect: 'follow' + }; + + fetch(serverUrl + 'account/verifyotp', requestOptions) + .then(response => response.text()) + .then(function(result){ + let data = JSON.parse(result); + if(data.result.contactConfirmed == true){ + document.getElementById('modal_Otp').style.display = 'none'; + document.getElementById('div_ResetPswd').style.display = 'block'; + document.getElementById('div_ValidationSummary').innerHTML = ""; + }else{ + let html = '
Error ! Enter Valid OTP
' ; + document.getElementById('div_ValidationSummary').innerHTML = ""; + let error = document.getElementById('div_ValidationSummary'); + error.insertAdjacentHTML('beforeend',html); + } + }) + .catch(error => console.log('error', error)); + }else{ + + } + + + } function showSuccessBox() { - document.getElementById('div_ResetPswd').style.display = 'none'; - document.getElementById('div_SuccessMsg').style.display = 'block'; -} \ No newline at end of file + let txt_NewPassword = document.getElementById('txt_NewPassword').value; + let txt_ConfirmPassword = document.getElementById('txt_ConfirmPassword').value; + if(txt_NewPassword == txt_ConfirmPassword){ + var myHeaders = new Headers(); +myHeaders.append("Content-Type", "application/json"); +var raw = JSON.stringify({ + "Password": txt_NewPassword, + "UserName": unibaseid +}); +var requestOptions = { + method: 'POST', + headers: myHeaders, + body: raw, + redirect: 'follow' +}; +fetch(serverUrl + 'account/updatepassword', requestOptions) + .then(response => response.text()) + .then(function(result){ + let updatepassword = JSON.parse(result); + let message = updatepassword.message; + if(message == 'Password Updated Successfully'){ + document.getElementById('div_ValidationSummary').innerHTML = ""; + document.getElementById('div_ResetPswd').style.display = 'none'; + document.getElementById('div_SuccessMsg').style.display = 'block'; + } + } + ) + .catch(error => console.log('error', error)); + + }else{ + let html = '
Error ! Password Does not Match
' ; + document.getElementById('div_ValidationSummary').innerHTML = ""; + let error = document.getElementById('div_ValidationSummary'); + error.insertAdjacentHTML('beforeend',html); + } + +} + + + +