public IHttpActionResult Login([FromBody] LoginRequest User) { GeneralResponse oResponse = new GeneralResponse(); try { UserManager oUserManager = new UserManager(); LoginResponse oLoginRespuesta = new LoginResponse(); User user = oUserManager.GetByCuil(User.Cuil); if (user.UserId == null) { throw new ArgumentException("Acesso denegado, cuil o cuil incorrecto"); } if (!BC.Verify(User.Password, user.Password)) { oResponse.Success = 0; oResponse.Message = "Contraseña incorrecta"; return(Content(HttpStatusCode.BadRequest, oResponse)); } oLoginRespuesta.Token = TokenGenerator.GenerateTokenJwt(user.Cuil, user.UserId); oResponse.Success = 1; oResponse.Message = "Acesso concedido"; oResponse.Data = oLoginRespuesta; return(Ok(oResponse)); } catch (ArgumentException ex) { oResponse.Success = 0; oResponse.Message = ex.Message; return(Ok(oResponse)); } catch (Exception ex) { oResponse.Success = 0; oResponse.Message = "Error desconocido, no se pudo logear"; oResponse.Data = ex.Message; return(BadRequest()); } }
public IHttpActionResult Authenticate(LoginRequest login) { if (login == null) { throw new HttpResponseException(HttpStatusCode.BadRequest); } GestorLogin gLogin = new GestorLogin(); bool isCredentialValid = gLogin.ValidarLogin(login); if (isCredentialValid) { var token = TokenGenerator.GenerateTokenJwt(login.Username); return(Ok(token)); } else { return(Unauthorized()); } }