예제 #1
0
        public async Task <ActionResult <string> > Login(User user)
        {
            if (user.Email == null || user.HashedPassword == null)
            {
                return(BadRequest());
            }

            var u = await this._userService.GetUserByEmail(user.Email);

            if (u == null)
            {
                return(NotFound());
            }

            var hashedPassword = PasswordUtil.Decode(user.HashedPassword, u.Salt);

            if (u.HashedPassword == hashedPassword)
            {
                return(TokenUtil.GenerateToken(u, _jwtSettings));
            }

            return(Unauthorized());
        }