mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-03 03:11:01 +01:00
Basic user/account tool.
This commit is contained in:
parent
0eac30d80d
commit
89dae65c35
15 changed files with 484 additions and 0 deletions
|
@ -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(
|
||||
|
|
|
@ -64,6 +64,11 @@ class AphrontDefaultApplicationConfiguration
|
|||
'type/edit/(?:(?<id>\d+)/)?$' => 'PhabricatorPHIDTypeEditController',
|
||||
'new/$' => 'PhabricatorPHIDAllocateController',
|
||||
),
|
||||
'/people/' => array(
|
||||
'$' => 'PhabricatorPeopleListController',
|
||||
'edit/(?:(?<username>\w+)/)?$' => 'PhabricatorPeopleEditController',
|
||||
),
|
||||
'/p/(?<username>\w+)/$' => 'PhabricatorPeopleProfileController',
|
||||
'.*' => 'AphrontDefaultApplicationController',
|
||||
);
|
||||
}
|
||||
|
|
12
src/aphront/response/file/__init__.php
Normal file
12
src/aphront/response/file/__init__.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/response/base');
|
||||
|
||||
|
||||
phutil_require_source('AphrontFileResponse.php');
|
|
@ -0,0 +1,34 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
abstract class PhabricatorPeopleController extends PhabricatorController {
|
||||
|
||||
public function buildStandardPageResponse($view, array $data) {
|
||||
$page = new PhabricatorStandardPageView();
|
||||
|
||||
$page->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());
|
||||
}
|
||||
|
||||
}
|
16
src/applications/people/controller/base/__init__.php
Normal file
16
src/applications/people/controller/base/__init__.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/response/webpage');
|
||||
phutil_require_module('phabricator', 'applications/base/controller/base');
|
||||
phutil_require_module('phabricator', 'view/page/standard');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorPeopleController.php');
|
|
@ -0,0 +1,142 @@
|
|||
<?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() {
|
||||
|
||||
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',
|
||||
));
|
||||
}
|
||||
|
||||
}
|
21
src/applications/people/controller/edit/__init__.php
Normal file
21
src/applications/people/controller/edit/__init__.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/response/404');
|
||||
phutil_require_module('phabricator', 'aphront/response/redirect');
|
||||
phutil_require_module('phabricator', 'applications/people/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/people/storage/user');
|
||||
phutil_require_module('phabricator', 'view/form/base');
|
||||
phutil_require_module('phabricator', 'view/form/control/submit');
|
||||
phutil_require_module('phabricator', 'view/form/error');
|
||||
phutil_require_module('phabricator', 'view/layout/panel');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorPeopleEditController.php');
|
|
@ -0,0 +1,76 @@
|
|||
<?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',
|
||||
));
|
||||
|
||||
$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',
|
||||
));
|
||||
}
|
||||
}
|
18
src/applications/people/controller/list/__init__.php
Normal file
18
src/applications/people/controller/list/__init__.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/people/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/people/storage/user');
|
||||
phutil_require_module('phabricator', 'view/control/table');
|
||||
phutil_require_module('phabricator', 'view/layout/panel');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorPeopleListController.php');
|
|
@ -0,0 +1,44 @@
|
|||
<?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 PhabricatorPeopleProfileController extends PhabricatorPeopleController {
|
||||
|
||||
private $username;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->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(),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
16
src/applications/people/controller/profile/__init__.php
Normal file
16
src/applications/people/controller/profile/__init__.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/response/404');
|
||||
phutil_require_module('phabricator', 'applications/people/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/people/storage/user');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorPeopleProfileController.php');
|
25
src/applications/people/storage/base/PhabricatorUserDAO.php
Normal file
25
src/applications/people/storage/base/PhabricatorUserDAO.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
abstract class PhabricatorUserDAO extends PhabricatorLiskDAO {
|
||||
|
||||
public function getApplicationName() {
|
||||
return 'user';
|
||||
}
|
||||
|
||||
}
|
12
src/applications/people/storage/base/__init__.php
Normal file
12
src/applications/people/storage/base/__init__.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/base/storage/lisk');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorUserDAO.php');
|
38
src/applications/people/storage/user/PhabricatorUser.php
Normal file
38
src/applications/people/storage/user/PhabricatorUser.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?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 PhabricatorUser extends PhabricatorUserDAO {
|
||||
|
||||
const PHID_TYPE = 'USER';
|
||||
|
||||
protected $phid;
|
||||
protected $userName;
|
||||
protected $realName;
|
||||
protected $email;
|
||||
|
||||
public function getConfiguration() {
|
||||
return array(
|
||||
self::CONFIG_AUX_PHID => true,
|
||||
) + parent::getConfiguration();
|
||||
}
|
||||
|
||||
public function generatePHID() {
|
||||
return PhabricatorPHID::generateNewPHID(self::PHID_TYPE);
|
||||
}
|
||||
|
||||
}
|
13
src/applications/people/storage/user/__init__.php
Normal file
13
src/applications/people/storage/user/__init__.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/people/storage/base');
|
||||
phutil_require_module('phabricator', 'applications/phid/storage/phid');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorUser.php');
|
Loading…
Reference in a new issue