public User getUser(string token) { User user = null; string json = DecodeJson(token); if (token == null) { return(null); } DataAuth data = new DataAuth(json); DataContext db = new DataContext(); user = db.User.FirstOrDefault(t => t.Id == data.Id && t.email == data.email); return(user); }
public User Decode(HttpRequest request) { this.request = request; string token = this.getToken(); if (token == null) { return(null); } try { this.json = Jose.JWT.Decode(token, secretKey); } catch (System.ArgumentOutOfRangeException ex) { Console.Write(ex); return(null); } catch (Jose.JoseException ex) { Console.Write(ex); return(null); } if (json == null) { return(null); } DataAuth dataAuth = new DataAuth(json); if (dataAuth.Id == 0) { return(null); } DateTime now = (new DateTime()).ToUniversalTime(); if (now > dataAuth.exp) { return(null); } DataContext db = new DataContext(); this.User = db.User.FirstOrDefault(t => t.Id == dataAuth.Id && t.email == dataAuth.email); return(this.User); }