mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 07:29:00 -07:00
Radicade Public Code
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using RadicadeServer.DB;
|
||||
|
||||
namespace RadicadeServer.Auth
|
||||
{
|
||||
[Route("/")]
|
||||
public class DeviceApprovalAPI : Controller
|
||||
{
|
||||
|
||||
public DeviceApprovalAPI() {
|
||||
}
|
||||
|
||||
[HttpGet("device")]
|
||||
public IActionResult Device([FromQuery(Name = "user_code")] string userCode)
|
||||
{
|
||||
var (found, approved, accountId, expiresUtc) = StudioAuthAPI.DescribeUserCode(userCode);
|
||||
|
||||
return Content(DevicePage(userCode, found, approved, accountId, expiresUtc), "text/html");
|
||||
}
|
||||
|
||||
private static string DevicePage(string userCode, bool found, bool approved, long accountId, DateTime expiresUtc)
|
||||
{
|
||||
var glyph = found && approved ? "✅" : found ? "⏳" : "⚠️";
|
||||
var color = found && approved ? "#16a34a" : found ? "#d97706" : "#dc2626";
|
||||
var title = found && approved ? "Approved" : found ? "Waiting for approval" : "Code not recognised";
|
||||
var body = found && approved
|
||||
? "This server signs Rec Room Studio in automatically, so this code is already approved as account <b>" + accountId + "</b>. Close this tab and go back to Unity."
|
||||
: found
|
||||
? "The code is valid, but it has not been approved yet. Return to Unity and try again."
|
||||
: "This server has no pending sign-in for that code - it may have expired, or it may already have been used (device codes are single use). Start the sign-in again from Unity.";
|
||||
|
||||
var codeBlock = string.IsNullOrWhiteSpace(userCode)
|
||||
? "<p style=\"color:#475569;font-size:15px;\">No <b>user_code</b> was supplied. Unity sends one when it opens this page.</p>"
|
||||
: "<p style=\"color:#475569;font-size:15px;\">Your code</p>" +
|
||||
"<p style=\"font-family:Consolas,Menlo,monospace;font-size:26px;letter-spacing:3px;color:#0f172a;background:#f1f5f9;border-radius:8px;padding:12px 0;margin:0;\">" +
|
||||
System.Net.WebUtility.HtmlEncode(userCode) + "</p>";
|
||||
|
||||
var expiry = found && expiresUtc > DateTime.UtcNow
|
||||
? "<p style=\"color:#94a3b8;font-size:13px;margin-top:18px;\">Code expires " + expiresUtc.ToString("u") + " UTC.</p>"
|
||||
: "";
|
||||
|
||||
return "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><title>" +
|
||||
"Radicade - Rec Room Studio sign-in</title></head>" +
|
||||
"<body style=\"margin:0;background:#0f172a;font-family:Arial,sans-serif;display:flex;align-items:center;justify-content:center;min-height:100vh;\">" +
|
||||
"<div style=\"background:#fff;border-radius:12px;padding:40px;max-width:440px;text-align:center;box-shadow:0 10px 40px rgba(0,0,0,0.3);\">" +
|
||||
"<div style=\"font-size:44px;\">" + glyph + "</div>" +
|
||||
"<h1 style=\"color:" + color + ";font-size:22px;margin:12px 0;\">" + title + "</h1>" +
|
||||
codeBlock +
|
||||
"<p style=\"color:#475569;font-size:15px;line-height:1.6;margin-top:18px;\">" + body + "</p>" +
|
||||
expiry +
|
||||
"<p style=\"color:#94a3b8;font-size:12px;margin-top:24px;\">" + DBConfig.ServerUrl + " - local Radicade server</p>" +
|
||||
"</div></body></html>";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user