public JsonResult Forgot(string id, string Password, string ConfirmPassword) { if (Password == ConfirmPassword) { string dusername = Env.Decrypt(id); var user = _userService.GetAll().FirstOrDefault(i => i.IsActive == false && i.Email == dusername); if (user != null) { user.Password = SecurePwdHasherHelper.Hash(Password); user.ChangePasswordCode = ""; user.IsActive = true; _userService.Update(user); return(Json(new { status = "success", message = "Successfully Reset now you may login" })); } else { return(Json(new { status = "warning", message = "Please re-send request for forget password." })); } } else { return(Json(new { status = "warning", message = "Password are not matached." })); } }
public async Task <IActionResult> Login(LoginViewModel model) { if (ModelState.IsValid) { var(isValid, user) = await _authLoginService.ValidateUserCredentialsAsync(model.UserName); string dbPassword = user.Password.ToString(); bool CheckPassword = false; if (SecurePwdHasherHelper.Verify(model.Password, dbPassword)) { CheckPassword = true; } if (isValid && CheckPassword) { var roleuser = _roleUserService.GetAll().Where(i => i.UserId == user.Id).Select(i => i.RoleId).FirstOrDefault(); var role = _roleService.GetAll().Where(i => i.Id == roleuser).Select(i => i.RoleName).FirstOrDefault(); var setting = _appSettingService.GetAll().FirstOrDefault(); if (roleuser > 0 && role != null) { await LoginAsync(user, roleuser, role, setting); if (IsUrlValid(model.ReturnUrl)) { return(Redirect(model.ReturnUrl)); } return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("RoleNotAssigned", "Role is Not Assigned."); } } else { ModelState.AddModelError("InvalidCredentials", "Invalid credentials."); } } return(View(model)); }
public IActionResult Register([FromForm] User model, string NewPasswordConfirm) { string msg = string.Empty; string msgstatus = string.Empty; if (ModelState.IsValid) { if (!string.IsNullOrEmpty(model.Password) && !string.IsNullOrEmpty(NewPasswordConfirm)) { if (model.Password == NewPasswordConfirm) { model.Password = SecurePwdHasherHelper.Hash(model.Password); _userService.Insert(model); return(Json(new { status = "success", message = "Register Successfully" })); } else { return(Json(new { status = "warning", message = "Confirm password mismatch" })); } } else { return(Json(new { status = "warning", message = "Fill Password Fields" })); } } else { StringBuilder sb = new StringBuilder(); foreach (var key in this.ViewData.ModelState.Keys) { foreach (var err in this.ViewData.ModelState[key].Errors) { sb.Append(err.ErrorMessage + "<br/>"); } } return(Json(new { status = "warning", message = sb.ToString() })); } }