Beispiel #1
0
        public async Task <IActionResult> Login([FromBody] LoginModel loginModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetFirstError()));
            }

            var user = await _userService.GetByEmail(loginModel.Email);

            if (user == null)
            {
                return(BadRequest(ValidationResultMessages.LoginWrongCredentials));
            }

            var result = PasswordHashHelper.VerifyHashedPassword(user.Password, loginModel.Password);

            if (!result || !user.IsAdmin)
            {
                return(BadRequest(ValidationResultMessages.LoginWrongCredentials));
            }

            var tokens = GetJWTTokens(user);

            return(Ok(tokens));
        }