Ejemplo n.º 1
0
 public void AddUser(User user)
 {
     _userRepository.AddUser(user);
 }
Ejemplo n.º 2
0
 public void AddUser(User user)
 {
     GetContext().User.Add(user);
     GetContext().SaveChanges();
 }
Ejemplo n.º 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");
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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!");
         }
     }
 }