diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index a94dc510f5..4a75250e10 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -78,7 +78,13 @@ phutil_register_library_map(array( 'PhabricatorPHIDType' => 'applications/phid/storage/type', 'PhabricatorPHIDTypeEditController' => 'applications/phid/controller/typeedit', 'PhabricatorPHIDTypeListController' => 'applications/phid/controller/typelist', + 'PhabricatorPeopleController' => 'applications/people/controller/base', + 'PhabricatorPeopleEditController' => 'applications/people/controller/edit', + 'PhabricatorPeopleListController' => 'applications/people/controller/list', + 'PhabricatorPeopleProfileController' => 'applications/people/controller/profile', 'PhabricatorStandardPageView' => 'view/page/standard', + 'PhabricatorUser' => 'applications/people/storage/user', + 'PhabricatorUserDAO' => 'applications/people/storage/base', ), 'function' => array( @@ -150,7 +156,13 @@ phutil_register_library_map(array( 'PhabricatorPHIDType' => 'PhabricatorPHIDDAO', 'PhabricatorPHIDTypeEditController' => 'PhabricatorPHIDController', 'PhabricatorPHIDTypeListController' => 'PhabricatorPHIDController', + 'PhabricatorPeopleController' => 'PhabricatorController', + 'PhabricatorPeopleEditController' => 'PhabricatorPeopleController', + 'PhabricatorPeopleListController' => 'PhabricatorPeopleController', + 'PhabricatorPeopleProfileController' => 'PhabricatorPeopleController', 'PhabricatorStandardPageView' => 'AphrontPageView', + 'PhabricatorUser' => 'PhabricatorUserDAO', + 'PhabricatorUserDAO' => 'PhabricatorLiskDAO', ), 'requires_interface' => array( diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index 0939448591..da2ab26f63 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -64,6 +64,11 @@ class AphrontDefaultApplicationConfiguration 'type/edit/(?:(?\d+)/)?$' => 'PhabricatorPHIDTypeEditController', 'new/$' => 'PhabricatorPHIDAllocateController', ), + '/people/' => array( + '$' => 'PhabricatorPeopleListController', + 'edit/(?:(?\w+)/)?$' => 'PhabricatorPeopleEditController', + ), + '/p/(?\w+)/$' => 'PhabricatorPeopleProfileController', '.*' => 'AphrontDefaultApplicationController', ); } diff --git a/src/aphront/response/file/__init__.php b/src/aphront/response/file/__init__.php new file mode 100644 index 0000000000..fa9dd6316a --- /dev/null +++ b/src/aphront/response/file/__init__.php @@ -0,0 +1,12 @@ +setApplicationName('People'); + $page->setBaseURI('/people/'); + $page->setTitle(idx($data, 'title')); + $page->setGlyph("\xE2\x99\xA5"); + $page->appendChild($view); + + $response = new AphrontWebpageResponse(); + return $response->setContent($page->render()); + } + +} diff --git a/src/applications/people/controller/base/__init__.php b/src/applications/people/controller/base/__init__.php new file mode 100644 index 0000000000..9544894bc6 --- /dev/null +++ b/src/applications/people/controller/base/__init__.php @@ -0,0 +1,16 @@ +username = idx($data, 'username'); + } + + public function processRequest() { + + 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(); + 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/edit/__init__.php b/src/applications/people/controller/edit/__init__.php new file mode 100644 index 0000000000..5698e351ac --- /dev/null +++ b/src/applications/people/controller/edit/__init__.php @@ -0,0 +1,21 @@ +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', + )); + + $panel = new AphrontPanelView(); + $panel->appendChild($table); + $panel->setHeader('People'); + $panel->setCreateButton('Create New User', '/people/edit/'); + + return $this->buildStandardPageResponse($panel, array( + 'title' => 'People', + 'tab' => 'people', + )); + } +} diff --git a/src/applications/people/controller/list/__init__.php b/src/applications/people/controller/list/__init__.php new file mode 100644 index 0000000000..adb44568b3 --- /dev/null +++ b/src/applications/people/controller/list/__init__.php @@ -0,0 +1,18 @@ +username = $data['username']; + } + + public function processRequest() { + + $user = id(new PhabricatorUser())->loadOneWhere( + 'userName = %s', + $this->username); + if (!$user) { + return new Aphront404Response(); + } + + + return $this->buildStandardPageResponse( + array('this is a profile thingie'), + array( + 'title' => $user->getUsername(), + )); + } + +} diff --git a/src/applications/people/controller/profile/__init__.php b/src/applications/people/controller/profile/__init__.php new file mode 100644 index 0000000000..6993f52ebb --- /dev/null +++ b/src/applications/people/controller/profile/__init__.php @@ -0,0 +1,16 @@ + true, + ) + parent::getConfiguration(); + } + + public function generatePHID() { + return PhabricatorPHID::generateNewPHID(self::PHID_TYPE); + } + +} diff --git a/src/applications/people/storage/user/__init__.php b/src/applications/people/storage/user/__init__.php new file mode 100644 index 0000000000..a6ff0d55ea --- /dev/null +++ b/src/applications/people/storage/user/__init__.php @@ -0,0 +1,13 @@ +