Ejemplo n.º 1
0
 public string GenerateAccessToken(string username, type_login type, int minute = 60)
 {
     try
     {
         //string type_str = type == type_login.mainsystem ? "mainsystem" : throw new Exception("Type Error");
         JWTPayload payload = new JWTPayload
         {
             username = $"{type.ToString()}:" + username,
             exp      = DateTime.UtcNow.AddMinutes(minute)
         };
         return(JWT.Encode(payload, this.secretKey, JwsAlgorithm.HS256));
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Ejemplo n.º 2
0
 public admin VerifyAccessToken_back(JWTPayload payload)
 {
     try
     {
         test_db db = new test_db();
         if (payload == null)
         {
             return(null);
         }
         if (payload.exp < DateTime.UtcNow)
         {
             return(null);
         }
         var res = db.admins.FirstOrDefault(e => e.ad_username.Equals(payload.username));
         return(res);
     }
     catch { return(null); }
 }
Ejemplo n.º 3
0
 public member VerifyAccessToken_main(JWTPayload payload)
 {
     try
     {
         test_db db = new test_db();
         if (payload == null)
         {
             return(null);
         }
         if (payload.exp < DateTime.UtcNow)
         {
             return(null);
         }
         var res = db.members.FirstOrDefault(e => e.mem_usename.Equals(payload.username));
         return(res);
     }
     catch { return(null); }
 }