mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 19:40:55 +01:00
Merge pull request #7 from cadamo/master
The user can't let empty the realname and/or e-mail form.
This commit is contained in:
commit
97eba990d8
1 changed files with 72 additions and 19 deletions
|
@ -54,16 +54,31 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
||||||
$account_editable = PhabricatorEnv::getEnvConfig('account.editable');
|
$account_editable = PhabricatorEnv::getEnvConfig('account.editable');
|
||||||
$this->accountEditable = $account_editable;
|
$this->accountEditable = $account_editable;
|
||||||
|
|
||||||
|
$e_realname = true;
|
||||||
|
$e_email = true;
|
||||||
|
$errors = array();
|
||||||
|
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
switch ($this->page) {
|
switch ($this->page) {
|
||||||
case 'email':
|
case 'email':
|
||||||
if (!$account_editable) {
|
if (!$account_editable) {
|
||||||
return new Aphront400Response();
|
return new Aphront400Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->setEmail($request->getStr('email'));
|
$user->setEmail($request->getStr('email'));
|
||||||
|
|
||||||
|
if (!strlen($user->getEmail())) {
|
||||||
|
$errors[] = 'You must enter an e-mail address';
|
||||||
|
$e_email = 'Required';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$errors) {
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
return id(new AphrontRedirectResponse())
|
return id(new AphrontRedirectResponse())
|
||||||
->setURI('/settings/page/email/?saved=true');
|
->setURI('/settings/page/email/?saved=true');
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'arcanist':
|
case 'arcanist':
|
||||||
|
|
||||||
if (!$request->isDialogFormPost()) {
|
if (!$request->isDialogFormPost()) {
|
||||||
|
@ -93,6 +108,7 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
||||||
$user->save();
|
$user->save();
|
||||||
return id(new AphrontRedirectResponse())
|
return id(new AphrontRedirectResponse())
|
||||||
->setURI('/settings/page/arcanist/?regenerated=true');
|
->setURI('/settings/page/arcanist/?regenerated=true');
|
||||||
|
break;
|
||||||
case 'account':
|
case 'account':
|
||||||
if (!$account_editable) {
|
if (!$account_editable) {
|
||||||
return new Aphront400Response();
|
return new Aphront400Response();
|
||||||
|
@ -106,21 +122,33 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$user->setRealName($request->getStr('realname'));
|
||||||
|
|
||||||
|
if (!strlen($user->getRealName())) {
|
||||||
|
$errors[] = 'Real name must be nonempty';
|
||||||
|
$e_realname = 'Required';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$errors) {
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
return id(new AphrontRedirectResponse())
|
return id(new AphrontRedirectResponse())
|
||||||
->setURI('/settings/page/account/');
|
->setURI('/settings/page/account/?saved=true');
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch ($this->page) {
|
switch ($this->page) {
|
||||||
case 'arcanist':
|
case 'arcanist':
|
||||||
$content = $this->renderArcanistCertificateForm();
|
$content = $this->renderArcanistCertificateForm();
|
||||||
break;
|
break;
|
||||||
case 'account':
|
case 'account':
|
||||||
$content = $this->renderAccountForm();
|
$content = $this->renderAccountForm($errors, $e_realname);
|
||||||
break;
|
break;
|
||||||
case 'email':
|
case 'email':
|
||||||
$content = $this->renderEmailForm();
|
$content = $this->renderEmailForm($errors, $e_email);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (empty($pages[$this->page])) {
|
if (empty($pages[$this->page])) {
|
||||||
|
@ -235,7 +263,7 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
||||||
return $notice.$cert->render().$regen->render();
|
return $notice.$cert->render().$regen->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderAccountForm() {
|
private function renderAccountForm(array $errors, $e_realname) {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
|
|
||||||
|
@ -244,6 +272,22 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
||||||
|
|
||||||
$editable = $this->accountEditable;
|
$editable = $this->accountEditable;
|
||||||
|
|
||||||
|
$notice = null;
|
||||||
|
if (!$errors) {
|
||||||
|
if ($request->getStr('saved')) {
|
||||||
|
$notice = new AphrontErrorView();
|
||||||
|
$notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
|
||||||
|
$notice->setTitle('Changed 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();
|
||||||
|
}
|
||||||
|
|
||||||
$form = new AphrontFormView();
|
$form = new AphrontFormView();
|
||||||
$form
|
$form
|
||||||
->setUser($user)
|
->setUser($user)
|
||||||
|
@ -255,6 +299,8 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormTextControl())
|
id(new AphrontFormTextControl())
|
||||||
->setLabel('Real Name')
|
->setLabel('Real Name')
|
||||||
|
->setName('realname')
|
||||||
|
->setError($e_realname)
|
||||||
->setValue($user->getRealName())
|
->setValue($user->getRealName())
|
||||||
->setDisabled(!$editable))
|
->setDisabled(!$editable))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
|
@ -290,23 +336,29 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
||||||
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
|
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
|
||||||
$panel->appendChild($form);
|
$panel->appendChild($form);
|
||||||
|
|
||||||
return $panel->render();
|
return $notice.$panel->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderEmailForm() {
|
private function renderEmailForm(array $errors, $e_email) {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
|
|
||||||
$editable = $this->accountEditable;
|
$editable = $this->accountEditable;
|
||||||
|
|
||||||
|
$notice = null;
|
||||||
|
if (!$errors) {
|
||||||
if ($request->getStr('saved')) {
|
if ($request->getStr('saved')) {
|
||||||
$notice = new AphrontErrorView();
|
$notice = new AphrontErrorView();
|
||||||
$notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
|
$notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
|
||||||
$notice->setTitle('Changed Saved');
|
$notice->setTitle('Changed Saved');
|
||||||
$notice->appendChild('<p>Your changes have been saved.</p>');
|
$notice->appendChild('<p>Your changes have been saved.</p>');
|
||||||
$notice = $notice->render();
|
$notice = $notice->render();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$notice = null;
|
$notice = new AphrontErrorView();
|
||||||
|
$notice->setTitle('Form Errors');
|
||||||
|
$notice->setErrors($errors);
|
||||||
|
$notice = $notice->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = new AphrontFormView();
|
$form = new AphrontFormView();
|
||||||
|
@ -320,7 +372,8 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
||||||
->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())
|
||||||
|
->setError($e_email));
|
||||||
|
|
||||||
if ($editable) {
|
if ($editable) {
|
||||||
$form
|
$form
|
||||||
|
|
Loading…
Reference in a new issue