1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 13:22:42 +01:00

No empty name or e-mail we'll be accepted.

Summary: the user can't let the realname and/or  e-mail address be empty

Test Plan: enter on 'settings/account' and change your name to '' and the same
for the e-mail 'settings/email'

Reviewers: epriestley

CC: epriestley
This commit is contained in:
Cristian Adamo 2011-05-23 00:20:35 -03:00
parent 553c6c78fe
commit c44b076b25

View file

@ -54,16 +54,31 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
$account_editable = PhabricatorEnv::getEnvConfig('account.editable');
$this->accountEditable = $account_editable;
$e_realname = true;
$e_email = true;
$errors = array();
if ($request->isFormPost()) {
switch ($this->page) {
case 'email':
if (!$account_editable) {
return new Aphront400Response();
}
$user->setEmail($request->getStr('email'));
$user->save();
return id(new AphrontRedirectResponse())
->setURI('/settings/page/email/?saved=true');
if (!strlen($user->getEmail())) {
$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':
if (!$request->isDialogFormPost()) {
@ -93,6 +108,7 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
$user->save();
return id(new AphrontRedirectResponse())
->setURI('/settings/page/arcanist/?regenerated=true');
break;
case 'account':
if (!$account_editable) {
return new Aphront400Response();
@ -106,21 +122,33 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
}
}
$user->save();
return id(new AphrontRedirectResponse())
->setURI('/settings/page/account/');
$user->setRealName($request->getStr('realname'));
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) {
case 'arcanist':
$content = $this->renderArcanistCertificateForm();
break;
case 'account':
$content = $this->renderAccountForm();
$content = $this->renderAccountForm($errors, $e_realname);
break;
case 'email':
$content = $this->renderEmailForm();
$content = $this->renderEmailForm($errors, $e_email);
break;
default:
if (empty($pages[$this->page])) {
@ -235,7 +263,7 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
return $notice.$cert->render().$regen->render();
}
private function renderAccountForm() {
private function renderAccountForm(array $errors, $e_realname) {
$request = $this->getRequest();
$user = $request->getUser();
@ -244,6 +272,22 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
$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
->setUser($user)
@ -255,6 +299,8 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
->appendChild(
id(new AphrontFormTextControl())
->setLabel('Real Name')
->setName('realname')
->setError($e_realname)
->setValue($user->getRealName())
->setDisabled(!$editable))
->appendChild(
@ -290,23 +336,29 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
$panel->appendChild($form);
return $panel->render();
return $notice.$panel->render();
}
private function renderEmailForm() {
private function renderEmailForm(array $errors, $e_email) {
$request = $this->getRequest();
$user = $request->getUser();
$editable = $this->accountEditable;
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();
$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 = null;
$notice = new AphrontErrorView();
$notice->setTitle('Form Errors');
$notice->setErrors($errors);
$notice = $notice->render();
}
$form = new AphrontFormView();
@ -320,7 +372,8 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
->setCaption(
'Note: there is no email validation yet; double-check your '.
'typing.')
->setValue($user->getEmail()));
->setValue($user->getEmail())
->setError($e_email));
if ($editable) {
$form