예제 #1
0
        public void ValidatePassword(User user, string password)
        {
            var isValid = passwordManager.ValidatePassword(user, password);

            if (!isValid)
            {
                throw new AuthenticationFailed();
            }
        }
        /// <summary>
        ///     Аутентификация
        /// </summary>
        public void Login(LoginViewModel loginModel, bool remember = true)
        {
            var user = _identityRepository.Find(x => x.Email == loginModel.Email);

            if (user != null)
            {
                // Проверка пароля
                if (!_passwordManager.ValidatePassword(loginModel.Password, user.Password))
                {
                    return;
                }

                var userIdentity = user.CreateUserIdentity();

                Logout();

                var authenticationProperties = new AuthenticationProperties
                {
                    IsPersistent = remember
                };

                _authenticationManager.SignIn(authenticationProperties, userIdentity);
            }
        }