Skip to content

Commit

Permalink
Hide other accounts behind a button on authorize.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Jan 21, 2024
1 parent a9b8e31 commit bd473e3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
6 changes: 3 additions & 3 deletions etc/pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@

{ "name": "authorize", "print_function": "*Authorize_Page::go", "allow_disabled": true },
[ "authorize/form/title", 1, "*Authorize_Page::print_form_title" ],
[ "authorize/form/active", 15, "*Authorize_Page::print_form_active" ],
[ "authorize/form/local", 20, "signin/form/local" ],
[ "authorize/form/oauth", 1000, "*Signin_Page::print_signin_form_oauth" ],
[ "authorize/form/main", 15, "*Authorize_Page::print_form_main" ],
[ "authorize/form/annotation", 2000, "*Authorize_Page::print_form_annotation" ],
[ "authorize/other/local", 15, "signin/form/local" ],
[ "authorize/other/oauth", 1000, "signin/form/oauth" ],


{ "name": "api", "print_function": "API_Page::go", "allow_disabled": true },
Expand Down
6 changes: 6 additions & 0 deletions src/conference.php
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,12 @@ function external_login() {
return $lt === "ldap" || $lt === "htauth";
}

/** @return bool */
function allow_local_signin() {
$lt = $this->login_type();
return $lt !== "none" && $lt !== "oauth";
}

/** @return bool */
function allow_user_self_register() {
return !$this->disable_non_pc && !$this->opt("disableNewUsers");
Expand Down
25 changes: 14 additions & 11 deletions src/pages/p_authorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,28 +177,31 @@ function print_form_annotation() {
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() {
function print_form_main() {
$buttons = [];
$nav = $this->qreq->navigation();
$top = "";
foreach (Contact::session_users($this->qreq) as $i => $email) {
if ($email === "") {
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 btn-primary"]);
$buttons[] = Ht::button("Sign in as " . htmlspecialchars($email), ["type" => "submit", "formaction" => $url, "formmethod" => "post", "class" => "btn-primary{$top} w-100 flex-grow-1"]);
$top = " mt-2";
}

$local = $this->conf->allow_local_signin();
if (!empty($buttons) && $local) {
$buttons[] = Ht::button("Use another account", ["type" => "button", "class" => "ui js-foldup{$top} w-100 flex-grow-1", "data-fold-target" => "p-authorize-other#2o"]);
}
if (!empty($buttons)) {
echo '<div class="mb-4">', join("", $buttons), '</div>';
echo '<div class="mb-5">', join("", $buttons), '</div>';
}
}

function print_form_actions() {
if (($lt = $this->conf->login_type()) === "none" || $lt === "oauth") {
return;
if ($local) {
echo '<div id="p-authorize-other" class="', empty($buttons) ? 'mt-3' : 'has-fold fold2c ui-fold js-fold-focus"><div class="mt-3 fx2', '">';
$this->cs->print_members("authorize/other");
echo empty($buttons) ? '</div>' : '</div></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
17 changes: 9 additions & 8 deletions src/pages/p_signin.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ function signin_request(Contact $user, Qrequest $qreq, $cs) {
$info = $cs->call_function($gj, $gj->signin_function, $info, $gj);
}
$conf->redirect();
} else if (($lt = $conf->login_type()) === "none" || $lt === "oauth") {
} else if (!$conf->allow_local_signin()) {
// do nothing
} else if ($lt === "htauth") {
} else if ($conf->login_type() === "htauth") {
LoginHelper::check_http_auth($user, $qreq);
} else if (!$qreq->valid_post()) {
self::bad_post_error($user, $qreq, "signin");
Expand Down Expand Up @@ -194,12 +194,11 @@ static function print_signin_form_accounts(Contact $user, Qrequest $qreq) {
}

static function print_signin_form_local(Contact $user, Qrequest $qreq, ComponentSet $cs) {
if (($lt = $user->conf->login_type()) === "none" || $lt === "oauth") {
return;
if ($user->conf->allow_local_signin()) {
echo '<div class="mt-3">';
$cs->print_members("__local_signin");
echo '</div>';
}
echo '<div class="mt-3">';
$cs->print_members("__local_signin");
echo '</div>';
}

function print_signin_form_email(Contact $user, Qrequest $qreq) {
Expand Down Expand Up @@ -262,10 +261,12 @@ function print_signin_form_oauth(Contact $user, Qrequest $qreq) {
}
$buttons = [];
$param = array_merge(["authtype" => null, "post" => $qreq->maybe_post_value()], $this->_oauth_hoturl_param ?? ["redirect" => $qreq->redirect]);
$top = "";
foreach ($conf->oauth_providers() as $authdata) {
if ($authdata->button_html && !($authdata->disabled ?? false)) {
$param["authtype"] = $authdata->name;
$buttons[] = Ht::button($authdata->button_html, ["type" => "submit", "formaction" => $conf->hoturl("oauth", $param), "formmethod" => "post", "class" => "mt-2 w-100 flex-grow-1"]);
$buttons[] = Ht::button($authdata->button_html, ["type" => "submit", "formaction" => $conf->hoturl("oauth", $param), "formmethod" => "post", "class" => "{$top}w-100 flex-grow-1"]);
$top = "mt-2 ";
}
}
if (!empty($buttons)) {
Expand Down

0 comments on commit bd473e3

Please sign in to comment.