mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
Further OAuth modularization.
This commit is contained in:
parent
d3efdcff03
commit
2f3d98b24b
7 changed files with 76 additions and 20 deletions
|
@ -181,7 +181,17 @@ return array(
|
||||||
// Can users login with a username/password, or by following the link from
|
// Can users login with a username/password, or by following the link from
|
||||||
// a password reset email? You can disable this and configure one or more
|
// a password reset email? You can disable this and configure one or more
|
||||||
// OAuth providers instead.
|
// OAuth providers instead.
|
||||||
'auth.password-auth-enabled' => true,
|
'auth.password-auth-enabled' => true,
|
||||||
|
|
||||||
|
|
||||||
|
// -- Accounts -------------------------------------------------------------- //
|
||||||
|
|
||||||
|
// Is basic account information (email, real name, profile picture) editable?
|
||||||
|
// If you set up Phabricator to automatically synchronize account information
|
||||||
|
// from some other authoritative system, you can disable this to ensure
|
||||||
|
// information remains consistent across both systems.
|
||||||
|
'account.editable' => true,
|
||||||
|
|
||||||
|
|
||||||
// -- Facebook ------------------------------------------------------------ //
|
// -- Facebook ------------------------------------------------------------ //
|
||||||
|
|
||||||
|
|
|
@ -86,4 +86,16 @@ abstract class AphrontApplicationConfiguration {
|
||||||
final public function willBuildRequest() {
|
final public function willBuildRequest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook for synchronizing account information from OAuth workflows.
|
||||||
|
*
|
||||||
|
* @task hook
|
||||||
|
*/
|
||||||
|
public function willAuthenticateUserWithOAuth(
|
||||||
|
PhabricatorUser $user,
|
||||||
|
PhabricatorUserOAuthInfo $oauth_info,
|
||||||
|
PhabricatorOAuthProvider $provider) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,6 +138,12 @@ class PhabricatorOAuthLoginController extends PhabricatorAuthController {
|
||||||
|
|
||||||
if ($oauth_info->getID()) {
|
if ($oauth_info->getID()) {
|
||||||
$known_user = id(new PhabricatorUser())->load($oauth_info->getUserID());
|
$known_user = id(new PhabricatorUser())->load($oauth_info->getUserID());
|
||||||
|
|
||||||
|
$request->getApplicationConfiguration()->willAuthenticateUserWithOAuth(
|
||||||
|
$known_user,
|
||||||
|
$oauth_info,
|
||||||
|
$provider);
|
||||||
|
|
||||||
$session_key = $known_user->establishSession('web');
|
$session_key = $known_user->establishSession('web');
|
||||||
|
|
||||||
$oauth_info->save();
|
$oauth_info->save();
|
||||||
|
|
|
@ -71,7 +71,7 @@ class PhabricatorOAuthDefaultRegistrationController
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$errors) {
|
if (!$errors) {
|
||||||
$image = $provider->retreiveUserProfileImage();
|
$image = $provider->retrieveUserProfileImage();
|
||||||
if ($image) {
|
if ($image) {
|
||||||
$file = PhabricatorFile::newFromFileData(
|
$file = PhabricatorFile::newFromFileData(
|
||||||
$image,
|
$image,
|
||||||
|
|
|
@ -184,7 +184,7 @@ class PhabricatorFile extends PhabricatorFileDAO {
|
||||||
|
|
||||||
$mime_type = $this->getMimeType();
|
$mime_type = $this->getMimeType();
|
||||||
$mime_parts = explode(';', $mime_type);
|
$mime_parts = explode(';', $mime_type);
|
||||||
$mime_type = reset($mime_parts);
|
$mime_type = trim(reset($mime_parts));
|
||||||
|
|
||||||
return idx($mime_map, $mime_type);
|
return idx($mime_map, $mime_type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
||||||
|
|
||||||
private $page;
|
private $page;
|
||||||
|
private $accountEditable;
|
||||||
|
|
||||||
public function willProcessRequest(array $data) {
|
public function willProcessRequest(array $data) {
|
||||||
$this->page = idx($data, 'page');
|
$this->page = idx($data, 'page');
|
||||||
|
@ -50,9 +51,15 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
||||||
$this->page = key($pages);
|
$this->page = key($pages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$account_editable = PhabricatorEnv::getEnvConfig('account.editable');
|
||||||
|
$this->accountEditable = $account_editable;
|
||||||
|
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
switch ($this->page) {
|
switch ($this->page) {
|
||||||
case 'email':
|
case 'email':
|
||||||
|
if (!$account_editable) {
|
||||||
|
return new Aphront400Response();
|
||||||
|
}
|
||||||
$user->setEmail($request->getStr('email'));
|
$user->setEmail($request->getStr('email'));
|
||||||
$user->save();
|
$user->save();
|
||||||
return id(new AphrontRedirectResponse())
|
return id(new AphrontRedirectResponse())
|
||||||
|
@ -87,6 +94,10 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
||||||
return id(new AphrontRedirectResponse())
|
return id(new AphrontRedirectResponse())
|
||||||
->setURI('/settings/page/arcanist/?regenerated=true');
|
->setURI('/settings/page/arcanist/?regenerated=true');
|
||||||
case 'account':
|
case 'account':
|
||||||
|
if (!$account_editable) {
|
||||||
|
return new Aphront400Response();
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($_FILES['profile'])) {
|
if (!empty($_FILES['profile'])) {
|
||||||
$err = idx($_FILES['profile'], 'error');
|
$err = idx($_FILES['profile'], 'error');
|
||||||
if ($err != UPLOAD_ERR_NO_FILE) {
|
if ($err != UPLOAD_ERR_NO_FILE) {
|
||||||
|
@ -208,6 +219,8 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
||||||
$img_src = PhabricatorFileURI::getViewURIForPHID(
|
$img_src = PhabricatorFileURI::getViewURIForPHID(
|
||||||
$user->getProfileImagePHID());
|
$user->getProfileImagePHID());
|
||||||
|
|
||||||
|
$editable = $this->accountEditable;
|
||||||
|
|
||||||
$form = new AphrontFormView();
|
$form = new AphrontFormView();
|
||||||
$form
|
$form
|
||||||
->setUser($user)
|
->setUser($user)
|
||||||
|
@ -219,7 +232,8 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormTextControl())
|
id(new AphrontFormTextControl())
|
||||||
->setLabel('Real Name')
|
->setLabel('Real Name')
|
||||||
->setValue($user->getRealName()))
|
->setValue($user->getRealName())
|
||||||
|
->setDisabled(!$editable))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormMarkupControl())
|
id(new AphrontFormMarkupControl())
|
||||||
->setValue('<hr />'))
|
->setValue('<hr />'))
|
||||||
|
@ -231,18 +245,22 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
||||||
'img',
|
'img',
|
||||||
array(
|
array(
|
||||||
'src' => $img_src,
|
'src' => $img_src,
|
||||||
))))
|
))));
|
||||||
->appendChild(
|
|
||||||
id(new AphrontFormFileControl())
|
if ($editable) {
|
||||||
->setLabel('Change Image')
|
$form
|
||||||
->setName('profile')
|
->appendChild(
|
||||||
->setCaption('Upload a 50x50px image.'))
|
id(new AphrontFormFileControl())
|
||||||
->appendChild(
|
->setLabel('Change Image')
|
||||||
id(new AphrontFormMarkupControl())
|
->setName('profile')
|
||||||
->setValue('<hr />'))
|
->setCaption('Upload a 50x50px image.'))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormSubmitControl())
|
id(new AphrontFormMarkupControl())
|
||||||
->setValue('Save'));
|
->setValue('<hr />'))
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormSubmitControl())
|
||||||
|
->setValue('Save'));
|
||||||
|
}
|
||||||
|
|
||||||
$panel = new AphrontPanelView();
|
$panel = new AphrontPanelView();
|
||||||
$panel->setHeader('Profile Settings');
|
$panel->setHeader('Profile Settings');
|
||||||
|
@ -256,6 +274,8 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
|
|
||||||
|
$editable = $this->accountEditable;
|
||||||
|
|
||||||
if ($request->getStr('saved')) {
|
if ($request->getStr('saved')) {
|
||||||
$notice = new AphrontErrorView();
|
$notice = new AphrontErrorView();
|
||||||
$notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
|
$notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
|
||||||
|
@ -273,13 +293,18 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
||||||
id(new AphrontFormTextControl())
|
id(new AphrontFormTextControl())
|
||||||
->setLabel('Email')
|
->setLabel('Email')
|
||||||
->setName('email')
|
->setName('email')
|
||||||
|
->setDisabled(!$editable)
|
||||||
->setCaption(
|
->setCaption(
|
||||||
'Note: there is no email validation yet; double-check your '.
|
'Note: there is no email validation yet; double-check your '.
|
||||||
'typing.')
|
'typing.')
|
||||||
->setValue($user->getEmail()))
|
->setValue($user->getEmail()));
|
||||||
->appendChild(
|
|
||||||
id(new AphrontFormSubmitControl())
|
if ($editable) {
|
||||||
->setValue('Save'));
|
$form
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormSubmitControl())
|
||||||
|
->setValue('Save'));
|
||||||
|
}
|
||||||
|
|
||||||
$panel = new AphrontPanelView();
|
$panel = new AphrontPanelView();
|
||||||
$panel->setHeader('Email Settings');
|
$panel->setHeader('Email Settings');
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
phutil_require_module('phabricator', 'aphront/response/400');
|
||||||
phutil_require_module('phabricator', 'aphront/response/404');
|
phutil_require_module('phabricator', 'aphront/response/404');
|
||||||
phutil_require_module('phabricator', 'aphront/response/dialog');
|
phutil_require_module('phabricator', 'aphront/response/dialog');
|
||||||
phutil_require_module('phabricator', 'aphront/response/redirect');
|
phutil_require_module('phabricator', 'aphront/response/redirect');
|
||||||
|
@ -19,8 +20,10 @@ phutil_require_module('phabricator', 'infrastructure/env');
|
||||||
phutil_require_module('phabricator', 'storage/queryfx');
|
phutil_require_module('phabricator', 'storage/queryfx');
|
||||||
phutil_require_module('phabricator', 'view/dialog');
|
phutil_require_module('phabricator', 'view/dialog');
|
||||||
phutil_require_module('phabricator', 'view/form/base');
|
phutil_require_module('phabricator', 'view/form/base');
|
||||||
|
phutil_require_module('phabricator', 'view/form/control/markup');
|
||||||
phutil_require_module('phabricator', 'view/form/control/static');
|
phutil_require_module('phabricator', 'view/form/control/static');
|
||||||
phutil_require_module('phabricator', 'view/form/control/submit');
|
phutil_require_module('phabricator', 'view/form/control/submit');
|
||||||
|
phutil_require_module('phabricator', 'view/form/control/text');
|
||||||
phutil_require_module('phabricator', 'view/form/control/textarea');
|
phutil_require_module('phabricator', 'view/form/control/textarea');
|
||||||
phutil_require_module('phabricator', 'view/form/error');
|
phutil_require_module('phabricator', 'view/form/error');
|
||||||
phutil_require_module('phabricator', 'view/layout/panel');
|
phutil_require_module('phabricator', 'view/layout/panel');
|
||||||
|
|
Loading…
Reference in a new issue