diff --git a/src/applications/people/controller/edit/PhabricatorPeopleEditController.php b/src/applications/people/controller/edit/PhabricatorPeopleEditController.php index fe52b50df..2f339530a 100644 --- a/src/applications/people/controller/edit/PhabricatorPeopleEditController.php +++ b/src/applications/people/controller/edit/PhabricatorPeopleEditController.php @@ -1,143 +1,145 @@ <?php /* * Copyright 2011 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ class PhabricatorPeopleEditController extends PhabricatorPeopleController { private $username; public function willProcessRequest(array $data) { $this->username = idx($data, 'username'); } public function processRequest() { + return new Aphront404Response(); + if ($this->username) { $user = id(new PhabricatorUser())->loadOneWhere( 'userName = %s', $this->username); if (!$user) { return new Aphront404Response(); } } else { $user = new PhabricatorUser(); } $e_username = true; $e_realname = true; $e_email = true; $errors = array(); $request = $this->getRequest(); if ($request->isFormPost()) { if (!$user->getID()) { $user->setUsername($request->getStr('username')); } $user->setRealName($request->getStr('realname')); $user->setEmail($request->getStr('email')); if (!strlen($user->getUsername())) { $errors[] = "Username is required."; $e_username = 'Required'; } else if (!preg_match('/^[a-z0-9]+$/', $user->getUsername())) { $errors[] = "Username must consist of only numbers and letters."; $e_username = 'Invalid'; } if (!strlen($user->getRealName())) { $errors[] = 'Real name is required.'; $e_realname = 'Required'; } if (!strlen($user->getEmail())) { $errors[] = 'Email is required.'; $e_email = 'Required'; } if (!$errors) { $user->save(); $response = id(new AphrontRedirectResponse()) ->setURI('/p/'.$user->getUsername().'/'); return $response; } } $error_view = null; if ($errors) { $error_view = id(new AphrontErrorView()) ->setTitle('Form Errors') ->setErrors($errors); } $form = new AphrontFormView(); $form->setUser($request->getUser()); if ($user->getUsername()) { $form->setAction('/people/edit/'.$user->getUsername().'/'); } else { $form->setAction('/people/edit/'); } if ($user->getID()) { $is_immutable = true; } else { $is_immutable = false; } $form ->appendChild( id(new AphrontFormTextControl()) ->setLabel('Username') ->setName('username') ->setValue($user->getUsername()) ->setError($e_username) ->setDisabled($is_immutable) ->setCaption('Usernames are permanent and can not be changed later!')) ->appendChild( id(new AphrontFormTextControl()) ->setLabel('Real Name') ->setName('realname') ->setValue($user->getRealName()) ->setError($e_realname)) ->appendChild( id(new AphrontFormTextControl()) ->setLabel('Email') ->setName('email') ->setValue($user->getEmail()) ->setError($e_email)) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue('Save') ->addCancelButton('/people/')); $panel = new AphrontPanelView(); if ($user->getID()) { $panel->setHeader('Edit User'); } else { $panel->setHeader('Create New User'); } $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return $this->buildStandardPageResponse( array($error_view, $panel), array( 'title' => 'Edit User', )); } } diff --git a/src/applications/people/controller/list/PhabricatorPeopleListController.php b/src/applications/people/controller/list/PhabricatorPeopleListController.php index b0a5ae757..ad31e0a8b 100644 --- a/src/applications/people/controller/list/PhabricatorPeopleListController.php +++ b/src/applications/people/controller/list/PhabricatorPeopleListController.php @@ -1,76 +1,78 @@ <?php /* * Copyright 2011 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ class PhabricatorPeopleListController extends PhabricatorPeopleController { public function processRequest() { $users = id(new PhabricatorUser())->loadAllWhere( '1 = 1 ORDER BY id DESC LIMIT 100'); $rows = array(); foreach ($users as $user) { $rows[] = array( $user->getPHID(), $user->getUserName(), $user->getRealName(), phutil_render_tag( 'a', array( 'class' => 'button grey small', 'href' => '/p/'.$user->getUsername().'/', ), 'View Profile'), +/* phutil_render_tag( 'a', array( 'class' => 'button grey small', 'href' => '/people/edit/'.$user->getUsername().'/', ), 'Edit'), +*/ ); } $table = new AphrontTableView($rows); $table->setHeaders( array( 'PHID', 'Username', 'Real Name', '', - '', +// '', )); $table->setColumnClasses( array( null, null, 'wide', 'action', - 'action', +// 'action', )); $panel = new AphrontPanelView(); $panel->appendChild($table); $panel->setHeader('People'); - $panel->setCreateButton('Create New User', '/people/edit/'); +// $panel->setCreateButton('Create New User', '/people/edit/'); return $this->buildStandardPageResponse($panel, array( 'title' => 'People', 'tab' => 'people', )); } } diff --git a/src/applications/people/controller/settings/PhabricatorUserSettingsController.php b/src/applications/people/controller/settings/PhabricatorUserSettingsController.php index 941bf55e3..b7b581f3d 100644 --- a/src/applications/people/controller/settings/PhabricatorUserSettingsController.php +++ b/src/applications/people/controller/settings/PhabricatorUserSettingsController.php @@ -1,238 +1,281 @@ <?php /* * Copyright 2011 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ class PhabricatorUserSettingsController extends PhabricatorPeopleController { private $page; public function willProcessRequest(array $data) { $this->page = idx($data, 'page'); } public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $pages = array( - 'account' => 'Account', + 'account' => 'Account', + 'email' => 'Email', // 'password' => 'Password', // 'facebook' => 'Facebook Account', 'arcanist' => 'Arcanist Certificate', ); if (empty($pages[$this->page])) { $this->page = key($pages); } if ($request->isFormPost()) { switch ($this->page) { + case 'email': + $user->setEmail($request->getStr('email')); + $user->save(); + return id(new AphrontRedirectResponse()) + ->setURI('/settings/page/email/?saved=true'); case 'arcanist': if (!$request->isDialogFormPost()) { $dialog = new AphrontDialogView(); $dialog->setUser($user); $dialog->setTitle('Really regenerate session?'); $dialog->setSubmitURI('/settings/page/arcanist/'); $dialog->addSubmitButton('Regenerate'); $dialog->addCancelbutton('/settings/page/arcanist/'); $dialog->appendChild( '<p>Really destroy the old certificate? Any established '. 'sessions will be terminated.'); return id(new AphrontDialogResponse()) ->setDialog($dialog); } $conn = $user->establishConnection('w'); queryfx( $conn, 'DELETE FROM %T WHERE userPHID = %s AND type LIKE %>', PhabricatorUser::SESSION_TABLE, $user->getPHID(), 'conduit'); // This implicitly regenerates the certificate. $user->setConduitCertificate(null); $user->save(); return id(new AphrontRedirectResponse()) ->setURI('/settings/page/arcanist/?regenerated=true'); case 'account': if (!empty($_FILES['profile'])) { $err = idx($_FILES['profile'], 'error'); if ($err != UPLOAD_ERR_NO_FILE) { $file = PhabricatorFile::newFromPHPUpload($_FILES['profile']); $user->setProfileImagePHID($file->getPHID()); } } $user->save(); return id(new AphrontRedirectResponse()) ->setURI('/settings/page/account/'); } } switch ($this->page) { case 'arcanist': $content = $this->renderArcanistCertificateForm(); break; case 'account': $content = $this->renderAccountForm(); break; + case 'email': + $content = $this->renderEmailForm(); + break; default: $content = 'derp derp'; break; } $sidenav = new AphrontSideNavView(); foreach ($pages as $page => $name) { $sidenav->addNavItem( phutil_render_tag( 'a', array( 'href' => '/settings/page/'.$page.'/', 'class' => ($page == $this->page) ? 'aphront-side-nav-selected' : null, ), phutil_escape_html($name))); } $sidenav->appendChild($content); return $this->buildStandardPageResponse( $sidenav, array( 'title' => 'Account Settings', )); } private function renderArcanistCertificateForm() { $request = $this->getRequest(); $user = $request->getUser(); if ($request->getStr('regenerated')) { $notice = new AphrontErrorView(); $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE); $notice->setTitle('Certificate Regenerated'); $notice->appendChild( '<p>Your old certificate has been destroyed and you have been issued '. 'a new certificate. Sessions established under the old certificate '. 'are no longer valid.</p>'); $notice = $notice->render(); } else { $notice = null; } $host = PhabricatorEnv::getEnvConfig('phabricator.conduit-uri'); $cert_form = new AphrontFormView(); $cert_form ->setUser($user) ->appendChild( '<p class="aphront-form-instructions">Copy and paste this certificate '. 'into your <tt>~/.arcrc</tt> in the "hosts" section to enable '. 'Arcanist to authenticate against this host.</p>') ->appendChild( id(new AphrontFormTextAreaControl()) ->setLabel('Certificate') ->setHeight(AphrontFormTextAreaControl::HEIGHT_SHORT) ->setValue($user->getConduitCertificate())); $cert = new AphrontPanelView(); $cert->setHeader('Arcanist Certificate'); $cert->appendChild($cert_form); $cert->setWidth(AphrontPanelView::WIDTH_FORM); $regen_form = new AphrontFormView(); $regen_form ->setUser($user) ->setWorkflow(true) ->setAction('/settings/page/arcanist/') ->appendChild( '<p class="aphront-form-instructions">You can regenerate this '. 'certificate, which will invalidate the old certificate and create '. 'a new one.</p>') ->appendChild( id(new AphrontFormSubmitControl()) ->setValue('Regenerate Certificate')); $regen = new AphrontPanelView(); $regen->setHeader('Regenerate Certificate'); $regen->appendChild($regen_form); $regen->setWidth(AphrontPanelView::WIDTH_FORM); return $notice.$cert->render().$regen->render(); } private function renderAccountForm() { $request = $this->getRequest(); $user = $request->getUser(); $img_src = PhabricatorFileURI::getViewURIForPHID( $user->getProfileImagePHID()); $form = new AphrontFormView(); $form ->setUser($user) ->setEncType('multipart/form-data') ->appendChild( id(new AphrontFormStaticControl()) ->setLabel('Username') ->setValue($user->getUsername())) - ->appendChild( - id(new AphrontFormStaticControl()) - ->setLabel('Email') - ->setValue($user->getEmail())) ->appendChild( id(new AphrontFormTextControl()) ->setLabel('Real Name') ->setValue($user->getRealName())) ->appendChild( id(new AphrontFormMarkupControl()) ->setValue('<hr />')) ->appendChild( id(new AphrontFormMarkupControl()) ->setLabel('Profile Image') ->setValue( phutil_render_tag( 'img', array( 'src' => $img_src, )))) ->appendChild( id(new AphrontFormFileControl()) ->setLabel('Change Image') ->setName('profile') ->setCaption('Upload a 50x50px image.')) ->appendChild( id(new AphrontFormMarkupControl()) ->setValue('<hr />')) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue('Save')); $panel = new AphrontPanelView(); $panel->setHeader('Profile Settings'); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $panel->appendChild($form); return $panel->render(); } + private function renderEmailForm() { + $request = $this->getRequest(); + $user = $request->getUser(); + + + 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; + } + + $form = new AphrontFormView(); + $form + ->setUser($user) + ->appendChild( + id(new AphrontFormTextControl()) + ->setLabel('Email') + ->setName('email') + ->setCaption( + 'Note: there is no email validation yet; double-check your '. + 'typing.') + ->setValue($user->getEmail())) + ->appendChild( + id(new AphrontFormSubmitControl()) + ->setValue('Save')); + + $panel = new AphrontPanelView(); + $panel->setHeader('Email Settings'); + $panel->setWidth(AphrontPanelView::WIDTH_FORM); + $panel->appendChild($form); + + return $notice.$panel->render(); + } + }