Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15423132
D20100.id48007.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D20100.id48007.diff
View Options
diff --git a/src/applications/auth/controller/PhabricatorAuthStartController.php b/src/applications/auth/controller/PhabricatorAuthStartController.php
--- a/src/applications/auth/controller/PhabricatorAuthStartController.php
+++ b/src/applications/auth/controller/PhabricatorAuthStartController.php
@@ -75,6 +75,11 @@
}
}
+ $configs = array();
+ foreach ($providers as $provider) {
+ $configs[] = $provider->getProviderConfig();
+ }
+
if (!$providers) {
if ($this->isFirstTimeSetup()) {
// If this is a fresh install, let the user register their admin
@@ -179,6 +184,8 @@
$custom_message = $this->newCustomStartMessage();
+ $email_login = $this->newEmailLoginView($configs);
+
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Login'));
$crumbs->setBorder(true);
@@ -188,6 +195,7 @@
$invite_message,
$custom_message,
$out,
+ $email_login,
);
return $this->newPage()
@@ -311,4 +319,43 @@
$remarkup_view);
}
+ private function newEmailLoginView(array $configs) {
+ assert_instances_of($configs, 'PhabricatorAuthProviderConfig');
+
+ // Check if password auth is enabled. If it is, the password login form
+ // renders a "Forgot password?" link, so we don't need to provide a
+ // supplemental link.
+
+ $has_password = false;
+ foreach ($configs as $config) {
+ $provider = $config->getProvider();
+ if ($provider instanceof PhabricatorPasswordAuthProvider) {
+ $has_password = true;
+ }
+ }
+
+ if ($has_password) {
+ return null;
+ }
+
+ $view = array(
+ pht('Trouble logging in?'),
+ ' ',
+ phutil_tag(
+ 'a',
+ array(
+ 'href' => '/login/email/',
+ ),
+ pht('Send a login link to your email address.')),
+ );
+
+ return phutil_tag(
+ 'div',
+ array(
+ 'class' => 'auth-custom-message',
+ ),
+ $view);
+ }
+
+
}
diff --git a/src/applications/auth/controller/PhabricatorEmailLoginController.php b/src/applications/auth/controller/PhabricatorEmailLoginController.php
--- a/src/applications/auth/controller/PhabricatorEmailLoginController.php
+++ b/src/applications/auth/controller/PhabricatorEmailLoginController.php
@@ -8,17 +8,13 @@
}
public function handleRequest(AphrontRequest $request) {
-
- if (!PhabricatorPasswordAuthProvider::getPasswordProvider()) {
- return new Aphront400Response();
- }
+ $viewer = $this->getViewer();
$e_email = true;
$e_captcha = true;
$errors = array();
- $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
-
+ $v_email = $request->getStr('email');
if ($request->isFormPost()) {
$e_email = null;
$e_captcha = pht('Again');
@@ -29,8 +25,7 @@
$e_captcha = pht('Invalid');
}
- $email = $request->getStr('email');
- if (!strlen($email)) {
+ if (!strlen($v_email)) {
$errors[] = pht('You must provide an email address.');
$e_email = pht('Required');
}
@@ -42,7 +37,7 @@
$target_email = id(new PhabricatorUserEmail())->loadOneWhere(
'address = %s',
- $email);
+ $v_email);
$target_user = null;
if ($target_email) {
@@ -81,33 +76,10 @@
}
if (!$errors) {
- $engine = new PhabricatorAuthSessionEngine();
- $uri = $engine->getOneTimeLoginURI(
- $target_user,
- null,
- PhabricatorAuthSessionEngine::ONETIME_RESET);
-
- if ($is_serious) {
- $body = pht(
- "You can use this link to reset your Phabricator password:".
- "\n\n %s\n",
- $uri);
- } else {
- $body = pht(
- "Condolences on forgetting your password. You can use this ".
- "link to reset it:\n\n".
- " %s\n\n".
- "After you set a new password, consider writing it down on a ".
- "sticky note and attaching it to your monitor so you don't ".
- "forget again! Choosing a very short, easy-to-remember password ".
- "like \"cat\" or \"1234\" might also help.\n\n".
- "Best Wishes,\nPhabricator\n",
- $uri);
-
- }
+ $body = $this->newAccountLoginMailBody($target_user);
$mail = id(new PhabricatorMetaMTAMail())
- ->setSubject(pht('[Phabricator] Password Reset'))
+ ->setSubject(pht('[Phabricator] Account Login Link'))
->setForceDelivery(true)
->addRawTos(array($target_email->getAddress()))
->setBody($body)
@@ -123,44 +95,90 @@
}
}
- $error_view = null;
- if ($errors) {
- $error_view = new PHUIInfoView();
- $error_view->setErrors($errors);
+ $form = id(new AphrontFormView())
+ ->setViewer($viewer);
+
+ if ($this->isPasswordAuthEnabled()) {
+ $form->appendRemarkupInstructions(
+ pht(
+ 'To reset your password, provide your email address. An email '.
+ 'with a login link will be sent to you.'));
+ } else {
+ $form->appendRemarkupInstructions(
+ pht(
+ 'To access your account, provide your email address. An email '.
+ 'with a login link will be sent to you.'));
}
- $email_auth = new PHUIFormLayoutView();
- $email_auth->appendChild($error_view);
- $email_auth
- ->setUser($request->getUser())
- ->setFullWidth(true)
- ->appendChild(
+ $form
+ ->appendControl(
id(new AphrontFormTextControl())
- ->setLabel(pht('Email'))
+ ->setLabel(pht('Email Address'))
->setName('email')
- ->setValue($request->getStr('email'))
+ ->setValue($v_email)
->setError($e_email))
- ->appendChild(
+ ->appendControl(
id(new AphrontFormRecaptchaControl())
->setLabel(pht('Captcha'))
->setError($e_captcha));
- $crumbs = $this->buildApplicationCrumbs();
- $crumbs->addTextCrumb(pht('Reset Password'));
- $crumbs->setBorder(true);
+ if ($this->isPasswordAuthEnabled()) {
+ $title = pht('Password Reset');
+ } else {
+ $title = pht('Email Login');
+ }
+
+ return $this->newDialog()
+ ->setTitle($title)
+ ->setErrors($errors)
+ ->setWidth(AphrontDialogView::WIDTH_FORM)
+ ->appendForm($form)
+ ->addCancelButton('/auth/start/')
+ ->addSubmitButton(pht('Send Email'));
+ }
- $dialog = new AphrontDialogView();
- $dialog->setUser($request->getUser());
- $dialog->setTitle(pht('Forgot Password / Email Login'));
- $dialog->appendChild($email_auth);
- $dialog->addSubmitButton(pht('Send Email'));
- $dialog->setSubmitURI('/login/email/');
+ private function newAccountLoginMailBody(PhabricatorUser $user) {
+ $engine = new PhabricatorAuthSessionEngine();
+ $uri = $engine->getOneTimeLoginURI(
+ $user,
+ null,
+ PhabricatorAuthSessionEngine::ONETIME_RESET);
- return $this->newPage()
- ->setTitle(pht('Forgot Password'))
- ->setCrumbs($crumbs)
- ->appendChild($dialog);
+ $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
+ $have_passwords = $this->isPasswordAuthEnabled();
+
+ if ($have_passwords) {
+ if ($is_serious) {
+ $body = pht(
+ "You can use this link to reset your Phabricator password:".
+ "\n\n %s\n",
+ $uri);
+ } else {
+ $body = pht(
+ "Condolences on forgetting your password. You can use this ".
+ "link to reset it:\n\n".
+ " %s\n\n".
+ "After you set a new password, consider writing it down on a ".
+ "sticky note and attaching it to your monitor so you don't ".
+ "forget again! Choosing a very short, easy-to-remember password ".
+ "like \"cat\" or \"1234\" might also help.\n\n".
+ "Best Wishes,\nPhabricator\n",
+ $uri);
+ }
+ } else {
+ $body = pht(
+ "You can use this login link to regain access to your Phabricator ".
+ "account:".
+ "\n\n".
+ " %s\n",
+ $uri);
+ }
+
+ return $body;
}
+ private function isPasswordAuthEnabled() {
+ return (bool)PhabricatorPasswordAuthProvider::getPasswordProvider();
+ }
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 23, 1:20 PM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7332252
Default Alt Text
D20100.id48007.diff (8 KB)
Attached To
Mode
D20100: Always allow users to login via email link, even if an install does not use passwords
Attached
Detach File
Event Timeline
Log In to Comment