source: binary-improvements/MapRendering/SteamLoginApi.cs@ 497

Last change on this file since 497 was 455, checked in by alloc, 16 months ago

25_30_44

  • Got rid (mostly) of custom JSON serialization
  • Some code cleanup
File size: 1.8 KB
RevLine 
[454]1using System.Net;
[455]2using JetBrains.Annotations;
[454]3using Webserver;
4using Webserver.UrlHandlers;
5using Webserver.WebAPI;
6
[455]7namespace AllocsFixes.Web {
8 [UsedImplicitly]
[454]9 public class SteamLoginApi : AbsWebAPI {
10 public override int DefaultPermissionLevel () => 2000;
11
12 private const string pageBasePath = "/legacymap/index.html";
13
14 private const string steamOpenIdVerifyUrl = "verifysteamopenid";
15 private const string steamLoginUrl = "loginsteam";
16
[455]17 public SteamLoginApi (Webserver.Web _parentWeb) : base(_parentWeb) {
[454]18 }
19
20 public override void HandleRequest (RequestContext _context) {
21 if (_context.Request.RemoteEndPoint == null) {
22 WebUtils.WriteText (_context.Response, "No remote endpoint", HttpStatusCode.BadRequest);
23 return;
24 }
25
26 string subpath = _context.RequestPath;
27
28 string remoteEndpointString = _context.Request.RemoteEndPoint!.ToString ();
29
30 if (subpath.StartsWith (steamOpenIdVerifyUrl)) {
31 if (SessionHandler.HandleSteamVerification (ParentWeb.ConnectionHandler, _context, remoteEndpointString)) {
32 _context.Response.Redirect (pageBasePath);
33 } else {
34 WebUtils.WriteText (_context.Response, "Login failed", HttpStatusCode.InternalServerError);
35 }
36 return;
37 }
38
39 if (subpath.StartsWith ("logout")) {
40 SessionHandler.HandleLogout (ParentWeb.ConnectionHandler, _context, pageBasePath);
41 return;
42 }
43
44 if (subpath.StartsWith (steamLoginUrl)) {
[455]45 string absoluteUrl = _context.Request.Url.AbsolutePath;
[454]46 absoluteUrl = absoluteUrl.Substring (0, absoluteUrl.Length - _context.RequestPath.Length);
47 SessionHandler.HandleSteamLogin (_context, $"{absoluteUrl}{steamOpenIdVerifyUrl}");
48 return;
49 }
50
51 WebUtils.WriteText (_context.Response, "Invalid path", HttpStatusCode.BadRequest);
52 }
53
54 }
55}
Note: See TracBrowser for help on using the repository browser.