public async Task <ActionResult <AuthLoginResponseDto> > Login([FromBody] AuthLoginResquestDto loginDto)
        {
            loginDto.usernameOrEmail = loginDto.usernameOrEmail.Trim().ToLower();
            loginDto.password        = loginDto.password.Trim();

            var responseDto = new AuthLoginResponseDto();

            try {
                responseDto.JwtToken = await _authService.Login(loginDto.usernameOrEmail, loginDto.password);

                responseDto.Success = true;
            } catch (UserNotFoundException) {
                responseDto.Success = false;
            } catch (IncorrectPasswordException) {
                responseDto.Success = false;
            }

            return(Ok(responseDto));
        }
Beispiel #2
0
        public async Task <ActionResult <JwtAuthResponseDto> > Login([FromBody] AuthLoginResquestDto loginDto)
        {
            loginDto.usernameOrEmail = loginDto.usernameOrEmail.Trim().ToLower();
            loginDto.password        = loginDto.password.Trim();

            var responseDto = new JwtAuthResponseDto();

            try {
                responseDto.JwtToken = await _authService.Login(loginDto.usernameOrEmail, loginDto.password);
            } catch (UserNotFoundException) {
                return(BadRequest(new {
                    message = "User not found"
                }));
            } catch (IncorrectPasswordException) {
                return(BadRequest(new {
                    message = "Incorrect password"
                }));
            }

            return(Ok(responseDto));
        }