Example #1
0
 private void CheckToken(int appid, int userId, string token)
 {
     if (userId == BuiltIns.ReadOnlyUser.Id)
     {
         return;
     }
     TokenCache tc = new TokenCache { User_Id = userId, Application_Id = appid };
     modelAccesser.Get(tc);
     if (tc.Loaded)
     {
         if (tc.Token == token)
         {
             return;
         }
         throw new FaultException(Resource.Messages.InvalidToken);
     }
     else
     {
         tc.Application_Id = BuiltIns.AllApplication.Id;
         modelAccesser.Get(tc);
         if (tc.Loaded)
         {
             if (tc.Token == token)
             {
                 return;
             }
         }
     }
     throw new FaultException(Resource.Messages.InvalidToken);
 }
Example #2
0
 public void LogOff(int appid, int userId)
 {
     TokenCache tc = new TokenCache { User_Id = userId, Application_Id = appid };
     modelAccesser.Delete(tc);
 }
Example #3
0
 private string GetUserToken(User user, string password, int appId)
 {
     TokenCache tc = new TokenCache { Application_Id = appId, User_Id = user.Id };
     modelAccesser.Get(tc);
     if (user.IsBuiltIn)
     {
         if (tc.Loaded)
         {
             return tc.Token;
         }
     }
     string rawToken = user.Id.ToString() + ClientAddress + password + Guid.NewGuid().ToString();
     byte[] rawTokenBytes = System.Text.UTF8Encoding.Default.GetBytes(rawToken);
     string token = Convert.ToBase64String(rawTokenBytes);
     tc.Token = token;
     if (tc.Loaded)
     {
         modelAccesser.Update(tc);
     }
     else
     {
         modelAccesser.Add(tc);
     }
     return token;
 }