Beispiel #1
0
        public async Task <BLSingleResponse <LoginRespDto> > LoginAsync(LoginDto model)
        {
            var response = new BLSingleResponse <LoginRespDto>();

            //new PasswordHasher<UserDto>().HashPassword(model.Username, pPassword);

            try
            {
                var signInResul = await _accountManager.SignInAsync(model.Username, model.Password, model.RememberMe);

                if (signInResul == SignInResult.Failed)
                {
                    response.Data = new LoginRespDto("Username or Password is invalid.");
                }
                else if (signInResul == SignInResult.TwoFactorRequired)
                {
                    response.Data = new LoginRespDto("This User does not confirmed email or phone.");
                }
                else if (signInResul == SignInResult.LockedOut)
                {
                    response.Data = new LoginRespDto("This User is currently locked out.");
                }
                else
                {
                    var user = await _accountManager.UserManager.FindByNameAsync(model.Username);

                    var role = await _accountManager.GetRoleByUserAsync(user);

                    if (role != null)
                    {
                        var tokenResul = _tokenProvider.GenerateToken(user, role);
                        response.Data = new LoginRespDto {
                            Token = tokenResul.Token, ExpirationDate = tokenResul.ExpirationDate
                        };
                    }
                    else
                    {
                        response.Data = new LoginRespDto("This User has no role assigned.");
                        await _accountManager.SignOutAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                HandleSVCException(response, ex);
            }

            return(response);
        }
Beispiel #2
0
 public async Task LogoutAsync()
 {
     await _accountManager.SignOutAsync();
 }