Beispiel #1
0
 /// <summary>
 /// Create a new CollectionUser object
 /// </summary>
 /// <param name="collection">The collection</param>
 /// <param name="user">The user</param>
 /// <param name="access">Allow/deny access</param>
 /// <returns>The new CollectionUser object</returns>
 public static CollectionUser CreateNew(Collection collection, User user, bool access)
 {
     CollectionUser cu = new CollectionUser();
     cu.CollectionId = collection.Id;
     cu.UserId = user.Id;
     cu.Access = access;
     cu.isNew = true;
     return cu;
 }
Beispiel #2
0
        public static User CreateNewUser(string username, string password, bool admin)
        {
            User newUser = new User();
            newUser.Username = username;
            newUser.SetPassword(password);
            newUser.Admin = admin;

            return newUser;
        }
Beispiel #3
0
        public static void DeleteUsers(int[] ids, User currentUser)
        {
            if (currentUser != null && currentUser.Id != -1)
            {
                List<int> newIds = new List<int>(ids);
                while (newIds.Remove(currentUser.Id))
                {
                }

                ids = newIds.ToArray();
            }

            Database.Delete("user", Database.BuildWhereClauseOr("id", ids));
            Database.Delete("collectionuser", Database.BuildWhereClauseOr("uid", ids));
        }
Beispiel #4
0
 private static User FromData(Dictionary<string, object> data)
 {
     User user = new User();
     user.Id = Convert.ToInt32(data["id"]);
     user.Username = Convert.ToString(data["username"]);
     user.password = Convert.ToString(data["password"]);
     user.Admin = Convert.ToInt32(data["admin"]) == 1;
     return user;
 }
Beispiel #5
0
        public static UserJson[] ToJsonArray(User[] users)
        {
            List<UserJson> objs = new List<UserJson>();
            foreach (User user in users)
            {
                objs.Add(user.ToJson());
            }

            return objs.ToArray();
        }
Beispiel #6
0
        public static void SetAdmin(int[] ids, bool admin, User currentUser)
        {
            if (currentUser != null && currentUser.Id != -1)
            {
                List<int> newIds = new List<int>(ids);
                while (newIds.Remove(currentUser.Id))
                {
                }

                ids = newIds.ToArray();
            }

            Dictionary<string, object> data = new Dictionary<string, object>();
            data.Add("admin", admin ? 1 : 0);
            Database.Update("user", data, Database.BuildWhereClauseOr("id", ids));
        }
Beispiel #7
0
        /// <summary>
        /// Get all CollectionUser objects associated to a user
        /// </summary>
        /// <param name="user">The user</param>
        /// <returns>An array of CollectionUser objects</returns>
        public static CollectionUser[] GetByUser(User user)
        {
            if (user != null && user.Id != -1)
            {
                return GetMultiple("`uid`=" + Database.Quote(user.Id.ToString()));
            }

            return new CollectionUser[] { };
        }
Beispiel #8
0
        public static CollectionUser Get(Collection collection, User user)
        {
            CollectionUser[] cus = GetMultiple("`cid`=" + Database.Quote(collection.Id.ToString()) + " AND `uid`=" + Database.Quote(user.Id.ToString()));
            if (cus.Length > 0)
            {
                return cus[0];
            }

            return null;
        }