[402] | 1 | using Utf8Json;
|
---|
[391] | 2 |
|
---|
| 3 | namespace Webserver.UrlHandlers {
|
---|
| 4 | public class UserStatusHandler : AbsHandler {
|
---|
| 5 | public UserStatusHandler (string _moduleName = null) : base (_moduleName) {
|
---|
| 6 | }
|
---|
| 7 |
|
---|
[402] | 8 | private static readonly byte[] jsonLoggedInKey = JsonWriter.GetEncodedPropertyNameWithBeginObject ("loggedIn");
|
---|
| 9 | private static readonly byte[] jsonUsernameKey = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("username");
|
---|
| 10 | private static readonly byte[] jsonPermissionsKey = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("permissions");
|
---|
| 11 |
|
---|
| 12 | private static readonly byte[] jsonModuleKey = JsonWriter.GetEncodedPropertyNameWithBeginObject ("module");
|
---|
| 13 | private static readonly byte[] jsonAllowedKey = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("allowed");
|
---|
| 14 |
|
---|
[391] | 15 | public override void HandleRequest (RequestContext _context) {
|
---|
[402] | 16 | WebUtils.PrepareEnvelopedResult (out JsonWriter writer);
|
---|
| 17 |
|
---|
| 18 | writer.WriteRaw (jsonLoggedInKey);
|
---|
| 19 | writer.WriteBoolean (_context.Connection != null);
|
---|
| 20 |
|
---|
| 21 | writer.WriteRaw (jsonUsernameKey);
|
---|
| 22 | writer.WriteString (_context.Connection != null ? _context.Connection.UserId.ToString () : string.Empty);
|
---|
| 23 |
|
---|
| 24 | writer.WriteRaw (jsonPermissionsKey);
|
---|
| 25 | writer.WriteBeginArray ();
|
---|
[391] | 26 |
|
---|
[402] | 27 | bool first = true;
|
---|
| 28 | foreach (WebPermissions.WebModulePermission perm in WebPermissions.Instance.GetModules ()) {
|
---|
| 29 | if (!first) {
|
---|
| 30 | writer.WriteValueSeparator ();
|
---|
| 31 | }
|
---|
[391] | 32 |
|
---|
[402] | 33 | first = false;
|
---|
| 34 |
|
---|
| 35 | writer.WriteRaw (jsonModuleKey);
|
---|
| 36 | writer.WriteString (perm.module);
|
---|
| 37 |
|
---|
| 38 | writer.WriteRaw (jsonAllowedKey);
|
---|
| 39 | writer.WriteBoolean (perm.permissionLevel >= _context.PermissionLevel);
|
---|
| 40 |
|
---|
| 41 | writer.WriteEndObject ();
|
---|
[391] | 42 | }
|
---|
| 43 |
|
---|
[402] | 44 | writer.WriteEndArray ();
|
---|
| 45 |
|
---|
| 46 | writer.WriteEndObject ();
|
---|
| 47 |
|
---|
| 48 | WebUtils.SendEnvelopedResult (_context, ref writer);
|
---|
[391] | 49 | }
|
---|
| 50 | }
|
---|
| 51 | }
|
---|