internal static BllUser ToBllUser(RegisterModel registermodel) { if (registermodel!=null) return new BllUser() { Email = registermodel.Email, Password = Crypto.HashPassword(registermodel.Password), Name = registermodel.Name, }; return null; }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // 尝试注册用户 try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password); WebSecurity.Login(model.UserName, model.Password); return RedirectToAction("Index", "Home"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // 如果我们进行到这一步时某个地方出错,则重新显示表单 return View(model); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { if (!(accountservice.UserExist(model.Name) && accountservice.UserEmailExist(model.Email))) { var blluser = Maper.ToBllUser(model); blluser.TimeRegister = DateTime.Now; accountservice.CreateUser(blluser); return RedirectToAction("Index", "Home"); } ModelState.AddModelError("", "Пользователь с таким логином или электронной почтой уже существует"); } ModelState.AddModelError("", "Incorrect input data"); return View(model); }