public async Task <IActionResult> SetPassword(SetPasswordVM model) { if (!ModelState.IsValid) { return(View(model)); } var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var addPasswordResult = await _userManager.AddPasswordAsync(user, model.NewPassword); if (!addPasswordResult.Succeeded) { AddErrors(addPasswordResult); return(View(model)); } await _signInManager.SignInAsync(user, isPersistent : false); StatusMessage = "Your password has been set."; return(RedirectToAction(nameof(SetPassword))); }
public async Task <ActionResult> ConfirmEmail(SetPasswordVM model, string userId) { // check if there were any errors if (ModelState.IsValid) { // Find the user which email was confirmed in the GET method var user = await UserManager.FindByIdAsync(userId); // Check the database to check if the user exists and email is confirmed, if false redirect to different page with error msg if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id))) { TempData["ErrorMsg"] = "Something went wrong, please contact an admin"; return(RedirectToAction("ForgotPassword", "Account")); } // Save the user's password from the model after email was confirmed and form submitted var result = await UserManager.AddPasswordAsync(user.Id, model.Password); // If above succeeded, redirect the user to login page if (result.Succeeded) { TempData["SuccessMsg"] = "Password set successfully, you may login"; return(RedirectToAction("Login", "Account")); } // If above failed, show error message on the current page TempData["ErrorMsg"] = "Something went wrong, please contact an admin"; } return(View(model)); }
public Result SetPassword(SetPasswordVM model) { if (_requestInfo.UserName == model.NewPassword) { return(Result.Failure(message: "نام کاربری و رمز عبور یکسان است")); } if (model.OldPassword == model.NewPassword) { return(Result.Failure(message: "کلمه عبور جدید نباید با کلمه عبور قبلی یکسان باشد")); } var userID = Guid.Empty; if (_requestInfo.UserId != null) { userID = (Guid)_requestInfo.UserId; } else { userID = model.UserID; } var userResult = _dataSource.Get(userID, null, model.OldPassword.HashText(), null, UserType.Unknown); if (!userResult.Success) { return(Result <User> .Failure()); } if (userResult.Data.ID == Guid.Empty) { return(Result.Failure(message: "کلمه عبور فعلی اشتباه است")); } model.NewPassword = model.NewPassword.HashText(); return(_dataSource.SetPassword(model)); }
public IHttpActionResult SetPassword(SetPasswordVM model) { try { var result = _service.SetPassword(model); return(Ok(result)); } catch (Exception e) { return(NotFound()); } }
public async Task <IActionResult> SetPassword() { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var hasPassword = await _userManager.HasPasswordAsync(user); if (hasPassword) { return(RedirectToAction(nameof(ChangePassword))); } var model = new SetPasswordVM { StatusMessage = StatusMessage }; return(View(model)); }
public Result SetPassword(SetPasswordVM model) { try { using (SqlConnection con = new SqlConnection(SQLHelper.GetConnectionString())) { SqlParameter[] param = new SqlParameter[3]; param[0] = new SqlParameter("@ID", _requestInfo.UserId); param[1] = new SqlParameter("@Password", model.NewPassword); param[2] = new SqlParameter("@PasswordExpireDate", DateTime.Now); int i = SQLHelper.CheckIntNull(SQLHelper.ExecuteScalar(con, CommandType.StoredProcedure, "org.spSetUserPassword", param)); if (i > 0) { return(Result.Successful(message: "تغییر رمز عبور با موفقیت انجام گرفت")); } else { return(Result.Failure(message: "خطایی رخ داده است")); } } } catch (Exception e) { throw; } }
public async Task<JsonResult> SetPassword(SetPasswordVM model) { if (ModelState.IsValid) { var result = await _userService.SetPassword(model.UserId, model.NewPassword); if (result.Succeeded) { return Json(true, JsonRequestBehavior.DenyGet); } } return Json(false, JsonRequestBehavior.DenyGet); }