示例#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() }));
            }
        }
 public IActionResult GetUser(string email)
 {
     try
     {
         Photographer  photographer = _database.GetPhotographerByEmail(email);
         IActionResult response     = Ok(new
         {
             photographer
         });
         return(response);
     }
     catch (Exception err)
     {
         Console.WriteLine(err.ToString());
         return(StatusCode(500));
     }
 }