62,047
社区成员
发帖
与我相关
我的任务
分享
@model Zjgcxx.Model.Web_User
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>修改密码</title>
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
});
function chkFrm() {
var pasw0 = $("#txtPassword").val();
var pasw1 = $("#txtPasw1").val();
var pasw2 = $("#txtPasw2").val();
if (pasw0 == "") {
alert("请输入原密码!");
$("#txtPassword").focus();
return false;
}
if (pasw1.length < 3) {
alert("新密码长度不足!");
$("#txtPasw1").focus();
return false;
}
if (pasw1 != pasw2) {
alert("新密码不一致!");
$("#txtPasw2").focus();
return false;
}
return true;
}
</script>
</head>
<body>
<center>
<br /><p style="font-size:18px; font-weight:bold;">修 改 密 码</p><br />
@using (Html.BeginForm("ChangePassword", "AdminUser", FormMethod.Post, new { id = "frm1" }))
{
@Html.ValidationSummary()
@*@Html.HiddenFor(model => model.user_id)*@
<table border="1" cellpadding="0" cellspacing="0" class="TabStyle" width="500">
<tr><td style="width:80px;">原 密 码:</td>
<td>@Html.Password("txtPassword", "", new { style = "width:200px;" })
@Html.ValidationMessage("txtPassword")
</td>
</tr>
<tr><td>新 密 码:</td>
<td>@Html.Password("txtPasw1", "", new { style = "width:200px;" })
@Html.ValidationMessage("txtPasw1")
</td>
</tr>
<tr><td>确认密码:</td>
<td>@Html.Password("txtPasw2", "", new { style = "width:200px;" })
@Html.ValidationMessage("txtPasw2")
</td>
</tr>
</table>
<br />
<input type="submit" value="提 交" @*onclick="return chkFrm();"*@
style="width:70px;" class="button0" onmouseover="this.className='button0_on'" onmouseout="this.className='button0'" />
}
<br />
</center>
</body>
</html>
Cotroller:
public ActionResult ChangePassword()
{
Web_User uModel = getLandUser();
return View(uModel);
}
[HttpPost]
public ViewResult saveChange()
{
string userid = Request["user_id"];
string oldPasw = Request["txtPassword"];
string newPasw1 = Request["txtPasw1"];
string newPasw2 = Request["txtPasw2"];
oldPasw = Tools.ToMD5(oldPasw);
Web_User uModel = null;
#region
if (newPasw1.Length < 3)
{
ModelState.AddModelError("txtPasw1", "密码长度必须大于3个字符~~");
}
if (ModelState.IsValid)
{
return View("Thanks.");
}
else
{
return View();
}
if (!newPasw1.Equals(newPasw2))
{
ModelState.AddModelError("txtPasw2", "新密码不一致~~");
return View();
}
if (userid != null)
{
uModel = userBLL.Get(userid);
if (uModel != null)
{
if (oldPasw != uModel.user_pasw)
{
ModelState.AddModelError("txtPassword", "原密码不正确~~");
return View();
}
else
{
newPasw1 = Tools.ToMD5(newPasw1);
uModel.user_pasw = newPasw1;
int flag = userBLL.Update(uModel);
if (flag > 0)
{
ModelState.AddModelError("lbMsg", "密码修改成功!");
return View();
}
}
}
else
{
ModelState.AddModelError("lbMsg", "用户身份无效~~");
return View();
}
}
else
{
ModelState.AddModelError("lbMsg", "用户身份无效~~");
return View();
}
#endregion
return View();
}
<body>
@using (Html.BeginForm()) {
@Html.ValidationSummary()
<p>Your name: @Html.Password("name") </p>
@Html.ValidationMessage("name")
<input type="submit" value="Submit RSVP" />
}
</body>
[HttpPost]
public ViewResult RsvpForm(string name)
{
if (string.IsNullOrEmpty(name))
{
ModelState.AddModelError("name", "Please enter your name");
}
if (ModelState.IsValid)
{
return View("Thanks");
}
else
{
// there is a validation error - redisplay the form
return View();
}
}