public HttpResponseMessage Login([FromBody] LoginRequest request) { try { if (request == null) { return(CreateErrorResponse(HttpStatusCode.BadRequest, "No se recibieron los parámetros de entrada.")); } var user = _authService.Authenticate(request.Username, SecurityUtil.EncryptPassword(request.Password)); if (user == null) { return(CreateErrorResponse(HttpStatusCode.BadRequest, "El usuario no existe o contraseña inválida.")); } if (!user.Status) { return(CreateErrorResponse(HttpStatusCode.BadRequest, "La cuenta del usuario se encuentra inactiva o no se ha confirmado.")); } /*if (user.Role.Code != Constants.ROLE_DEFAULT_API) * { * return CreateErrorResponse(HttpStatusCode.BadRequest, "El usuario no cuenta con acceso al API"); * }*/ var expiration = DateUtil.GetDateTimeNow().AddHours(Constants.HOURS_EXPIRATION_KEY).ToUniversalTime(); user.ApiKey = Guid.NewGuid().ToString(); user.ExpiraApiKey = expiration; user.LastLoginAt = DateUtil.GetDateTimeNow(); _userService.Update(user); var response = new AuthUserResponse { ApiKey = user.ApiKey, ApiKeyExpiration = DateUtil.ConvertToUnixTime(expiration), Uuid = user.Uuid, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, MobilePhone = user.MobileNumber, }; return(CreateResponse(response)); } catch (Exception e) { return(CreateErrorResponse(e)); } }