2011-01-16 22:51:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-01-15 10:07:56 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-01-16 22:51:39 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-01-23 02:48:55 +01:00
|
|
|
abstract class PhabricatorController extends AphrontController {
|
2011-01-16 22:51:39 +01:00
|
|
|
|
2011-01-26 22:21:12 +01:00
|
|
|
public function shouldRequireLogin() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-05-12 19:06:54 +02:00
|
|
|
public function shouldRequireAdmin() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldRequireEnabledUser() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Allow installs to require email verification
Summary:
Allow installs to require users to verify email addresses before they can use Phabricator. If a user logs in without a verified email address, they're given instructions to verify their address.
This isn't too useful on its own since we don't actually have arbitrary email registration, but the next step is to allow installs to restrict email to only some domains (e.g., @mycompany.com).
Test Plan:
- Verification
- Set verification requirement to `true`.
- Tried to use Phabricator with an unverified account, was told to verify.
- Tried to use Conduit, was given a verification error.
- Verified account, used Phabricator.
- Unverified account, reset password, verified implicit verification, used Phabricator.
- People Admin Interface
- Viewed as admin. Clicked "Administrate User".
- Viewed as non-admin
- Sanity Checks
- Used Conduit normally from web/CLI with a verified account.
- Logged in/out.
- Sent password reset email.
- Created a new user.
- Logged in with an unverified user but with the configuration set to off.
Reviewers: btrahan, vrana, jungejason
Reviewed By: btrahan
CC: aran, csilvers
Maniphest Tasks: T1184
Differential Revision: https://secure.phabricator.com/D2520
2012-05-21 21:47:38 +02:00
|
|
|
public function shouldRequireEmailVerification() {
|
Allow restriction of permitted email domains
Summary:
Allow allowed email addresses to be restricted to certain domains. This implies email must be verified.
This probably isn't QUITE ready for prime-time without a few other tweaks (better administrative tools, notably) but we're nearly there.
Test Plan:
- With no restrictions:
- Registered with OAuth
- Created an account with accountadmin
- Added an email
- With restrictions:
- Tried to OAuth register with a restricted address, was prompted to provide a valid one.
- Tried to OAuth register with a valid address, worked fine.
- Tried to accountadmin a restricted address, got blocked.
- Tried to accountadmin a valid address, worked fine.
- Tried to add a restricted address, blocked.
- Tried to add a valid address, worked fine.
- Created a user with People with an invalid address, got blocked.
- Created a user with People with a valid address, worked fine.
Reviewers: btrahan, csilvers
Reviewed By: csilvers
CC: aran, joe, csilvers
Maniphest Tasks: T1184
Differential Revision: https://secure.phabricator.com/D2581
2012-05-26 15:04:35 +02:00
|
|
|
$need_verify = PhabricatorUserEmail::isEmailVerificationRequired();
|
Allow installs to require email verification
Summary:
Allow installs to require users to verify email addresses before they can use Phabricator. If a user logs in without a verified email address, they're given instructions to verify their address.
This isn't too useful on its own since we don't actually have arbitrary email registration, but the next step is to allow installs to restrict email to only some domains (e.g., @mycompany.com).
Test Plan:
- Verification
- Set verification requirement to `true`.
- Tried to use Phabricator with an unverified account, was told to verify.
- Tried to use Conduit, was given a verification error.
- Verified account, used Phabricator.
- Unverified account, reset password, verified implicit verification, used Phabricator.
- People Admin Interface
- Viewed as admin. Clicked "Administrate User".
- Viewed as non-admin
- Sanity Checks
- Used Conduit normally from web/CLI with a verified account.
- Logged in/out.
- Sent password reset email.
- Created a new user.
- Logged in with an unverified user but with the configuration set to off.
Reviewers: btrahan, vrana, jungejason
Reviewed By: btrahan
CC: aran, csilvers
Maniphest Tasks: T1184
Differential Revision: https://secure.phabricator.com/D2520
2012-05-21 21:47:38 +02:00
|
|
|
$need_login = $this->shouldRequireLogin();
|
|
|
|
|
|
|
|
return ($need_login && $need_verify);
|
|
|
|
}
|
|
|
|
|
2011-01-26 22:21:12 +01:00
|
|
|
final public function willBeginExecution() {
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
$user = new PhabricatorUser();
|
|
|
|
|
|
|
|
$phusr = $request->getCookie('phusr');
|
|
|
|
$phsid = $request->getCookie('phsid');
|
|
|
|
|
|
|
|
if ($phusr && $phsid) {
|
|
|
|
$info = queryfx_one(
|
|
|
|
$user->establishConnection('r'),
|
|
|
|
'SELECT u.* FROM %T u JOIN %T s ON u.phid = s.userPHID
|
Enable multiple web sessions
Summary:
Conduit already has multiple-session code, just move it to the main
establishSession() method and set a web session limit larger than 1.
NOTE: This will log everyone out since we no longer look for the "web" session,
only for "web-1", "web-2", ..., etc. Presumably this doesn't matter.
Test Plan:
Applied patch, was logged out. Logged in in Safari. Verified I was issued
"web-1". Logged in in Firefox. Verified I was issued "web-2".
Kept logging in and out until I got issued "web-5", then did it again and was
issued "web-1" with a new key.
Ran conduit methods and verified they work and correctly cycled session keys.
Reviewed By: tuomaspelkonen
Reviewers: tuomaspelkonen, jungejason, aran
Commenters: jungejason
CC: rm, fzamore, ola, aran, epriestley, jungejason, tuomaspelkonen
Differential Revision: 264
2011-05-11 13:52:32 +02:00
|
|
|
AND s.type LIKE %> AND s.sessionKey = %s',
|
2011-01-26 22:21:12 +01:00
|
|
|
$user->getTableName(),
|
|
|
|
'phabricator_session',
|
Enable multiple web sessions
Summary:
Conduit already has multiple-session code, just move it to the main
establishSession() method and set a web session limit larger than 1.
NOTE: This will log everyone out since we no longer look for the "web" session,
only for "web-1", "web-2", ..., etc. Presumably this doesn't matter.
Test Plan:
Applied patch, was logged out. Logged in in Safari. Verified I was issued
"web-1". Logged in in Firefox. Verified I was issued "web-2".
Kept logging in and out until I got issued "web-5", then did it again and was
issued "web-1" with a new key.
Ran conduit methods and verified they work and correctly cycled session keys.
Reviewed By: tuomaspelkonen
Reviewers: tuomaspelkonen, jungejason, aran
Commenters: jungejason
CC: rm, fzamore, ola, aran, epriestley, jungejason, tuomaspelkonen
Differential Revision: 264
2011-05-11 13:52:32 +02:00
|
|
|
'web-',
|
2011-01-26 22:21:12 +01:00
|
|
|
$phsid);
|
|
|
|
if ($info) {
|
|
|
|
$user->loadFromArray($info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-15 03:08:06 +02:00
|
|
|
$translation = $user->getTranslation();
|
|
|
|
if ($translation &&
|
2012-06-16 08:21:25 +02:00
|
|
|
$translation != PhabricatorEnv::getEnvConfig('translation.provider')) {
|
2012-06-15 03:08:06 +02:00
|
|
|
$translation = newv($translation, array());
|
|
|
|
PhutilTranslator::getInstance()
|
|
|
|
->setLanguage($translation->getLanguage())
|
|
|
|
->addTranslations($translation->getTranslations());
|
|
|
|
}
|
|
|
|
|
2011-01-26 22:21:12 +01:00
|
|
|
$request->setUser($user);
|
2011-02-05 21:20:18 +01:00
|
|
|
|
2011-05-12 19:06:54 +02:00
|
|
|
if ($user->getIsDisabled() && $this->shouldRequireEnabledUser()) {
|
2012-05-31 01:38:53 +02:00
|
|
|
$disabled_user_controller = new PhabricatorDisabledUserController(
|
|
|
|
$request);
|
2011-05-12 19:06:54 +02:00
|
|
|
return $this->delegateToController($disabled_user_controller);
|
|
|
|
}
|
|
|
|
|
2011-02-05 20:45:13 +01:00
|
|
|
if (PhabricatorEnv::getEnvConfig('darkconsole.enabled')) {
|
|
|
|
if ($user->getConsoleEnabled() ||
|
|
|
|
PhabricatorEnv::getEnvConfig('darkconsole.always-on')) {
|
|
|
|
$console = new DarkConsoleCore();
|
|
|
|
$request->getApplicationConfiguration()->setConsole($console);
|
|
|
|
}
|
|
|
|
}
|
2011-01-26 22:21:12 +01:00
|
|
|
|
Allow restriction of permitted email domains
Summary:
Allow allowed email addresses to be restricted to certain domains. This implies email must be verified.
This probably isn't QUITE ready for prime-time without a few other tweaks (better administrative tools, notably) but we're nearly there.
Test Plan:
- With no restrictions:
- Registered with OAuth
- Created an account with accountadmin
- Added an email
- With restrictions:
- Tried to OAuth register with a restricted address, was prompted to provide a valid one.
- Tried to OAuth register with a valid address, worked fine.
- Tried to accountadmin a restricted address, got blocked.
- Tried to accountadmin a valid address, worked fine.
- Tried to add a restricted address, blocked.
- Tried to add a valid address, worked fine.
- Created a user with People with an invalid address, got blocked.
- Created a user with People with a valid address, worked fine.
Reviewers: btrahan, csilvers
Reviewed By: csilvers
CC: aran, joe, csilvers
Maniphest Tasks: T1184
Differential Revision: https://secure.phabricator.com/D2581
2012-05-26 15:04:35 +02:00
|
|
|
if ($this->shouldRequireLogin() && !$user->getPHID()) {
|
2012-05-31 01:38:53 +02:00
|
|
|
$login_controller = new PhabricatorLoginController($request);
|
Allow restriction of permitted email domains
Summary:
Allow allowed email addresses to be restricted to certain domains. This implies email must be verified.
This probably isn't QUITE ready for prime-time without a few other tweaks (better administrative tools, notably) but we're nearly there.
Test Plan:
- With no restrictions:
- Registered with OAuth
- Created an account with accountadmin
- Added an email
- With restrictions:
- Tried to OAuth register with a restricted address, was prompted to provide a valid one.
- Tried to OAuth register with a valid address, worked fine.
- Tried to accountadmin a restricted address, got blocked.
- Tried to accountadmin a valid address, worked fine.
- Tried to add a restricted address, blocked.
- Tried to add a valid address, worked fine.
- Created a user with People with an invalid address, got blocked.
- Created a user with People with a valid address, worked fine.
Reviewers: btrahan, csilvers
Reviewed By: csilvers
CC: aran, joe, csilvers
Maniphest Tasks: T1184
Differential Revision: https://secure.phabricator.com/D2581
2012-05-26 15:04:35 +02:00
|
|
|
return $this->delegateToController($login_controller);
|
|
|
|
}
|
|
|
|
|
Allow installs to require email verification
Summary:
Allow installs to require users to verify email addresses before they can use Phabricator. If a user logs in without a verified email address, they're given instructions to verify their address.
This isn't too useful on its own since we don't actually have arbitrary email registration, but the next step is to allow installs to restrict email to only some domains (e.g., @mycompany.com).
Test Plan:
- Verification
- Set verification requirement to `true`.
- Tried to use Phabricator with an unverified account, was told to verify.
- Tried to use Conduit, was given a verification error.
- Verified account, used Phabricator.
- Unverified account, reset password, verified implicit verification, used Phabricator.
- People Admin Interface
- Viewed as admin. Clicked "Administrate User".
- Viewed as non-admin
- Sanity Checks
- Used Conduit normally from web/CLI with a verified account.
- Logged in/out.
- Sent password reset email.
- Created a new user.
- Logged in with an unverified user but with the configuration set to off.
Reviewers: btrahan, vrana, jungejason
Reviewed By: btrahan
CC: aran, csilvers
Maniphest Tasks: T1184
Differential Revision: https://secure.phabricator.com/D2520
2012-05-21 21:47:38 +02:00
|
|
|
if ($this->shouldRequireEmailVerification()) {
|
|
|
|
$email = $user->loadPrimaryEmail();
|
|
|
|
if (!$email) {
|
|
|
|
throw new Exception(
|
|
|
|
"No primary email address associated with this account!");
|
|
|
|
}
|
|
|
|
if (!$email->getIsVerified()) {
|
2012-05-31 01:38:53 +02:00
|
|
|
$verify_controller = new PhabricatorMustVerifyEmailController($request);
|
Allow installs to require email verification
Summary:
Allow installs to require users to verify email addresses before they can use Phabricator. If a user logs in without a verified email address, they're given instructions to verify their address.
This isn't too useful on its own since we don't actually have arbitrary email registration, but the next step is to allow installs to restrict email to only some domains (e.g., @mycompany.com).
Test Plan:
- Verification
- Set verification requirement to `true`.
- Tried to use Phabricator with an unverified account, was told to verify.
- Tried to use Conduit, was given a verification error.
- Verified account, used Phabricator.
- Unverified account, reset password, verified implicit verification, used Phabricator.
- People Admin Interface
- Viewed as admin. Clicked "Administrate User".
- Viewed as non-admin
- Sanity Checks
- Used Conduit normally from web/CLI with a verified account.
- Logged in/out.
- Sent password reset email.
- Created a new user.
- Logged in with an unverified user but with the configuration set to off.
Reviewers: btrahan, vrana, jungejason
Reviewed By: btrahan
CC: aran, csilvers
Maniphest Tasks: T1184
Differential Revision: https://secure.phabricator.com/D2520
2012-05-21 21:47:38 +02:00
|
|
|
return $this->delegateToController($verify_controller);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-12 19:06:54 +02:00
|
|
|
if ($this->shouldRequireAdmin() && !$user->getIsAdmin()) {
|
2012-01-15 10:07:56 +01:00
|
|
|
return new Aphront403Response();
|
2011-05-12 19:06:54 +02:00
|
|
|
}
|
|
|
|
|
2011-01-26 22:21:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function buildStandardPageView() {
|
|
|
|
$view = new PhabricatorStandardPageView();
|
|
|
|
$view->setRequest($this->getRequest());
|
2012-08-05 23:12:43 +02:00
|
|
|
$view->setController($this);
|
2011-05-12 19:06:54 +02:00
|
|
|
|
|
|
|
if ($this->shouldRequireAdmin()) {
|
|
|
|
$view->setIsAdminInterface(true);
|
|
|
|
}
|
|
|
|
|
2011-01-26 22:21:12 +01:00
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
2011-02-03 07:38:42 +01:00
|
|
|
public function buildStandardPageResponse($view, array $data) {
|
2011-01-26 22:21:12 +01:00
|
|
|
$page = $this->buildStandardPageView();
|
2011-01-23 02:48:55 +01:00
|
|
|
$page->appendChild($view);
|
|
|
|
$response = new AphrontWebpageResponse();
|
|
|
|
$response->setContent($page->render());
|
|
|
|
return $response;
|
2011-01-16 22:51:39 +01:00
|
|
|
}
|
|
|
|
|
2012-08-05 23:12:43 +02:00
|
|
|
public function didProcessRequest($response) {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$response->setRequest($request);
|
|
|
|
if ($response instanceof AphrontDialogResponse) {
|
|
|
|
if (!$request->isAjax()) {
|
|
|
|
$view = new PhabricatorStandardPageView();
|
|
|
|
$view->setRequest($request);
|
|
|
|
$view->setController($this);
|
|
|
|
$view->appendChild(
|
|
|
|
'<div style="padding: 2em 0;">'.
|
|
|
|
$response->buildResponseString().
|
|
|
|
'</div>');
|
|
|
|
$response = new AphrontWebpageResponse();
|
|
|
|
$response->setContent($view->render());
|
|
|
|
return $response;
|
|
|
|
} else {
|
|
|
|
return id(new AphrontAjaxResponse())
|
|
|
|
->setContent(array(
|
|
|
|
'dialog' => $response->buildResponseString(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
} else if ($response instanceof AphrontRedirectResponse) {
|
|
|
|
if ($request->isAjax()) {
|
|
|
|
return id(new AphrontAjaxResponse())
|
|
|
|
->setContent(
|
|
|
|
array(
|
|
|
|
'redirect' => $response->getURI(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
2011-01-16 22:51:39 +01:00
|
|
|
}
|