Esempio n. 1
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            UsersMenuItem usersMenuItem = (UsersMenuItem)menuItem;

            usersMenuItem.Refresh();
            EliteConsoleMenu menu = new EliteConsoleMenu(EliteConsoleMenu.EliteConsoleMenuType.List, "Users");

            menu.Columns.Add("Username");
            menu.Columns.Add("Roles");
            menu.Columns.Add("Status");
            usersMenuItem.Users.ForEach(U =>
            {
                var userRoles       = this.CovenantClient.ApiUsersByUidRolesGet(U.Id).ToList();
                List <string> roles = new List <string>();
                foreach (var userRole in userRoles)
                {
                    IdentityRole role = CovenantClient.ApiRolesByRidGet(userRole.RoleId);
                    if (role != null)
                    {
                        roles.Add(role.Name);
                    }
                }
                menu.Rows.Add(new List <string> {
                    U.UserName, String.Join(", ", roles), "Active"
                });
            });
            menu.Print();
        }
Esempio n. 2
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            UsersMenuItem usersMenuItem = (UsersMenuItem)menuItem;

            usersMenuItem.Refresh();
            string[] commands = UserInput.Split(" ");
            if (commands.Length != 2 || commands[0].ToLower() != "delete")
            {
                menuItem.PrintInvalidOptionError(UserInput);
                EliteConsole.PrintFormattedErrorLine("Usage: Delete <username>");
                return;
            }

            CovenantUser user = usersMenuItem.Users.FirstOrDefault(U => U.UserName == commands[1]);

            if (user != null)
            {
                EliteConsole.PrintFormattedWarning("Delete user: \"" + commands[1] + "\"? [y/N] ");
                string input = EliteConsole.Read();
                if (input.ToLower().StartsWith("y"))
                {
                    this.CovenantClient.ApiUsersByUidDelete(user.Id);
                }
            }
            else
            {
                EliteConsole.PrintFormattedErrorLine("User: \"" + commands[1] + "\" does not exist.");
            }
        }
Esempio n. 3
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            UsersMenuItem usersMenuItem = (UsersMenuItem)menuItem;

            usersMenuItem.Refresh();
            string[] commands = UserInput.Split(" ");
            if (commands.Length < 3 || commands.Length > 4 || commands[0].ToLower() != "create")
            {
                menuItem.PrintInvalidOptionError(UserInput);
                EliteConsole.PrintFormattedErrorLine("Usage: Create <username> <password> [<roles>]");
                return;
            }
            CovenantUser user = this.CovenantClient.ApiUsersPost(new CovenantUserLogin(commands[1], commands[2]));

            if (user != null)
            {
                EliteConsole.PrintFormattedHighlightLine("Created user: \"" + commands[1] + "\"");
                if (commands.Length == 4)
                {
                    string[] roleNames = commands[3].Split(",");
                    foreach (string roleName in roleNames)
                    {
                        IdentityRole role = this.CovenantClient.ApiRolesGet().FirstOrDefault(R => R.Name == roleName);
                        if (role != null)
                        {
                            IdentityUserRoleString roleResult = this.CovenantClient.ApiUsersByUidRolesByRidPost(user.Id, role.Id);
                            if (roleResult.UserId == user.Id && roleResult.RoleId == role.Id)
                            {
                                EliteConsole.PrintFormattedHighlightLine("Added user: \"" + commands[1] + "\"" + " to role: \"" + roleName + "\"");
                            }
                            else
                            {
                                EliteConsole.PrintFormattedErrorLine("Failed to add user: \"" + commands[1] + "\" to role: \"" + roleName + "\"");
                            }
                        }
                    }
                }
            }
            else
            {
                EliteConsole.PrintFormattedErrorLine("Failed to create user: \"" + commands[1] + "\"");
            }
        }