public ActionResult Register(RegisterModel newUser) { if (ModelState.IsValid) { var user = _userService.GetByUserName(newUser.UserName); if (user != null) { ModelState.AddModelError("UserName", "The user name you entered already exists"); return View(newUser); } if (newUser.Password.Contains(newUser.UserName)) { ModelState.AddModelError("", "User name and password can't be equal."); return View(newUser); } var membershipUser = ((UserMembershipProvider)Membership.Provider).CreateUser(newUser); if (membershipUser != null) { if (newUser.Avatar != null) { SetUserAvatar((Guid)membershipUser.ProviderUserKey, newUser.Avatar); } FormsAuthentication.SetAuthCookie(newUser.UserName, false); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", "Eror registration."); return View(newUser); } } return View(newUser); }
public MembershipUser CreateUser(RegisterModel newUser) { var membershipUser = GetUser(newUser.UserName, false); if (membershipUser != null) { return null; } else { var bllUser = Mapper.Map<BllUser>(newUser); bllUser.CreateDate = DateTime.Now; bllUser.Password = Crypto.HashPassword(bllUser.Password); userService.Create(bllUser); membershipUser = GetUser(newUser.UserName, false); return membershipUser; } }