mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-11 17:32:41 +01:00
ef85f49adc
Summary: This commit doesn't change license of any file. It just makes the license implicit (inherited from LICENSE file in the root directory). We are removing the headers for these reasons: - It wastes space in editors, less code is visible in editor upon opening a file. - It brings noise to diff of the first change of any file every year. - It confuses Git file copy detection when creating small files. - We don't have an explicit license header in other files (JS, CSS, images, documentation). - Using license header in every file is not obligatory: http://www.apache.org/dev/apply-license.html#new. This change is approved by Alma Chao (Lead Open Source and IP Counsel at Facebook). Test Plan: Verified that the license survived only in LICENSE file and that it didn't modify externals. Reviewers: epriestley, davidrecordon Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2035 Differential Revision: https://secure.phabricator.com/D3886
153 lines
4.1 KiB
PHP
153 lines
4.1 KiB
PHP
<?php
|
|
|
|
final class PhabricatorEmailLoginController
|
|
extends PhabricatorAuthController {
|
|
|
|
public function shouldRequireLogin() {
|
|
return false;
|
|
}
|
|
|
|
public function processRequest() {
|
|
$request = $this->getRequest();
|
|
|
|
if (!PhabricatorEnv::getEnvConfig('auth.password-auth-enabled')) {
|
|
return new Aphront400Response();
|
|
}
|
|
|
|
$e_email = true;
|
|
$e_captcha = true;
|
|
$errors = array();
|
|
|
|
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
|
|
|
|
if ($request->isFormPost()) {
|
|
$e_email = null;
|
|
$e_captcha = 'Again';
|
|
|
|
$captcha_ok = AphrontFormRecaptchaControl::processCaptcha($request);
|
|
if (!$captcha_ok) {
|
|
$errors[] = "Captcha response is incorrect, try again.";
|
|
$e_captcha = 'Invalid';
|
|
}
|
|
|
|
$email = $request->getStr('email');
|
|
if (!strlen($email)) {
|
|
$errors[] = "You must provide an email address.";
|
|
$e_email = 'Required';
|
|
}
|
|
|
|
if (!$errors) {
|
|
// NOTE: Don't validate the email unless the captcha is good; this makes
|
|
// it expensive to fish for valid email addresses while giving the user
|
|
// a better error if they goof their email.
|
|
|
|
$target_email = id(new PhabricatorUserEmail())->loadOneWhere(
|
|
'address = %s',
|
|
$email);
|
|
|
|
$target_user = null;
|
|
if ($target_email) {
|
|
$target_user = id(new PhabricatorUser())->loadOneWhere(
|
|
'phid = %s',
|
|
$target_email->getUserPHID());
|
|
}
|
|
|
|
if (!$target_user) {
|
|
$errors[] = "There is no account associated with that email address.";
|
|
$e_email = "Invalid";
|
|
}
|
|
|
|
if (!$errors) {
|
|
$uri = $target_user->getEmailLoginURI($target_email);
|
|
if ($is_serious) {
|
|
$body = <<<EOBODY
|
|
You can use this link to reset your Phabricator password:
|
|
|
|
{$uri}
|
|
|
|
EOBODY;
|
|
} else {
|
|
$body = <<<EOBODY
|
|
Condolences on forgetting your password. You can use this link to reset it:
|
|
|
|
{$uri}
|
|
|
|
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.
|
|
|
|
Best Wishes,
|
|
Phabricator
|
|
|
|
EOBODY;
|
|
}
|
|
|
|
// NOTE: Don't set the user as 'from', or they may not receive the
|
|
// mail if they have the "don't send me email about my own actions"
|
|
// preference set.
|
|
|
|
$mail = new PhabricatorMetaMTAMail();
|
|
$mail->setSubject('[Phabricator] Password Reset');
|
|
$mail->addTos(
|
|
array(
|
|
$target_user->getPHID(),
|
|
));
|
|
$mail->setBody($body);
|
|
$mail->saveAndSend();
|
|
|
|
$view = new AphrontRequestFailureView();
|
|
$view->setHeader('Check Your Email');
|
|
$view->appendChild(
|
|
'<p>An email has been sent with a link you can use to login.</p>');
|
|
return $this->buildStandardPageResponse(
|
|
$view,
|
|
array(
|
|
'title' => 'Email Sent',
|
|
));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
$email_auth = new AphrontFormView();
|
|
$email_auth
|
|
->setAction('/login/email/')
|
|
->setUser($request->getUser())
|
|
->appendChild(
|
|
id(new AphrontFormTextControl())
|
|
->setLabel('Email')
|
|
->setName('email')
|
|
->setValue($request->getStr('email'))
|
|
->setError($e_email))
|
|
->appendChild(
|
|
id(new AphrontFormRecaptchaControl())
|
|
->setLabel('Captcha')
|
|
->setError($e_captcha))
|
|
->appendChild(
|
|
id(new AphrontFormSubmitControl())
|
|
->setValue('Send Email'));
|
|
|
|
$error_view = null;
|
|
if ($errors) {
|
|
$error_view = new AphrontErrorView();
|
|
$error_view->setTitle('Login Error');
|
|
$error_view->setErrors($errors);
|
|
}
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
|
|
$panel->appendChild('<h1>Forgot Password / Email Login</h1>');
|
|
$panel->appendChild($email_auth);
|
|
|
|
return $this->buildStandardPageResponse(
|
|
array(
|
|
$error_view,
|
|
$panel,
|
|
),
|
|
array(
|
|
'title' => 'Create New Account',
|
|
));
|
|
}
|
|
|
|
}
|