本文整理汇总了C#中UserModel.IsValid方法的典型用法代码示例。如果您正苦于以下问题:C# UserModel.IsValid方法的具体用法?C# UserModel.IsValid怎么用?C# UserModel.IsValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserModel
的用法示例。
在下文中一共展示了UserModel.IsValid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SavePasswordInfo
public ActionResult SavePasswordInfo(UserModel.User user)
{
if (ModelState.IsValid)
{
if (user.IsValid(User.Identity.Name, user.BillingPasswordOriginal))
{
//Pass Authentication
var regexItem = new Regex(@"\d");
if (user.BillingPassword != user.BillingPasswordTwo)
{
//Passwords Don't Match
ModelState.AddModelError("BillingPassword", "Passwords do not match");
}
else if (user.BillingPassword.Length < 6)
{
//Passwords Too Short
ModelState.AddModelError("BillingPassword", "Password must be at least 6 characters in length");
}
else if (!regexItem.IsMatch(user.BillingPassword))
{
//Passwords do not contain number
ModelState.AddModelError("BillingPassword", "Password must contain at least one number");
}
else
{
//Change password
if (!user.UpdatePassword(User.Identity.Name, user.BillingPassword))
{
//Fail
return RedirectToAction("Error", "User");
}
}
}
else
{
//Fail Authentication
ModelState.AddModelError("BillingPasswordOriginal", "Password is incorrect");
}
}
TempData["ViewData"] = ViewData;
return RedirectToAction("AccountDashboard", "User", new { ADPW = "PasswordInfo" });
}
示例2: Login
public ActionResult Login(UserModel.User user)
{
if (ModelState.IsValid)
{
if (user.IsValid(user.UserName, user.Password))
{
FormsAuthentication.SetAuthCookie(user.UserName, user.RememberMe);
if (user.RememberMe)
{
HttpCookie userNameCookie = new HttpCookie("QueueViewUserName");
DateTime now = DateTime.Now;
userNameCookie.Value = user.UserName;
userNameCookie.Expires = now.AddDays(30);
Response.Cookies.Add(userNameCookie);
}
else
{
HttpCookie userNameCookie = new HttpCookie("QueueViewUserName");
DateTime now = DateTime.Now;
userNameCookie.Value = user.UserName;
userNameCookie.Expires = now.AddDays(-1D);
Response.Cookies.Add(userNameCookie);
}
return RedirectToAction("Queue", "SMS");
}
else
{
ModelState.AddModelError("", "Username or Password is incorrect");
}
}
return View(user);
}