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())) {
|
|
|
|
$errors[] = 'Real name must be nonempty.';
|
|
|
|
$e_realname = '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 {
|
|
|
|
$errors[] = 'The selected timezone is not a valid timezone.';
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
$notice->setTitle('Changes Saved');
|
|
|
|
$notice->appendChild('<p>Your changes have been saved.</p>');
|
|
|
|
$notice = $notice->render();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$notice = new AphrontErrorView();
|
|
|
|
$notice->setTitle('Form Errors');
|
|
|
|
$notice->setErrors($errors);
|
|
|
|
$notice = $notice->render();
|
|
|
|
}
|
|
|
|
|
2011-07-25 00:03:59 +02:00
|
|
|
$timezone_ids = DateTimeZone::listIdentifiers();
|
|
|
|
$timezone_id_map = array_combine($timezone_ids, $timezone_ids);
|
|
|
|
|
2011-07-18 17:02:00 +02:00
|
|
|
$form = new AphrontFormView();
|
|
|
|
$form
|
|
|
|
->setUser($user)
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormStaticControl())
|
|
|
|
->setLabel('Username')
|
|
|
|
->setValue($user->getUsername()))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel('Real Name')
|
|
|
|
->setName('realname')
|
|
|
|
->setError($e_realname)
|
|
|
|
->setValue($user->getRealName())
|
|
|
|
->setDisabled(!$editable))
|
|
|
|
->appendChild(
|
2011-07-25 00:03:59 +02:00
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setLabel('Timezone')
|
|
|
|
->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())
|
|
|
|
->setValue('Save'));
|
2011-07-18 17:02:00 +02:00
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
2011-07-25 00:03:59 +02:00
|
|
|
$panel->setHeader('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
|
|
|
}
|
|
|
|
}
|