Example #1
0
 public void AddUser(User user)
 {
     _userRepository.AddUser(user);
 }
Example #2
0
 public void AddUser(User user)
 {
     GetContext().User.Add(user);
     GetContext().SaveChanges();
 }
Example #3
0
        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");
        }
Example #4
0
        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);
        }
Example #5
0
 // 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!");
         }
     }
 }