public ActionResult Login(MvcUser model, string returnUrl) { if (ModelState.IsValid) { if (_membershipProviderService.ValidateUser(model.Email, model.Password)) { FormsAuthentication.SetAuthCookie(model.Email, false); if (Url.IsLocalUrl(returnUrl)) { return Redirect(returnUrl); } else { if (_roleService.GetRoleEntity( _userService.GetByPredicate(u => u.Email == model.Email).ToMvcUser().RoleId.GetValueOrDefault()).Name == "admin") { return RedirectToAction("Index", "Home", new { area = "Admin" }); } else { return RedirectToAction("Index", "Home", new {area = "User"}); } } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } return View(model); }
public MembershipUser CreateUser(string name, string email, string password) { MembershipUser membershipUser = GetUser(email, false); if (membershipUser == null) { try { int userRoleId = _roleService.GetAllRoleEntities().First(role => role.Name == "user").Id; MvcUser mvcUser = new MvcUser() { Name = name, Email = email, RoleId = userRoleId, Password = Crypto.HashPassword(password), CreationDate = DateTime.Now }; _userService.CreateUser(mvcUser.ToBllUser()); membershipUser = GetUser(email, false); return membershipUser; } catch { return null; } } return null; }
public ActionResult Register(MvcUser model) { if (ModelState.IsValid) { MembershipUser membershipUser = ((CustomMembershipProvider)_membershipProviderService).CreateUser(model.Name, model.Email, model.Password); if (membershipUser != null) { FormsAuthentication.SetAuthCookie(model.Email, false); return RedirectToAction("Index", "Home", new {area = "User"}); } else { ModelState.AddModelError("", "Ошибка при регистрации"); } } return View(model); }
public ActionResult DeleteConfirmed(MvcUser user) { _userService.DeleteUser(user.ToBllUser()); return RedirectToAction("Index"); }