Ejemplo n.º 1
0
 public IActionResult Authenticate([FromBody] LoginModel login)
 {
     if (ModelState.IsValid)
     {
         var user = _dao.GetByEmail(login.Email);
         if (user == null)
         {
             ModelState.AddModelError("Email", "Email not registered");
             return(ValidationProblem());
         }
         if (HashService.Decrypt(user.Password).CompareTo(login.Password) != 0)
         {
             ModelState.AddModelError("Password", "Invalid password");
             return(ValidationProblem());
         }
         var jwt = _jwtService.GenerateToken(user);
         return(Ok(new DeveloperLogged(new DeveloperView(user), jwt)));
     }
     return(ValidationProblem());
 }