Skip to content

Commit

Permalink
Improve authorize page.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Jan 21, 2024
1 parent 65745ad commit 3889bf0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions etc/pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@

{ "name": "authorize", "print_function": "*Authorize_Page::go", "allow_disabled": true },
[ "authorize/form/title", 1, "*Authorize_Page::print_form_title" ],
[ "authorize/form/description", 10, "*Authorize_Page::print_form_description" ],
[ "authorize/form/active", 15, "*Authorize_Page::print_form_active" ],
[ "authorize/form/email", 20, "signin/form/email" ],
[ "authorize/form/password", 30, "signin/form/password" ],
[ "authorize/form/actions", 100, "*Authorize_Page::print_form_actions" ],
[ "authorize/form/oauth", 1000, "Signin_Page::print_signin_form_oauth" ],
[ "authorize/form/oauth", 1000, "*Signin_Page::print_signin_form_oauth" ],
[ "authorize/form/annotation", 2000, "*Authorize_Page::print_form_annotation" ],


{ "name": "api", "print_function": "API_Page::go", "allow_disabled": true },
Expand Down
35 changes: 22 additions & 13 deletions src/pages/p_authorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class OAuthClient {
public $client_id;
/** @var string */
public $client_secret;
/** @var ?string */
public $client_uri;
/** @var list<string> */
public $redirect_uri = [];

Expand All @@ -27,6 +29,7 @@ static function make($x) {
$oac->title = $x->title ?? null;
$oac->client_id = $x->client_id ?? null;
$oac->client_secret = $x->client_secret ?? null;
$oac->client_uri = $x->client_uri ?? null;
if (isset($x->redirect_uri)) {
if (is_string($x->redirect_uri)) {
$oac->redirect_uri[] = $x->redirect_uri;
Expand Down Expand Up @@ -63,6 +66,8 @@ class Authorize_Page {
public $qreq;
/** @var ComponentSet */
public $cs;
/** @var OAuthClient */
public $client;
/** @var array<string,object> */
private $clients = [];
/** @var TokenInfo */
Expand Down Expand Up @@ -147,7 +152,8 @@ private function handle_request(OAuthClient $client) {
->change_data("redirect_uri", $this->qreq->redirect_uri);
$this->token->create();

$this->qreq->print_header("Sign in", "authorize", ["action_bar" => "", "hide_title" => true, "body_class" => "body-signin"]);
$this->client = $client;
$this->qreq->print_header("Sign in", "authorize", ["action_bar" => "", "hide_header" => true, "body_class" => "body-signin"]);
Signin_Page::print_form_start_for($this->qreq, "=signin");
$nav = $this->qreq->navigation();
echo Ht::hidden("redirect", "authorize{$nav->php_suffix}?code=" . urlencode($this->token->salt) . "&authconfirm=1");
Expand All @@ -158,11 +164,17 @@ private function handle_request(OAuthClient $client) {
}

function print_form_title() {
echo '<h1>Sign in</h1>';
echo '<h1>Choose an account</h1>';
$clt = htmlspecialchars($this->client->title ?? $this->client->name);
if ($this->client->client_uri) {
$clt = Ht::link($clt, htmlspecialchars($this->client->client_uri));
}
echo '<div class="mb-4">to continue to ', $clt, '</div>';
}

function print_form_description() {

function print_form_annotation() {
$clt = htmlspecialchars($this->client->title ?? $this->client->name);
echo '<p class="mt-4 mb-0 hint">If you continue, HotCRP.com will share your name, email address, affiliation, and other profile information with ', $clt, '.</p>';
}

function print_form_active() {
Expand All @@ -173,23 +185,20 @@ function print_form_active() {
continue;
}
$url = $nav->base_absolute() . "u/{$i}/authorize{$nav->php_suffix}?code=" . urlencode($this->token->salt) . "&authconfirm=1";
$buttons[] = Ht::button("Sign in as " . htmlspecialchars($email), ["type" => "submit", "formaction" => $url, "formmethod" => "post", "class" => "mt-2 w-100 flex-grow-1"]);
$buttons[] = Ht::button("Sign in as " . htmlspecialchars($email), ["type" => "submit", "formaction" => $url, "formmethod" => "post", "class" => "mt-2 w-100 flex-grow-1 btn-primary"]);
}
if (!empty($buttons)) {
echo '<div class="mt-4">', join("", $buttons), '</div>';
echo '<div class="mb-4">', join("", $buttons), '</div>';
}
}

function print_form_actions() {
if (($lt = $this->conf->login_type()) === "none" || $lt === "oauth") {
return;
}
echo '<div class="popup-actions">',
Ht::submit("", "Sign in", ["id" => "k-signin", "class" => "btn-success", "tabindex" => 1]);
if ($this->cs->root !== "home") {
echo Ht::submit("cancel", "Cancel", ["tabindex" => 1, "formnovalidate" => true, "class" => "uic js-no-signin"]);
}
echo '</div>';
echo '<div class="mt-3">',
Ht::submit("", "Sign in", ["id" => "k-signin", "class" => "btn-success w-100 flex-grow-1", "tabindex" => 1]),
'</div>';
}

private function handle_authconfirm() {
Expand Down Expand Up @@ -264,7 +273,7 @@ private function print_error_exit($m) {
if (http_response_code() === 200) {
http_response_code(400);
}
$this->qreq->print_header("Sign in", "authorize", ["action_bar" => "", "body_class" => "body-error"]);
$this->qreq->print_header("Sign in", "authorize", ["action_bar" => "", "hide_header" => true, "body_class" => "body-error"]);
$this->conf->error_msg($m);
$this->qreq->print_footer();
exit;
Expand Down
2 changes: 1 addition & 1 deletion stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ strong.overdue {
background: var(--brand-bg);
margin-left: auto;
margin-right: auto;
max-width: 600px;
max-width: 500px;
width: fit-content;
}
.signingrp.homegrp {
Expand Down

0 comments on commit 3889bf0

Please sign in to comment.