Esempio n. 1
0
        public static async Task <bool> AddUser(string user, string password, string fullName, string groups, string masterPassword)
        {
            using (var ocCommand = new OCAddUser(user, password))
            {
                ocCommand.setCredentials("admin", masterPassword);
                await ocCommand.sendRequest();

                if (ocCommand.status != "ok")
                {
                    return(false);
                }
            }
            using (var ocCommand = new OCEditUser(user, "display", fullName))
            {
                ocCommand.setCredentials("admin", masterPassword);
                await ocCommand.sendRequest();

                if (ocCommand.status != "ok")
                {
                    return(false);
                }
            }
            foreach (var group in groups.Split('|'))
            {
                bool result = await CheckGroup(group, masterPassword); //lets check the group exists

                if (!result)
                {
                    result = await AddGroup(group, masterPassword); //if it doesnt we create it

                    if (!result)
                    {
                        return(false);
                    }
                }
                else
                {
                    result = await CheckUserGroup(user, group, masterPassword); //lets check if the user already belongs to the group

                    if (result)
                    {
                        break;
                    }
                }
                result = await AddUserToGroup(user, group, masterPassword);// if he doesnt, we add to the group

                if (!result)
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 2
0
        public static async Task <bool> UppUser(string user, string password, string fullName, string groups)
        {
            using (var ocCommand = new OCGetUsers(user))
            {
                ocCommand.setCredentials(Credentials);
                await ocCommand.sendRequest();

                if (!ocCommand.userList.Contains(user))
                {
                    return(false);
                }
            }
            using (var ocCommand = new OCEditUser(user, "display", fullName))
            {
                ocCommand.setCredentials(Credentials);
                await ocCommand.sendRequest();

                if (ocCommand.status != "ok")
                {
                    return(false);
                }
            }
            using (var ocCommand = new OCEditUser(user, "password", password))
            {
                ocCommand.setCredentials(Credentials);
                await ocCommand.sendRequest();

                if (ocCommand.status != "ok")
                {
                    return(false);
                }
            }
            foreach (var group in groups.Split('|'))
            {
                if (group.Trim() != "")
                {
                    bool result = await CheckGroup(group); //lets check the group exists

                    if (!result)
                    {
                        result = await AddGroup(group); //if it doesnt we create it

                        if (!result)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        result = await CheckUserGroup(user, group); //lets check if the user already belongs to the group

                        if (result)
                        {
                            break;
                        }
                    }
                    result = await AddUserToGroup(user, group);// if he doesnt, we add to the group

                    if (!result)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }