protected void btnChangePassword_Click(object sender, EventArgs e) { try { UserSystem usrsys = new UserSystem(); User usr = (User)Session["CurrentUser"]; usrsys.ChangePassword(usr.UserName, txtOldPassword.Text, txtNewPassword.Text); lblError.Visible = false; lblSuccess.Visible = true; lblSuccess.Text = "Zapisano."; } catch (System.Data.SqlClient.SqlException) { lblError.Text = "Wystąpił nieoczekiwany błąd. (SQL)"; lblError.Visible = true; } catch (UserException ue) { string ErrorMssg = ""; switch (ue.Type) { case UserException.UserExceptionType.Unknown: ErrorMssg = "Wystąpił nieoczekiwany błąd."; break; case UserException.UserExceptionType.IncorrectPassword: ErrorMssg = "Niepoprawne hasło."; break; } lblError.Text = ErrorMssg; lblError.Visible = true; } }
public IActionResult Changepwd([FromBody] User user) { if (!JudgeRoles(1)) { return(Json(new { code = -1, msg = "您没有权限修改用户密码!" })); } if (UserSystem.ChangePassword(user)) { AdminSystem.AddLog(GetAdminName(), "修改用户 " + user.Userid + " 的密码"); return(Json(new { code = 0, msg = "密码修改成功" })); } return(Json(new { code = -1, msg = "密码修改失败" })); }