public void AddUser(User user) { _userRepository.AddUser(user); }
public void AddUser(User user) { GetContext().User.Add(user); GetContext().SaveChanges(); }
public PartialViewResult SignUp(SignUpModel signUpModel) { if (ModelState.IsValid) { ValidateSignUpModel(signUpModel); } if (ModelState.IsValid) { User user = new User { Email = signUpModel.Email, First_Name = signUpModel.FirstName, Last_Name = signUpModel.LastName, Username = signUpModel.Username, Password = BCrypt.Net.BCrypt.HashString(signUpModel.Password), IsManager = signUpModel.Username == ManagerName }; _userBlo.AddUser(user); Authorize(user); } return PartialView("_SignUp"); }
private void Authorize(User dbUser) { // Create principal UserPrincipal userPrincipal = new UserPrincipal(dbUser.Username, dbUser.Id, dbUser.IsManager); // Save it to this request and session string principalApplicationKey = Guid.NewGuid().ToString(); UserPrincipal.CurrentPrincipal = userPrincipal; ControllerContext.HttpContext.User = userPrincipal; ControllerContext.HttpContext.Application[principalApplicationKey] = userPrincipal; // Set Forms auth cookie HttpCookie authCookie = GetAuthCookie(userPrincipal, principalApplicationKey); Response.Cookies.Add(authCookie); }
// Verify that user exists and password is right private void ValidateLogInModel(User dbUser, LogInModel logInModel) { if (dbUser == null) { ModelState.AddModelError("Username", "This username doesn't exist"); } else { try { if (!BCrypt.Net.BCrypt.Verify(logInModel.Password, dbUser.Password)) { ModelState.AddModelError("Password", "Password is wrong!"); } } catch (SaltParseException) { ModelState.AddModelError("Password", "Password is wrong!"); } } }