Exemplo n.º 1
0
        public IActionResult Post([FromBody] UserCredentials credentials)
        {
            try
            {
                var user = _database.GetPhotographerByEmail(credentials.email);

                if (user == null)
                {
                    return(StatusCode(401));
                }

                // Check if password is valid
                if (_pwHelper.VerifyHashedPassword(user.hashedPassword, credentials.password) == PasswordVerificationResult.Success)
                {
                    string tokenString = _jwtHelper.CreatePhotographerJWT(credentials.email);

                    return(Ok(new { token = tokenString }));;
                }
                else
                {
                    return(Unauthorized(new { message = "Password provided is wrong" }));
                }
            }
            catch (ArgumentNullException)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, new { message = "Request must contain a password." }));
            }
            catch (Exception err)
            {
                Console.WriteLine(err);
                return(StatusCode(StatusCodes.Status500InternalServerError, new { message = err.ToString() }));
            }
        }