public ActionResult Login(LoginViewModel model, string returnUrl) { var message = string.Empty; var user = new Zs_User(); var identity = new ClaimsIdentity(); if (!ModelState.IsValid) { return View(model); } user = bUser.Login(model.Account); if (user == null) { message = string.Format("账号 {0} 不存在", model.Account); ModelState.AddModelError("Account", message); return View(model); } else if (user.UserStatus != 1) { message = string.Format("账号 {0} 无效", model.Account); ModelState.AddModelError("Account", message); return View(model); } else if (user.Pwd != StringUtil.EncodeString(model.Password, StringUtil.GetPwdKey(user.UserChar.ToString()))) { message = string.Format("密码输入错误"); ModelState.AddModelError("Account", message); return View(model); } identity = bUser.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = model.RememberMe }, identity); if (string.IsNullOrEmpty(returnUrl)) { return RedirectToAction("Index", "Home"); } else if (Url.IsLocalUrl(returnUrl)) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home"); } }
public string Create(UserCreate user) { string msg; try { if (ModelState.IsValid) { Zs_User item = new Zs_User(); item = sysFun.InitialEntity<UserCreate, Zs_User>(user, item); item.UserChar = StringUtil.GetGUID(); item.Pwd = StringUtil.EncodeString(user.Pwd, StringUtil.GetPwdKey(item.UserChar.ToString())); bUser.Add(item); msg = "Saved Successfully"; } else { msg = "Validation data not successfull"; } } catch (Exception ex) { msg = "Error occured:" + ex.Message; } return msg; }