source: binary-improvements2/MapRendering/Web/Handlers/UserStatusHandler.cs@ 389

Last change on this file since 389 was 387, checked in by alloc, 2 years ago

Big refactoring in Web to pass around a Context instead of a bunch of individual arguments all the time

File size: 992 bytes
Line 
1using AllocsFixes.JSON;
2
3namespace AllocsFixes.NetConnections.Servers.Web.Handlers {
4 public class UserStatusHandler : AbsHandler {
5 public UserStatusHandler (string _moduleName = null) : base (_moduleName) {
6 }
7
8 public override void HandleRequest (RequestContext _context) {
9 JSONObject result = new JSONObject ();
10
11 result.Add ("loggedin", new JSONBoolean (_context.Connection != null));
12 result.Add ("username", new JSONString (_context.Connection != null ? _context.Connection.UserId.ToString () : string.Empty));
13
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);
20 }
21
22 result.Add ("permissions", perms);
23
24 WebUtils.WriteJson (_context.Response, result);
25 }
26 }
27}
Note: See TracBrowser for help on using the repository browser.