From c44b076b259d5a2a9c6a189d97d42e378c4abd0e Mon Sep 17 00:00:00 2001 From: Cristian Adamo Date: Mon, 23 May 2011 00:20:35 -0300 Subject: [PATCH] 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 --- .../PhabricatorUserSettingsController.php | 91 +++++++++++++++---- 1 file changed, 72 insertions(+), 19 deletions(-) diff --git a/src/applications/people/controller/settings/PhabricatorUserSettingsController.php b/src/applications/people/controller/settings/PhabricatorUserSettingsController.php index c131b69cc1..45290e4c95 100644 --- a/src/applications/people/controller/settings/PhabricatorUserSettingsController.php +++ b/src/applications/people/controller/settings/PhabricatorUserSettingsController.php @@ -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('

Your changes have been saved.

'); + $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('

Your changes have been saved.

'); - $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('

Your changes have been saved.

'); + $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