trying to port web app starter from PHP
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
#load "../../lib/app.uce"
|
||||
|
||||
RENDER(Request& context)
|
||||
{
|
||||
starter_boot(context);
|
||||
context.var["starter"]["page_title"] = "OAuth Callback";
|
||||
String code = context.get["code"];
|
||||
String state = context.get["state"];
|
||||
String error = context.get["error"];
|
||||
String error_description = context.get["error_description"];
|
||||
|
||||
<>
|
||||
<div class="oauth-callback-page">
|
||||
<div class="callback-container">
|
||||
<? if(error != "") { ?>
|
||||
<div class="callback-result error">
|
||||
<div class="result-icon">✗</div>
|
||||
<h2>Authentication Failed</h2>
|
||||
<p><?= first(error_description, error) ?></p>
|
||||
<div class="callback-actions">
|
||||
<a href="<?= starter_link("auth/demo", context) ?>" class="btn btn-primary">Try Again</a>
|
||||
<a href="<?= starter_link("", context) ?>" class="btn btn-outline">Go Home</a>
|
||||
</div>
|
||||
</div>
|
||||
<? } else if(code != "" && state != "") { ?>
|
||||
<div class="callback-result success">
|
||||
<div class="result-icon">✓</div>
|
||||
<h2>Authentication Successful</h2>
|
||||
<p>OAuth callback received successfully! Demo mode is active until real provider credentials are configured.</p>
|
||||
<div class="callback-details">
|
||||
<p><strong>Service:</strong> <?= first(context.session["oauth_service"], "unknown") ?></p>
|
||||
<p><strong>Code:</strong> <?= code.substr(0, std::min((u64)20, (u64)code.length())) ?>...</p>
|
||||
<p><strong>State:</strong> <?= state ?></p>
|
||||
</div>
|
||||
<div class="callback-actions">
|
||||
<a href="<?= starter_link("auth/demo", context) ?>" class="btn btn-primary">Back to Auth Demo</a>
|
||||
<a href="<?= starter_link("", context) ?>" class="btn btn-outline">Go Home</a>
|
||||
</div>
|
||||
</div>
|
||||
<? } else { ?>
|
||||
<div class="callback-result error">
|
||||
<div class="result-icon">✗</div>
|
||||
<h2>Invalid Callback</h2>
|
||||
<p>Missing required OAuth parameters.</p>
|
||||
</div>
|
||||
<? } ?>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#load "../../lib/app.uce"
|
||||
|
||||
RENDER(Request& context)
|
||||
{
|
||||
starter_boot(context);
|
||||
context.var["starter"]["page_title"] = "Auth";
|
||||
starter_register_css("views/marketing.css", context);
|
||||
|
||||
DTree props;
|
||||
props["title"] = "Sign In to Your Account";
|
||||
props["subtitle"] = "Choose your preferred authentication method to continue";
|
||||
props["google_client_id"] = "YOUR_GOOGLE_CLIENT_ID";
|
||||
props["github_client_id"] = "YOUR_GITHUB_CLIENT_ID";
|
||||
props["discord_client_id"] = "YOUR_DISCORD_CLIENT_ID";
|
||||
props["twitch_client_id"] = "YOUR_TWITCH_CLIENT_ID";
|
||||
props["callback_url"] = starter_link("auth/callback", context);
|
||||
|
||||
<>
|
||||
<h1>Authentication Demo</h1>
|
||||
<div class="card">
|
||||
<h2>OAuth Authentication</h2>
|
||||
<p>This component provides secure OAuth authentication with popular identity providers.</p>
|
||||
<? print(component("../../components/auth/oauth-client", props, context)); ?>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h2>Current Session Status</h2>
|
||||
<? if(context.session["starter_user_id"] != "") { ?>
|
||||
<div class="success-card">
|
||||
<h3>Logged In</h3>
|
||||
<p>User ID: <?= context.session["starter_user_id"] ?></p>
|
||||
</div>
|
||||
<? } else { ?>
|
||||
<div class="component-card">
|
||||
<h3>Not Logged In</h3>
|
||||
<p>Use the OAuth component above to sign in with Google, GitHub, Discord, or Twitch.</p>
|
||||
</div>
|
||||
<? } ?>
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#load "../../lib/app.uce"
|
||||
|
||||
RENDER(Request& context)
|
||||
{
|
||||
starter_boot(context);
|
||||
context.var["starter"]["page_type"] = "json";
|
||||
|
||||
DTree body = json_decode(context.in);
|
||||
if(context.params["REQUEST_METHOD"] == "POST" && body["oauth_service"].to_string() != "" && body["oauth_state"].to_string() != "")
|
||||
{
|
||||
context.session["oauth_service"] = body["oauth_service"].to_string();
|
||||
context.session["oauth_state"] = body["oauth_state"].to_string();
|
||||
context.var["starter"]["json"]["status"] = "success";
|
||||
}
|
||||
else
|
||||
{
|
||||
starter_set_status(context, 400, "Bad Request");
|
||||
context.var["starter"]["json"]["status"] = "error";
|
||||
context.var["starter"]["json"]["message"] = "Invalid input";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user