Esempio n. 1
0
        public async Task <IActionResult> Register([FromBody] UserRegistrationRequest request)
        {
            if (ModelState.IsValid == false)
            {
                return(BadRequest
                       (
                           new AuthFailureResponse
                {
                    Errors = ModelState.Values.SelectMany(v => v.Errors.Select(e => e.ErrorMessage))
                }
                       ));
            }
            var authResult = await _service.RegisterAsync(request.Email, request.Password);

            if (authResult.IsSuccessful == false)
            {
                var failureResult = new AuthFailureResponse
                {
                    Errors = authResult.Errors
                };
                return(BadRequest(failureResult));
            }
            var successResult = new AuthSuccessResponse
            {
                Token        = authResult.Token,
                RefreshToken = authResult.RefreshToken
            };

            return(Ok(successResult));
        }
Esempio n. 2
0
        public async Task <IActionResult> Refresh([FromBody] RefreshTokenRequest request)
        {
            var authResult = await _service.RefreshTokenAsync(request.Token, request.RefreshToken);

            if (authResult.IsSuccessful == false)
            {
                var failureResult = new AuthFailureResponse
                {
                    Errors = authResult.Errors
                };
                return(BadRequest(failureResult));
            }
            var successResult = new AuthSuccessResponse
            {
                Token        = authResult.Token,
                RefreshToken = authResult.RefreshToken
            };

            return(Ok(successResult));
        }