Example #1
0
        public async Task <IActionResult> Login(UserPostLoginDto request)
        {
            var authResponse = await _identityService.LoginAsync(request);

            if (!authResponse.Success)
            {
                return(BadRequest(new AuthFailedResponse {
                    Errors = authResponse.Errors
                }));
            }

            return(Ok(new AuthSuccessResponse {
                Token = authResponse.Token, RefreshToken = authResponse.RefreshToken
            }));
        }
Example #2
0
        public async Task <AuthenticationResult> LoginAsync(UserPostLoginDto request)
        {
            var user = await _userManager.FindByEmailAsync(request.Email);

            if (user == null)
            {
                return(new AuthenticationResult
                {
                    Errors = new[] { "User does not exist" }
                });
            }
            var userValidPassword = await _userManager.CheckPasswordAsync(user, request.Password);

            if (!userValidPassword)
            {
                return(new AuthenticationResult
                {
                    Errors = new[] { "Email or password is wrong" }
                });
            }

            return(await GenerateAuthorizationForUserAsync(user));
        }