Exemplo n.º 1
0
 public JsonResult <object> Login(dynamic user)
 {
     using (var db = new LiteDB.LiteDatabase(AppDomain.CurrentDomain.BaseDirectory + "\\mydb.db"))
     {
         string password = user.password;
         string userid   = user.user;
         var    users    = db.GetCollection <User>("Users");
         var    first    = users.Find(o => o.name == userid).FirstOrDefault();
         if (first != null && Actions.IsValide(password, first.pwdhash))
         {
             var to = new TokenObj {
                 userid = userid, Expires = DateTime.Now.AddSeconds(20)
             };
             return(Json <object>(new { token = to.ToTokenString() }));
         }
     }
     return(Json <object>(new { token = "" }));
 }