1
0
Fork 0
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:
Evan Priestley 2011-05-22 20:52:48 -07:00
commit 97eba990d8

View file

@ -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'));
$user->save();
return id(new AphrontRedirectResponse()) if (!strlen($user->getEmail())) {
->setURI('/settings/page/email/?saved=true'); $errors[] = 'You must enter an e-mail address';
$e_email = 'Required';
}
if (!$errors) {
$user->save();
return id(new AphrontRedirectResponse())
->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->save(); $user->setRealName($request->getStr('realname'));
return id(new AphrontRedirectResponse())
->setURI('/settings/page/account/'); if (!strlen($user->getRealName())) {
$errors[] = 'Real name must be nonempty';
$e_realname = 'Required';
}
if (!$errors) {
$user->save();
return id(new AphrontRedirectResponse())
->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;
if ($request->getStr('saved')) { $notice = null;
$notice = new AphrontErrorView(); if (!$errors) {
$notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE); if ($request->getStr('saved')) {
$notice->setTitle('Changed Saved'); $notice = new AphrontErrorView();
$notice->appendChild('<p>Your changes have been saved.</p>'); $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
$notice = $notice->render(); $notice->setTitle('Changed Saved');
$notice->appendChild('<p>Your changes have been saved.</p>');
$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