@@ -54,16 +54,31 @@ public function processRequest() {
5454 $ account_editable = PhabricatorEnv::getEnvConfig ('account.editable ' );
5555 $ this ->accountEditable = $ account_editable ;
5656
57+ $ e_realname = true ;
58+ $ e_email = true ;
59+ $ errors = array ();
60+
5761 if ($ request ->isFormPost ()) {
5862 switch ($ this ->page ) {
5963 case 'email ' :
6064 if (!$ account_editable ) {
6165 return new Aphront400Response ();
6266 }
67+
6368 $ user ->setEmail ($ request ->getStr ('email ' ));
64- $ user ->save ();
65- return id (new AphrontRedirectResponse ())
66- ->setURI ('/settings/page/email/?saved=true ' );
69+
70+ if (!strlen ($ user ->getEmail ())) {
71+ $ errors [] = 'You must enter an e-mail address ' ;
72+ $ e_email = 'Required ' ;
73+ }
74+
75+ if (!$ errors ) {
76+ $ user ->save ();
77+
78+ return id (new AphrontRedirectResponse ())
79+ ->setURI ('/settings/page/email/?saved=true ' );
80+ }
81+ break ;
6782 case 'arcanist ' :
6883
6984 if (!$ request ->isDialogFormPost ()) {
@@ -93,6 +108,7 @@ public function processRequest() {
93108 $ user ->save ();
94109 return id (new AphrontRedirectResponse ())
95110 ->setURI ('/settings/page/arcanist/?regenerated=true ' );
111+ break ;
96112 case 'account ' :
97113 if (!$ account_editable ) {
98114 return new Aphront400Response ();
@@ -106,21 +122,33 @@ public function processRequest() {
106122 }
107123 }
108124
109- $ user ->save ();
110- return id (new AphrontRedirectResponse ())
111- ->setURI ('/settings/page/account/ ' );
125+ $ user ->setRealName ($ request ->getStr ('realname ' ));
126+
127+ if (!strlen ($ user ->getRealName ())) {
128+ $ errors [] = 'Real name must be nonempty ' ;
129+ $ e_realname = 'Required ' ;
130+ }
131+
132+ if (!$ errors ) {
133+ $ user ->save ();
134+
135+ return id (new AphrontRedirectResponse ())
136+ ->setURI ('/settings/page/account/?saved=true ' );
137+ }
138+ break ;
112139 }
113140 }
114141
142+
115143 switch ($ this ->page ) {
116144 case 'arcanist ' :
117145 $ content = $ this ->renderArcanistCertificateForm ();
118146 break ;
119147 case 'account ' :
120- $ content = $ this ->renderAccountForm ();
148+ $ content = $ this ->renderAccountForm ($ errors , $ e_realname );
121149 break ;
122150 case 'email ' :
123- $ content = $ this ->renderEmailForm ();
151+ $ content = $ this ->renderEmailForm ($ errors , $ e_email );
124152 break ;
125153 default :
126154 if (empty ($ pages [$ this ->page ])) {
@@ -235,7 +263,7 @@ private function renderArcanistCertificateForm() {
235263 return $ notice .$ cert ->render ().$ regen ->render ();
236264 }
237265
238- private function renderAccountForm () {
266+ private function renderAccountForm (array $ errors , $ e_realname ) {
239267 $ request = $ this ->getRequest ();
240268 $ user = $ request ->getUser ();
241269
@@ -244,6 +272,22 @@ private function renderAccountForm() {
244272
245273 $ editable = $ this ->accountEditable ;
246274
275+ $ notice = null ;
276+ if (!$ errors ) {
277+ if ($ request ->getStr ('saved ' )) {
278+ $ notice = new AphrontErrorView ();
279+ $ notice ->setSeverity (AphrontErrorView::SEVERITY_NOTICE );
280+ $ notice ->setTitle ('Changed Saved ' );
281+ $ notice ->appendChild ('<p>Your changes have been saved.</p> ' );
282+ $ notice = $ notice ->render ();
283+ }
284+ } else {
285+ $ notice = new AphrontErrorView ();
286+ $ notice ->setTitle ('Form Errors ' );
287+ $ notice ->setErrors ($ errors );
288+ $ notice = $ notice ->render ();
289+ }
290+
247291 $ form = new AphrontFormView ();
248292 $ form
249293 ->setUser ($ user )
@@ -255,6 +299,8 @@ private function renderAccountForm() {
255299 ->appendChild (
256300 id (new AphrontFormTextControl ())
257301 ->setLabel ('Real Name ' )
302+ ->setName ('realname ' )
303+ ->setError ($ e_realname )
258304 ->setValue ($ user ->getRealName ())
259305 ->setDisabled (!$ editable ))
260306 ->appendChild (
@@ -290,23 +336,29 @@ private function renderAccountForm() {
290336 $ panel ->setWidth (AphrontPanelView::WIDTH_FORM );
291337 $ panel ->appendChild ($ form );
292338
293- return $ panel ->render ();
339+ return $ notice . $ panel ->render ();
294340 }
295341
296- private function renderEmailForm () {
342+ private function renderEmailForm (array $ errors , $ e_email ) {
297343 $ request = $ this ->getRequest ();
298344 $ user = $ request ->getUser ();
299345
300346 $ editable = $ this ->accountEditable ;
301347
302- if ($ request ->getStr ('saved ' )) {
348+ $ notice = null ;
349+ if (!$ errors ) {
350+ if ($ request ->getStr ('saved ' )) {
351+ $ notice = new AphrontErrorView ();
352+ $ notice ->setSeverity (AphrontErrorView::SEVERITY_NOTICE );
353+ $ notice ->setTitle ('Changed Saved ' );
354+ $ notice ->appendChild ('<p>Your changes have been saved.</p> ' );
355+ $ notice = $ notice ->render ();
356+ }
357+ } else {
303358 $ notice = new AphrontErrorView ();
304- $ notice ->setSeverity (AphrontErrorView::SEVERITY_NOTICE );
305- $ notice ->setTitle ('Changed Saved ' );
306- $ notice ->appendChild ('<p>Your changes have been saved.</p> ' );
359+ $ notice ->setTitle ('Form Errors ' );
360+ $ notice ->setErrors ($ errors );
307361 $ notice = $ notice ->render ();
308- } else {
309- $ notice = null ;
310362 }
311363
312364 $ form = new AphrontFormView ();
@@ -320,7 +372,8 @@ private function renderEmailForm() {
320372 ->setCaption (
321373 'Note: there is no email validation yet; double-check your ' .
322374 'typing. ' )
323- ->setValue ($ user ->getEmail ()));
375+ ->setValue ($ user ->getEmail ())
376+ ->setError ($ e_email ));
324377
325378 if ($ editable ) {
326379 $ form
0 commit comments