source: binary-improvements2/WebServer/src/Commands/CreateWebUser.cs@ 404

Last change on this file since 404 was 404, checked in by alloc, 21 months ago

Latest state including reworking to the permissions system

File size: 2.0 KB
Line 
1using System.Collections.Generic;
2using System.Text.RegularExpressions;
3using JetBrains.Annotations;
4using Platform.EOS;
5using Platform.Steam;
6using Webserver.Permissions;
7
8namespace Webserver.Commands {
9 [UsedImplicitly]
10 public class CreateWebUser : ConsoleCmdAbstract {
11 private static readonly Regex validNameTokenMatcher = new Regex (@"^\w+$");
12
13 public override string[] GetCommands () {
14 return new[] {"createwebuser"};
15 }
16
17 public override string GetDescription () {
18 return "Create a web dashboard user account";
19 }
20
21 public override string GetHelp () {
22 return ""; // TODO
23 }
24
25 public override int DefaultPermissionLevel => 1000;
26 public override bool IsExecuteOnClient => true;
27
28 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
29 // if (GameManager.IsDedicatedServer) {
30 // SdtdConsole.Instance.Output ("Command can only be executed on game clients or listen servers.");
31 // return;
32 // }
33
34 // TODO
35
36 if (_params.Count < 2) {
37 SdtdConsole.Instance.Output ($"Wrong number of arguments");
38 return;
39 }
40
41 string name = _params [0];
42 string pass = _params [1];
43
44 if (string.IsNullOrEmpty (name)) {
45 SdtdConsole.Instance.Output ("Argument 'name' is empty.");
46 return;
47 }
48
49 if (!validNameTokenMatcher.IsMatch (name)) {
50 SdtdConsole.Instance.Output (
51 "Argument 'name' may only contain characters (A-Z, a-z), digits (0-9) and underscores (_).");
52 return;
53 }
54
55 if (string.IsNullOrEmpty (pass)) {
56 SdtdConsole.Instance.Output ("Argument 'password' is empty.");
57 return;
58 }
59
60 if (!validNameTokenMatcher.IsMatch (pass)) {
61 SdtdConsole.Instance.Output (
62 "Argument 'password' may only contain characters (A-Z, a-z), digits (0-9) and underscores (_).");
63 return;
64 }
65
66 AdminWebUsers.Instance.AddUser (name, pass, new UserIdentifierSteam (76561198066968172ul),
67 new UserIdentifierEos ("0002bc29a5624774b4b0dc27e60b974f"));
68
69 SdtdConsole.Instance.Output ($"User added");
70 }
71
72 }
73}
Note: See TracBrowser for help on using the repository browser.