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

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

24_29_43
Switched over to vanilla Web infrastructure

File size: 1.8 KB
RevLine 
[454]1using System;
2using System.Net;
3using Platform.Steam;
4using Webserver;
5using Webserver.UrlHandlers;
6using Webserver.WebAPI;
7
8namespace AllocsFixes {
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
17 public SteamLoginApi (Web _parentWeb) : base(_parentWeb) {
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)) {
45 var absoluteUrl = _context.Request.Url.AbsolutePath;
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.