diff --git a/etc/pages.json b/etc/pages.json index f0d846962..4ff01d6f3 100644 --- a/etc/pages.json +++ b/etc/pages.json @@ -186,6 +186,14 @@ "name": "resetpassword/request", "order": 100, "request_function": "*Signin_Page::reset_request" }, + { + "name": "resetpassword/request/basic", "order": 100, + "signin_function": "*Signin_Page::reset_request_basic" + }, + { + "name": "resetpassword/request/success", "order": 100000, + "signin_function": "*Signin_Page::reset_request_success" + }, [ "resetpassword/head", 1000, "Signin_Page::print_reset_head" ], [ "resetpassword/body", 3000, "*Signin_Page::print_reset_body" ], [ "resetpassword/form/title", 1, "Signin_Page::print_reset_form_title" ], diff --git a/src/pages/p_signin.php b/src/pages/p_signin.php index cbf5167ea..7495d3c82 100644 --- a/src/pages/p_signin.php +++ b/src/pages/p_signin.php @@ -48,36 +48,36 @@ private function problem_status_at($field) { /** @param ComponentSet $cs */ function signin_request(Contact $user, Qrequest $qreq, $cs) { assert($qreq->method() === "POST"); + $conf = $user->conf; if ($qreq->cancel) { $info = ["ok" => false]; foreach ($cs->members("signin/request") as $gj) { - $info = call_user_func($gj->signin_function, $user, $qreq, $info, $gj); + $info = $cs->call_function($gj, $gj->signin_function, $info, $gj); } - $user->conf->redirect(); - } else if ($user->conf->opt("httpAuthLogin")) { + $conf->redirect(); + } else if ($conf->opt("httpAuthLogin")) { LoginHelper::check_http_auth($user, $qreq); - } else if ($qreq->valid_post()) { - if (!$user->is_empty() && strcasecmp($qreq->email, $user->email) === 0) { - $user->conf->redirect(); - } else if (!$qreq->start) { - $info = ["ok" => true]; - foreach ($cs->members("signin/request") as $gj) { - $info = call_user_func($gj->signin_function, $user, $qreq, $info, $gj); - } - if ($info["ok"] || isset($info["redirect"])) { - $user->conf->redirect($info["redirect"] ?? ""); - } else if (($code = self::check_password_as_reset_code($user, $qreq))) { - $user->conf->redirect_hoturl("resetpassword", ["__PATH__" => $code]); - } else { - LoginHelper::login_error($user->conf, $qreq->email, $info, $this->ms()); - } - } - } else { + } else if (!$qreq->valid_post()) { self::bad_post_error($user, $qreq, "signin"); + } else if (!$user->is_empty() + && strcasecmp($qreq->email, $user->email) === 0) { + $conf->redirect(); + } else if (!$qreq->start) { + $info = ["ok" => true]; + foreach ($cs->members("signin/request") as $gj) { + $info = $cs->call_function($gj, $gj->signin_function, $info, $gj); + } + if ($info["ok"] || isset($info["redirect"])) { + $conf->redirect($info["redirect"] ?? ""); + } else if (($code = self::check_password_as_reset_code($user, $qreq))) { + $conf->redirect_hoturl("resetpassword", ["__PATH__" => $code]); + } else { + LoginHelper::login_error($conf, $qreq->email, $info, $this->ms()); + } } } - static function signin_request_basic(Contact $user, Qrequest $qreq, $info) { + static function signin_request_basic(Contact $user, Qrequest $qreq, $cs, $info) { if (!$info["ok"]) { return $info; } else if ($user->conf->external_login()) { @@ -87,7 +87,7 @@ static function signin_request_basic(Contact $user, Qrequest $qreq, $info) { } } - static function signin_request_success(Contact $user, Qrequest $qreq, $info) { + static function signin_request_success(Contact $user, Qrequest $qreq, $cs, $info) { if (!$info["ok"]) { return $info; } else { @@ -99,7 +99,7 @@ static function signin_request_success(Contact $user, Qrequest $qreq, $info) { * @return ?TokenInfo */ static private function _find_reset_token(Conf $conf, $token) { if ($token) { - $is_cdb = str_starts_with($token, "2") /* XXX */ || str_starts_with($token, "hcpw1"); + $is_cdb = str_starts_with($token, "hcpw1"); if (($tok = TokenInfo::find($token, $conf, $is_cdb)) && $tok->is_active() && $tok->capabilityType === TokenInfo::RESETPASSWORD) { @@ -172,7 +172,7 @@ static function print_signin_form(Contact $user, Qrequest $qreq, $cs) { } static function print_signin_form_title(Contact $user, Qrequest $qreq) { - echo '

Sign in

'; + echo '

Sign in

'; } static function print_signin_form_description(Contact $user, Qrequest $qreq) { @@ -194,10 +194,10 @@ function print_signin_form_email(Contact $user, Qrequest $qreq) { $is_external_login = $user->conf->external_login(); $email = $qreq->email ?? ""; echo '
', - Ht::label($is_external_login ? "Username" : "Email", "signin_email"), + Ht::label($is_external_login ? "Username" : "Email", "k-email"), $this->feedback_html_at("email"), Ht::entry("email", $email, [ - "size" => 36, "id" => "signin_email", "class" => "fullw", + "size" => 36, "id" => "k-email", "class" => "fullw", "autocomplete" => "username", "tabindex" => 1, "type" => !$is_external_login && !str_ends_with($email, "@_.com") ? "email" : "text", "autofocus" => $this->problem_status_at("email") @@ -215,18 +215,18 @@ function print_signin_form_password(Contact $user, Qrequest $qreq) { '" class="n ulh small uic js-href-add-email">Forgot your password?
'; } $password_reset = $qreq->csession("password_reset"); - echo Ht::label("Password", "signin_password"), + echo Ht::label("Password", "k-password"), $this->feedback_html_at("password"), Ht::password("password", $this->problem_status_at("password") !== 1 ? "" : $qreq->password, [ - "size" => 36, "id" => "signin_password", "class" => "fullw", + "size" => 36, "id" => "k-password", "class" => "fullw", "autocomplete" => "current-password", "tabindex" => 1, "autofocus" => !$this->problem_status_at("email") && $qreq->email && ($this->problem_status_at("password") || $password_reset) ]), ''; if ($password_reset) { - echo Ht::unstash_script("\$(function(){\$(\"#signin_password\").val(" . json_encode_browser($password_reset->password) . ")})"); + echo Ht::unstash_script("\$(function(){\$(\"#k-password\").val(" . json_encode_browser($password_reset->password) . ")})"); } } @@ -272,7 +272,7 @@ static function print_signout(Contact $user, Qrequest $qreq, $cs) { } else { $qreq->print_header("Sign out", "signout", ["action_bar" => "", "hide_title" => true, "body_class" => "body-signin"]); self::print_form_start_for($qreq, "signout"); - echo '

Sign out

', + echo '

Sign out

', $user->conf->_("Use this page to sign out of the site."), '