public async Task <dynamic> Register(string data) { string url = $"{baseUrl}/Register"; var result = await _httpService.PostApiResult(url, KeyValuePair.Create(Rsa.PublicKey, RijndaelCrypt.EncryptString(data, Client.ServerKey, Client.ServerIV))); if (result.All(char.IsDigit)) { return(JsonConvert.DeserializeObject <AuthorizeResultEnum>(result)); } else { Client.AccessToken = RijndaelCrypt.DecryptString(JsonConvert.DeserializeObject <string>(result), Client.ServerKey, Client.ServerIV); } return(AuthorizeResultEnum.Ok); }
public ActionResult ForgotPassword(ForgotPasswordViewModel forgotInfo) { try { if (!ModelState.IsValid) { return(View()); } AccountInfo _account = null; string _token; using (AccountRepository Repo = new AccountRepository()) { _account = Repo.GetEmployeeAccountByCompanyEmail(forgotInfo.CompanyEmail); } if (_account == null) { TempData["Msg"] = "<span style='color:red; text-align:center;'>Account does not associate with this email.</span>"; return(RedirectToAction("ForgotPassword", "Auth")); } if (_account.IsFirstTimeLogin == true) { TempData["Msg"] = "<span style='color:red; text-align:center;'>You cannot reset password right now, please check your account creation email.</span>"; return(RedirectToAction("ForgotPassword", "Auth")); } byte[] time = BitConverter.GetBytes(DateTime.UtcNow.ToBinary()); byte[] key = Guid.NewGuid().ToByteArray(); _token = Convert.ToBase64String(time.Concat(key).ToArray()); using (AccountConfirmationRepository Repo = new AccountConfirmationRepository()) { AccountConfirmationInfo _accountConfirmation = null; _accountConfirmation = Repo.GetAccountConfirmationByAccountId(_account.Id); if (_accountConfirmation != null) { Repo.DeleteAccountConfirmation(_accountConfirmation.Id); } _accountConfirmation = new AccountConfirmationInfo(); _accountConfirmation.Token = _token; _accountConfirmation.AccountId = _account.Id; Repo.SaveAccountConfirmation(_accountConfirmation); } List <string> To = new List <string>() { _account.CompanyEmail }; string Subject = "Password Reset Link"; var resetPasswordUrl = Url.Action("Verify", "Auth", new { t = RijndaelCrypt.EncryptString(_token) }, protocol: Request.Url.Scheme); var forgotPasswordUrl = Url.Action("ForgotPassword", "Auth", null, protocol: Request.Url.Scheme); string Body = "Dear " + _account.EmployeeFullName + ", <br/><br/>" + "We heard that you lost your LPS online account password. Sorry about that! <br/><br/>" + "But don’t worry! You can use the following link within the next day to reset your password: <br/><br/>" + "<a href='" + resetPasswordUrl + "' target='_blank'>" + resetPasswordUrl + "</a> <br/><br/>" + "If you don’t use this link within 24 hours, it will expire. To get a new password reset link, visit<br/>" + "<a href='" + forgotPasswordUrl + "' target='_blank'>" + forgotPasswordUrl + " </a> <br/><br/>" + "Thanks,<br/>" + "Logic Powered Solutions"; bool result = EmailSender.Send(Subject, Body, To); if (result) { TempData["Msg"] = "<span style='color:green; text-align:center;'>Request launched, for further processing please check your email.</span>"; } else { TempData["Msg"] = "<span style='color:red; text-align:center;'>Something went wrong! email not sent, please try again later.</span>"; } return(RedirectToAction("ForgotPassword", "Auth")); } catch (Exception ex) { TempData["Msg"] = "<span style='color:red; text-align:center;'>" + ex.Message.ToString() + ".</span>"; return(View()); } }