Example #1
0
 public User GetByToken(string token)
 {
     using (var context = new SsoModel())
     {
         return context.SsoUsers.SingleOrDefault(u => u.Token == token);
     }
 }
Example #2
0
 public Admin Get(string key)
 {
     using (var context = new SsoModel())
     {
         return context.SsoAdmins.SingleOrDefault(u => u.AuthKey == key);
     }
 }
Example #3
0
 public User GetByName(Guid ssoId, string name)
 {
     using (var context = new SsoModel())
     {
         return context.SsoUsers.SingleOrDefault(u => u.Name == name && u.SsoId == ssoId);
     }
 }
Example #4
0
 public User Get(Guid ssoId, string key)
 {
     using (var context = new SsoModel())
     {
         return context.SsoUsers.SingleOrDefault(u => u.AuthKey == key && u.SsoId == ssoId);
     }
 }
Example #5
0
 public string GetSettings(Guid userId, Guid appId)
 {
     using (var context = new SsoModel())
     {
         var store = context.SsoStores.SingleOrDefault(s => s.UserId == userId && s.AppId == appId);
         return store?.Settings;
     }
 }
Example #6
0
 public void Update(string key, Action<Admin> update)
 {
     using (var context = new SsoModel())
     {
         var admin = context.SsoAdmins.SingleOrDefault(u => u.AuthKey == key);
         if (admin == null) throw ExceptionHelper.UserNotFound();
         update(admin);
         context.SaveChanges();
     }
 }
Example #7
0
 public void Add(Admin admin)
 {
     using (var context = new SsoModel())
     {
         var curentUser = context.SsoUsers.SingleOrDefault(u => u.Name.ToLower() == admin.Name.ToLower());
         if (curentUser != null) throw ExceptionHelper.Conflict("User is already exist");
         context.SsoAdmins.Add((SsoAdmin) admin);
         context.SaveChanges();
     }
 }
Example #8
0
 public void UpdateByToken(string token, Action<User> update)
 {
     using (var context = new SsoModel())
     {
         var user = context.SsoUsers.SingleOrDefault(u => u.Token == token);
         if (user == null) throw ExceptionHelper.UserNotFound();
         update(user);
         context.SaveChanges();
     }
 }
Example #9
0
 public void Update(Guid ssoId, string key, Action<User> update)
 {
     using (var context = new SsoModel())
     {
         var user = context.SsoUsers.SingleOrDefault(u => u.AuthKey == key && u.SsoId == ssoId);
         if (user == null) throw ExceptionHelper.UserNotFound();
         update(user);
         context.SaveChanges();
     }
 }
Example #10
0
 public void Delete(Guid userId, Guid appId)
 {
     using (var context = new SsoModel())
     {
         var store = context.SsoStores.SingleOrDefault(s => s.UserId == userId && s.AppId == appId);
         if (store != null)
         {
             context.SsoStores.Remove(store);
             context.SaveChanges();
         }
     }
 }
Example #11
0
 public void Add(User user)
 {
     using (var context = new SsoModel())
     {
         var curentUser =
             context.SsoUsers.SingleOrDefault(
                 u => u.Name.ToLower() == user.Name.ToLower() && u.SsoId == user.SsoId);
         if (curentUser != null) throw ExceptionHelper.Conflict("User is already exist");
         context.SsoUsers.Add((SsoUser) user);
         context.SaveChanges();
     }
 }
Example #12
0
 public Store GetStore(Guid userId, Guid appId)
 {
     using (var context = new SsoModel())
     {
         var store = context.SsoStores.SingleOrDefault(s => s.UserId == userId && s.AppId == appId);
         var storeValue = store != null ? store.Store : string.Empty;
         return new Store
         {
             Hash = storeValue.GetSHA1(),
             Value = storeValue
         };
     }
 }
Example #13
0
 public void Add(Guid userId, Guid appId, string store, string settings)
 {
     using (var context = new SsoModel())
     {
         context.SsoStores.Add(new SsoStore
         {
             UserId = userId,
             AppId = appId,
             Store = store,
             Settings = settings
         });
         context.SaveChanges();
     }
 }
Example #14
0
 public void Add(Guid userId, Guid appId, DateTime time, int type, string message)
 {
     using (var context = new SsoModel())
     {
         context.SsoLogs.Add(new SsoLog
         {
             UserId = userId,
             AppId = appId,
             Time = time,
             Type = type,
             Message = message
         });
         context.SaveChanges();
     }
 }
Example #15
0
        public void UpdateSettings(Guid userId, Guid appId, string settings)
        {
            using (var context = new SsoModel())
            {
                var store = context.SsoStores.SingleOrDefault(s => s.UserId == userId && s.AppId == appId);
                if (store != null)
                {
                    store.Settings = settings;
                }
                else
                {
                    context.SsoStores.Add(new SsoStore
                    {
                        AppId = appId,
                        UserId = userId,
                        Settings = settings
                    });
                }

                context.SaveChanges();
            }
        }
Example #16
0
        public string UpdateStore(Guid userId, Guid appId, Diff diff)
        {
            using (var context = new SsoModel())
            {
                var currentStore = context.SsoStores.SingleOrDefault(s => s.UserId == userId && s.AppId == appId);

                if (currentStore != null)
                {
                    if (currentStore.Store.GetSHA1() != diff.Hash)
                        throw ExceptionHelper.Conflict("hash is not relevant");

                    var store = string.Concat(
                        currentStore.Store.Substring(0, diff.Start),
                        diff.Value,
                        currentStore.Store.Substring(currentStore.Store.Length - diff.End, diff.End));

                    currentStore.Store = store;
                    context.SaveChanges();
                    return store.GetSHA1();
                }
                context.SsoStores.Add(new SsoStore
                {
                    AppId = appId,
                    UserId = userId,
                    Store = diff.Value
                });
                context.SaveChanges();
                return diff.Value.GetSHA1();
            }
        }