mirror of
https://github.com/Leonmmcoset/CMLeonOS.git
synced 2026-03-03 15:30:27 +00:00
拆分代码9
This commit is contained in:
10
shell/Commands/User/CpassCommand.cs
Normal file
10
shell/Commands/User/CpassCommand.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace CMLeonOS.Commands.User
|
||||
{
|
||||
public static class CpassCommand
|
||||
{
|
||||
public static void ProcessCpass(CMLeonOS.UserSystem userSystem)
|
||||
{
|
||||
userSystem.ChangePassword();
|
||||
}
|
||||
}
|
||||
}
|
||||
18
shell/Commands/User/HostnameCommand.cs
Normal file
18
shell/Commands/User/HostnameCommand.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace CMLeonOS.Commands.User
|
||||
{
|
||||
public static class HostnameCommand
|
||||
{
|
||||
public static void ProcessHostnameCommand(string args, CMLeonOS.UserSystem userSystem, Action<string> showError)
|
||||
{
|
||||
if (string.IsNullOrEmpty(args))
|
||||
{
|
||||
showError("Usage: hostname <new_hostname>");
|
||||
return;
|
||||
}
|
||||
|
||||
userSystem.ProcessHostnameCommand(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
71
shell/Commands/User/UserCommand.cs
Normal file
71
shell/Commands/User/UserCommand.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
|
||||
namespace CMLeonOS.Commands.User
|
||||
{
|
||||
public static class UserCommand
|
||||
{
|
||||
public static void ProcessUserCommand(string args, CMLeonOS.UserSystem userSystem, Action<string> showError)
|
||||
{
|
||||
if (string.IsNullOrEmpty(args))
|
||||
{
|
||||
showError("Error: Please specify a user command");
|
||||
showError("Please specify a user command");
|
||||
showError("user <add|delete> [args]");
|
||||
showError(" user add admin <username> <password> - Add admin user");
|
||||
showError(" user add user <username> <password> - Add regular user");
|
||||
showError(" user delete <username> - Delete user");
|
||||
showError(" user list - List all users");
|
||||
return;
|
||||
}
|
||||
|
||||
string[] parts = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length < 1)
|
||||
{
|
||||
showError("Error: Please specify a user command");
|
||||
showError("Usage: user <add|delete> [args]");
|
||||
return;
|
||||
}
|
||||
|
||||
string subCommand = parts[0].ToLower();
|
||||
|
||||
if (subCommand == "add")
|
||||
{
|
||||
if (parts.Length < 4)
|
||||
{
|
||||
showError("Error: Please specify user type and username and password");
|
||||
showError("Usage: user add admin <username> <password>");
|
||||
showError("Usage: user add user <username> <password>");
|
||||
return;
|
||||
}
|
||||
|
||||
string userType = parts[1].ToLower();
|
||||
string username = parts[2];
|
||||
string password = parts[3];
|
||||
bool isAdmin = userType == "admin";
|
||||
|
||||
userSystem.AddUser($"{username} {password}", isAdmin);
|
||||
}
|
||||
else if (subCommand == "delete")
|
||||
{
|
||||
if (parts.Length < 2)
|
||||
{
|
||||
showError("Error: Please specify username");
|
||||
showError("Usage: user delete <username>");
|
||||
return;
|
||||
}
|
||||
|
||||
string username = parts[1];
|
||||
userSystem.DeleteUser(username);
|
||||
}
|
||||
else if (subCommand == "list")
|
||||
{
|
||||
userSystem.ListUsers();
|
||||
}
|
||||
else
|
||||
{
|
||||
showError($"Error: Unknown user command '{subCommand}'");
|
||||
showError("Available commands: add, delete, list");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user