- Timestamp:
- Jan 27, 2023, 7:28:00 PM (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/WebServer/src/UrlHandlers/UserStatusHandler.cs
r391 r402 1 using AllocsFixes.JSON;1 using Utf8Json; 2 2 3 3 namespace Webserver.UrlHandlers { … … 6 6 } 7 7 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 8 15 public override void HandleRequest (RequestContext _context) { 9 JsonObject result = new JsonObject (); 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 (); 10 26 11 result.Add ("loggedin", new JsonBoolean (_context.Connection != null)); 12 result.Add ("username", new JsonString (_context.Connection != null ? _context.Connection.UserId.ToString () : string.Empty)); 27 bool first = true; 28 foreach (WebPermissions.WebModulePermission perm in WebPermissions.Instance.GetModules ()) { 29 if (!first) { 30 writer.WriteValueSeparator (); 31 } 13 32 14 JsonArray perms = new JsonArray (); 15 foreach (WebPermissions.WebModulePermission perm in WebPermissions.Instance.GetModules ()) { 16 JsonObject permObj = new JsonObject (); 17 permObj.Add ("module", new JsonString (perm.module)); 18 permObj.Add ("allowed", new JsonBoolean (perm.permissionLevel >= _context.PermissionLevel)); 19 perms.Add (permObj); 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 (); 20 42 } 21 43 22 result.Add ("permissions", perms); 23 24 WebUtils.WriteJson (_context.Response, result); 44 writer.WriteEndArray (); 45 46 writer.WriteEndObject (); 47 48 WebUtils.SendEnvelopedResult (_context, ref writer); 25 49 } 26 50 }
Note:
See TracChangeset
for help on using the changeset viewer.