2011-07-18 17:02:00 +02:00
|
|
|
<?php
|
|
|
|
|
2012-08-13 21:37:26 +02:00
|
|
|
final class PhabricatorSettingsPanelAccount
|
|
|
|
extends PhabricatorSettingsPanel {
|
2011-07-18 17:02:00 +02:00
|
|
|
|
2012-08-13 21:37:26 +02:00
|
|
|
public function getPanelKey() {
|
|
|
|
return 'account';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPanelName() {
|
|
|
|
return pht('Account');
|
|
|
|
}
|
2011-07-18 17:02:00 +02:00
|
|
|
|
2012-08-13 21:37:26 +02:00
|
|
|
public function getPanelGroup() {
|
|
|
|
return pht('Account Information');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest(AphrontRequest $request) {
|
2011-07-18 17:02:00 +02:00
|
|
|
$user = $request->getUser();
|
2012-08-13 21:37:26 +02:00
|
|
|
$editable = PhabricatorEnv::getEnvConfig('account.editable');
|
2011-07-18 17:02:00 +02:00
|
|
|
|
2011-07-25 00:03:59 +02:00
|
|
|
$e_realname = $editable ? true : null;
|
2011-07-18 17:02:00 +02:00
|
|
|
$errors = array();
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
|
2011-07-25 00:03:59 +02:00
|
|
|
if ($editable) {
|
|
|
|
$user->setRealName($request->getStr('realname'));
|
|
|
|
if (!strlen($user->getRealName())) {
|
2013-03-03 15:52:42 +01:00
|
|
|
$errors[] = pht('Real name must be nonempty.');
|
|
|
|
$e_realname = pht('Required');
|
2011-07-18 17:02:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$new_timezone = $request->getStr('timezone');
|
|
|
|
if (in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) {
|
|
|
|
$user->setTimezoneIdentifier($new_timezone);
|
|
|
|
} else {
|
2013-03-03 15:52:42 +01:00
|
|
|
$errors[] = pht('The selected timezone is not a valid timezone.');
|
2011-07-18 17:02:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$errors) {
|
|
|
|
$user->save();
|
|
|
|
return id(new AphrontRedirectResponse())
|
2012-08-13 21:37:26 +02:00
|
|
|
->setURI($this->getPanelURI('?saved=true'));
|
2011-07-18 17:02:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$notice = null;
|
|
|
|
if (!$errors) {
|
|
|
|
if ($request->getStr('saved')) {
|
|
|
|
$notice = new AphrontErrorView();
|
|
|
|
$notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
|
2013-03-03 15:52:42 +01:00
|
|
|
$notice->setTitle(pht('Changes Saved'));
|
2013-02-07 01:53:49 +01:00
|
|
|
$notice->appendChild(
|
2013-03-03 15:52:42 +01:00
|
|
|
phutil_tag('p', array(), pht('Your changes have been saved.')));
|
2011-07-18 17:02:00 +02:00
|
|
|
$notice = $notice->render();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$notice = new AphrontErrorView();
|
2013-03-03 15:52:42 +01:00
|
|
|
$notice->setTitle(pht('Form Errors'));
|
2011-07-18 17:02:00 +02:00
|
|
|
$notice->setErrors($errors);
|
|
|
|
$notice = $notice->render();
|
|
|
|
}
|
|
|
|
|
2011-07-25 00:03:59 +02:00
|
|
|
$timezone_ids = DateTimeZone::listIdentifiers();
|
2013-01-26 02:06:55 +01:00
|
|
|
$timezone_id_map = array_fuse($timezone_ids);
|
2011-07-25 00:03:59 +02:00
|
|
|
|
2011-07-18 17:02:00 +02:00
|
|
|
$form = new AphrontFormView();
|
|
|
|
$form
|
|
|
|
->setUser($user)
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormStaticControl())
|
2013-03-03 15:52:42 +01:00
|
|
|
->setLabel(pht('Username'))
|
2011-07-18 17:02:00 +02:00
|
|
|
->setValue($user->getUsername()))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
2013-03-03 15:52:42 +01:00
|
|
|
->setLabel(pht('Real Name'))
|
2011-07-18 17:02:00 +02:00
|
|
|
->setName('realname')
|
|
|
|
->setError($e_realname)
|
|
|
|
->setValue($user->getRealName())
|
|
|
|
->setDisabled(!$editable))
|
|
|
|
->appendChild(
|
2011-07-25 00:03:59 +02:00
|
|
|
id(new AphrontFormSelectControl())
|
2013-03-03 15:52:42 +01:00
|
|
|
->setLabel(pht('Timezone'))
|
2011-07-25 00:03:59 +02:00
|
|
|
->setName('timezone')
|
|
|
|
->setOptions($timezone_id_map)
|
|
|
|
->setValue($user->getTimezoneIdentifier()))
|
2011-07-18 17:02:00 +02:00
|
|
|
->appendChild(
|
2011-07-25 00:03:59 +02:00
|
|
|
id(new AphrontFormSubmitControl())
|
2013-03-03 15:52:42 +01:00
|
|
|
->setValue(pht('Save')));
|
2011-07-18 17:02:00 +02:00
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
2013-03-03 15:52:42 +01:00
|
|
|
$panel->setHeader(pht('Account Settings'));
|
2011-07-18 17:02:00 +02:00
|
|
|
$panel->appendChild($form);
|
2013-01-16 16:49:05 +01:00
|
|
|
$panel->setNoBackground();
|
2011-07-18 17:02:00 +02:00
|
|
|
|
2012-08-13 21:37:26 +02:00
|
|
|
return array(
|
|
|
|
$notice,
|
|
|
|
$panel,
|
|
|
|
);
|
2011-07-18 17:02:00 +02:00
|
|
|
}
|
|
|
|
}
|