public UserModel RegisterUser(UserModel model, string password)
        {
            var userRepository = new UserRepository();
            var salt = BCryptHelper.GenerateSalt();
            var passwordHash = BCryptHelper.HashPassword(password, salt);

            model.Salt = salt;
            model.Password = passwordHash;

            userRepository.Save(model);
            userRepository.Commit();

            return model;
        }
        public async Task<ActionResult> Register(Register model)
        {
            if (ModelState.IsValid)
            {
                var userRepository = new UserRepository();

                var user = userRepository.GetByEmail(model.Email);

                if (user != null ) {
                    RedirectToAction("Register");
                }

                var authService = new AuthServise();

                var userModel = new UserModel {
                    Email = model.Email,
                    Name = model.Email,
                    CreateDate = DateTime.Now
                };

                authService.RegisterUser(userModel, model.Password);

                RedirectToAction("Login");
            }

            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            return View(model);
        }
 public void InitializeCurrentUser(UserModel user)
 {
     var userData = new UserSessionModel { UserModel = user };
     CurrentUser.Info = userData;
 }
 public UserModel Login(UserModel model)
 {
     InitializeCurrentUser(model);
     SaveToCookie();
     return model;
 }
        public AppResult VerifyUser(UserModel user, string pswd)
        {
            if (user == null) {
                return new AppResult {
                    isError = true,
                    Message = "No User"
                };
            }

            var isValidPassword = BCryptHelper.CheckPassword(pswd, user.Password);

            if (!isValidPassword) {
                return new AppResult
                {
                    isError = true,
                    Message = "Password incorrect"
                };
            }

            return new AppResult
            {
                isError = false,
                Message = "Password correct"
            };
        }