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

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

Refactored console commands for A21 caching

File size: 2.0 KB
RevLine 
[404]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
[405]13 protected override string[] getCommands () {
14 return new[] {"createwebusermanual"};
[404]15 }
16
[405]17 protected override string getDescription () {
18 return "Create a web dashboard user account - manual for testing";
[404]19 }
20
[405]21 protected override string getHelp () {
[404]22 return ""; // TODO
23 }
24
25 public override bool IsExecuteOnClient => true;
26
27 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
28 // if (GameManager.IsDedicatedServer) {
29 // SdtdConsole.Instance.Output ("Command can only be executed on game clients or listen servers.");
30 // return;
31 // }
32
33 // TODO
34
35 if (_params.Count < 2) {
36 SdtdConsole.Instance.Output ($"Wrong number of arguments");
37 return;
38 }
39
40 string name = _params [0];
41 string pass = _params [1];
42
43 if (string.IsNullOrEmpty (name)) {
44 SdtdConsole.Instance.Output ("Argument 'name' is empty.");
45 return;
46 }
47
48 if (!validNameTokenMatcher.IsMatch (name)) {
49 SdtdConsole.Instance.Output (
50 "Argument 'name' may only contain characters (A-Z, a-z), digits (0-9) and underscores (_).");
51 return;
52 }
53
54 if (string.IsNullOrEmpty (pass)) {
55 SdtdConsole.Instance.Output ("Argument 'password' is empty.");
56 return;
57 }
58
59 if (!validNameTokenMatcher.IsMatch (pass)) {
60 SdtdConsole.Instance.Output (
61 "Argument 'password' may only contain characters (A-Z, a-z), digits (0-9) and underscores (_).");
62 return;
63 }
64
65 AdminWebUsers.Instance.AddUser (name, pass, new UserIdentifierSteam (76561198066968172ul),
66 new UserIdentifierEos ("0002bc29a5624774b4b0dc27e60b974f"));
67
68 SdtdConsole.Instance.Output ($"User added");
69 }
70
71 }
72}
Note: See TracBrowser for help on using the repository browser.