예제 #1
0
        public async Task <ApiResponse> Login(LoginDto parameters)
        {
            try
            {
                var result = await _signInManager.PasswordSignInAsync(parameters.UserName, parameters.Password, parameters.RememberMe, true);

                // If lock out activated and the max. amounts of attempts is reached.
                if (result.IsLockedOut)
                {
                    _logger.LogInformation("User Locked out: {0}", parameters.UserName);
                    return(new ApiResponse(Status401Unauthorized, "User is locked out!"));
                }

                // If your email is not confirmed but you require it in the settings for login.
                if (result.IsNotAllowed)
                {
                    _logger.LogInformation("User not allowed to log in: {0}", parameters.UserName);
                    return(new ApiResponse(Status401Unauthorized, "Login not allowed!"));
                }

                if (result.Succeeded)
                {
                    _logger.LogInformation("Logged In: {0}", parameters.UserName);
                    return(new ApiResponse(Status200OK, await _userProfileStore.GetLastPageVisited(parameters.UserName)));
                }
            }
            catch (Exception ex)
            {
                _logger.LogInformation("Login Failed: " + ex.Message);
            }

            _logger.LogInformation("Invalid Password for user {0}}", parameters.UserName);
            return(new ApiResponse(Status401Unauthorized, "Login Failed"));
        }
예제 #2
0
        public async Task <ApiResponse> Login(LoginDto parameters)
        {
            try
            {
                var result = await _signInManager.PasswordSignInAsync(parameters.UserName, parameters.Password, parameters.RememberMe, true);

                // If lock out activated and the max. amounts of attempts is reached.
                if (result.IsLockedOut)
                {
                    _logger.LogInformation("Пользователь заблокирован: {0}", parameters.UserName);
                    return(new ApiResponse(Status401Unauthorized, "Пользователь заблокирован!"));
                }

                // If your email is not confirmed but you require it in the settings for login.
                if (result.IsNotAllowed)
                {
                    _logger.LogInformation("Пользователю не разрешено входить: {0}", parameters.UserName);
                    return(new ApiResponse(Status401Unauthorized, "Пользователю не разрешено входить!"));
                }

                if (result.Succeeded)
                {
                    _logger.LogInformation("Вошел: {0}", parameters.UserName);
                    return(new ApiResponse(Status200OK, await _userProfileStore.GetLastPageVisited(parameters.UserName)));
                }
            }
            catch (Exception ex)
            {
                _logger.LogInformation("Вход не удался: " + ex.Message);
            }

            _logger.LogInformation("Неверный пароль для пользователя {0}}", parameters.UserName);
            return(new ApiResponse(Status401Unauthorized, "Вход не удался"));
        }
예제 #3
0
 public async Task <string> GetLastPageVisited(string userName)
 => await _userProfileStore.GetLastPageVisited(userName);