Changeset 422 for binary-improvements2/WebServer/src
- Timestamp:
- Mar 28, 2023, 5:40:08 PM (20 months ago)
- Location:
- binary-improvements2/WebServer/src
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/WebServer/src/UrlHandlers/SessionHandler.cs
r417 r422 61 61 private void HandleUserPassLogin (RequestContext _context, string _remoteEndpointString) { 62 62 if (!_context.Request.HasEntityBody) { 63 _context.Response.Redirect (pageErrorPath + "NoLoginData");63 WebUtils.WriteText (_context.Response, "NoLoginData", HttpStatusCode.BadRequest); 64 64 return; 65 65 } … … 76 76 Log.Error ("Error deserializing JSON from user/password login:"); 77 77 Log.Exception (e); 78 _context.Response.Redirect (pageErrorPath + "InvalidLoginJson");78 WebUtils.WriteText (_context.Response, "InvalidLoginJson", HttpStatusCode.BadRequest); 79 79 return; 80 80 } 81 81 82 82 if (!inputJson.TryGetValue ("username", out object fieldNode) || fieldNode is not string username) { 83 _context.Response.Redirect (pageErrorPath + "InvalidLoginJson");83 WebUtils.WriteText (_context.Response, "InvalidLoginJson", HttpStatusCode.BadRequest); 84 84 return; 85 85 } 86 86 87 87 if (!inputJson.TryGetValue ("password", out fieldNode) || fieldNode is not string password) { 88 _context.Response.Redirect (pageErrorPath + "InvalidLoginJson");88 WebUtils.WriteText (_context.Response, "InvalidLoginJson", HttpStatusCode.BadRequest); 89 89 return; 90 90 } … … 94 94 if (!webUser.HasValue) { 95 95 Log.Out ($"[Web] User/pass login failed from {_remoteEndpointString}"); 96 _context.Response.Redirect (pageErrorPath + "UserPassInvalid");96 WebUtils.WriteText (_context.Response, "UserPassInvalid", HttpStatusCode.Unauthorized); 97 97 return; 98 98 } … … 144 144 145 145 public static void HandleUserIdLogin (ConnectionHandler _connectionHandler, RequestContext _context, string _remoteEndpointString, 146 string _loginName, string _errorPage, string _username, PlatformUserIdentifierAbs _userId, PlatformUserIdentifierAbs _crossUserId = null, bool _ redirect= true) {146 string _loginName, string _errorPage, string _username, PlatformUserIdentifierAbs _userId, PlatformUserIdentifierAbs _crossUserId = null, bool _sendResponse = true) { 147 147 try { 148 148 WebConnection con = _connectionHandler.LogIn (_context.Request.RemoteEndPoint!.Address, _username, _userId, _crossUserId); … … 165 165 _context.Response.AppendCookie (cookie); 166 166 167 if (_ redirect) {168 _context.Response.Redirect (pageBasePath);167 if (_sendResponse) { 168 WebUtils.WriteText (_context.Response, ""); 169 169 } 170 170 } catch (Exception e) { 171 171 Log.Error ($"[Web] Error during {_loginName} login:"); 172 172 Log.Exception (e); 173 if (_ redirect) {174 _context.Response.Redirect (pageErrorPath + _errorPage);173 if (_sendResponse) { 174 WebUtils.WriteText (_context.Response, "LoginError", HttpStatusCode.InternalServerError); 175 175 } 176 176 } -
binary-improvements2/WebServer/src/WebUtils.cs
r404 r422 24 24 _resp.ContentEncoding = Encoding.UTF8; 25 25 26 byte[] buf = Encoding.UTF8.GetBytes (_text); 27 _resp.ContentLength64 = buf.Length; 28 _resp.OutputStream.Write (buf, 0, buf.Length); 26 if (string.IsNullOrEmpty (_text)) { 27 _resp.ContentLength64 = 0; 28 } else { 29 byte[] buf = Encoding.UTF8.GetBytes (_text); 30 _resp.ContentLength64 = buf.Length; 31 _resp.OutputStream.Write (buf, 0, buf.Length); 32 } 29 33 } 30 34
Note:
See TracChangeset
for help on using the changeset viewer.