- Timestamp:
- Aug 6, 2022, 11:32:32 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/MapRendering/Web/Handlers/SessionHandler.cs
r382 r387 3 3 using System.Net; 4 4 using System.Text; 5 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;6 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;7 5 8 6 namespace AllocsFixes.NetConnections.Servers.Web.Handlers { … … 29 27 } 30 28 31 public override void HandleRequest (string _requestPath, HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _con, 32 int _permissionLevel) { 29 public override void HandleRequest (RequestContext _context) { 33 30 34 IPEndPoint reqRemoteEndPoint = _ req.RemoteEndPoint;31 IPEndPoint reqRemoteEndPoint = _context.Request.RemoteEndPoint; 35 32 if (reqRemoteEndPoint == null) { 36 _ resp.Redirect (pageBasePath);33 _context.Response.Redirect (pageBasePath); 37 34 return; 38 35 } 39 36 40 string subpath = _ requestPath.Remove (0, urlBasePath.Length);37 string subpath = _context.RequestPath.Remove (0, urlBasePath.Length); 41 38 42 39 StringBuilder result = new StringBuilder (); … … 47 44 48 45 try { 49 ulong id = OpenID.Validate (_ req);46 ulong id = OpenID.Validate (_context.Request); 50 47 if (id > 0) { 51 48 WebConnection con = connectionHandler.LogIn (id, reqRemoteEndPoint.Address); … … 60 57 Secure = false 61 58 }; 62 _ resp.AppendCookie (cookie);63 _ resp.Redirect (pageBasePath);59 _context.Response.AppendCookie (cookie); 60 _context.Response.Redirect (pageBasePath); 64 61 65 62 return; … … 73 70 result.Append ($"<h1>Login failed, <a href=\"{pageBasePath}\">click to return to main page</a>.</h1>"); 74 71 } else if (subpath.StartsWith ("logout")) { 75 if (_con != null) {76 connectionHandler.LogOut (_con .SessionID);72 if (_context.Connection != null) { 73 connectionHandler.LogOut (_context.Connection.SessionID); 77 74 Cookie cookie = new Cookie ("sid", "", "/") { 78 75 Expired = true 79 76 }; 80 _ resp.AppendCookie (cookie);81 _ resp.Redirect (pageBasePath);77 _context.Response.AppendCookie (cookie); 78 _context.Response.Redirect (pageBasePath); 82 79 return; 83 80 } … … 85 82 result.Append ($"<h1>Not logged in, <a href=\"{pageBasePath}\">click to return to main page</a>.</h1>"); 86 83 } else if (subpath.StartsWith (steamLoginUrl)) { 87 string host = (Web.IsSslRedirected (_ req) ? "https://" : "http://") + _req.UserHostName;84 string host = (Web.IsSslRedirected (_context.Request) ? "https://" : "http://") + _context.Request.UserHostName; 88 85 string url = OpenID.GetOpenIdLoginUrl (host, host + urlBasePath + steamOpenIdVerifyUrl); 89 _ resp.Redirect (url);86 _context.Response.Redirect (url); 90 87 return; 91 88 } else { … … 95 92 result.Append (footer); 96 93 97 _resp.ContentType = MimeType.GetMimeType (".html"); 98 _resp.ContentEncoding = Encoding.UTF8; 99 byte[] buf = Encoding.UTF8.GetBytes (result.ToString ()); 100 _resp.ContentLength64 = buf.Length; 101 _resp.OutputStream.Write (buf, 0, buf.Length); 94 WebUtils.WriteText (_context.Response, result.ToString (), _mimeType: WebUtils.MimeHtml); 102 95 } 103 96 }
Note:
See TracChangeset
for help on using the changeset viewer.