From 8338711c653db15f2bf5b7e3df374d13eeeac84e Mon Sep 17 00:00:00 2001
From: Florent Bruneau
Date: Thu, 16 Sep 2010 15:58:28 +0200
Subject: [PATCH] Rewrite admin/accounts.
This page can now be used as a portal for account management. It provides
the following tools:
* access to account edition page
* list of non-automatic account (currently only 'ax' accounts are listed here)
* small form to add an 'ax' account
* link to other account-related admin pages.
Signed-off-by: Florent Bruneau
---
modules/admin.php | 40 ++++++++++++-
templates/admin/account_watch.tpl | 58 +++++++++++++++++++
templates/admin/accounts.tpl | 116 ++++++++++++++++++++++++++++----------
templates/admin/index.tpl | 14 ++---
templates/admin/user.tpl | 42 +-------------
5 files changed, 187 insertions(+), 83 deletions(-)
create mode 100644 templates/admin/account_watch.tpl
diff --git a/modules/admin.php b/modules/admin.php
index bde2161..c98c5bc 100644
--- a/modules/admin.php
+++ b/modules/admin.php
@@ -47,6 +47,7 @@ class AdminModule extends PLModule
'admin/ipwatch' => $this->make_hook('ipwatch', AUTH_MDP, 'admin'),
'admin/icons' => $this->make_hook('icons', AUTH_MDP, 'admin'),
'admin/accounts' => $this->make_hook('accounts', AUTH_MDP, 'admin'),
+ 'admin/account/watch' => $this->make_hook('account_watch', AUTH_MDP, 'admin'),
'admin/account/types' => $this->make_hook('account_types', AUTH_MDP, 'admin'),
'admin/jobs' => $this->make_hook('jobs', AUTH_MDP, 'admin'),
);
@@ -381,8 +382,7 @@ class AdminModule extends PLModule
$user = User::get($login);
}
if (empty($user)) {
- $page->assign('user', false);
- return;
+ pl_redirect('admin/accounts');
}
$login = $user->login();
@@ -1141,6 +1141,40 @@ class AdminModule extends PLModule
$table_editor->apply($page, $action, $id);
}
+ function handler_accounts(PlPage $page)
+ {
+ $page->changeTpl('admin/accounts.tpl');
+ $page->setTitle('Administration - Comptes');
+ $page->addJsLink('password.js');
+
+ if (Post::has('create_account')) {
+ S::assert_xsrf_token();
+ $firstname = Post::t('firstname');
+ $lastname = strtoupper(Post::t('lastname'));
+ $sex = Post::b('sex') ? User::GENDER_FEMALE : User::GENDER_FEMALE;
+ $email = Post::t('email');
+ $login = PlUser::makeHrid($firstname, $lastname, 'ax');
+ if (!isvalid_email($email)) {
+ $page->trigError("Invalid email address: $email");
+ } else if (strlen(Post::s('pwhash')) != 40) {
+ $page->trigError("Invalid password hash");
+ } else {
+ $full_name = $firstname . ' ' . $lastname;
+ $directory_name = $lastname . ' ' . $firstname;
+ XDB::execute("INSERT INTO accounts (hruid, type, state, password,
+ registration_date, email, full_name,
+ display_name, sex, directory_name)
+ VALUES ({?}, 'ax', 'active', {?}, NOW(), {?}, {?}, {?}, {?}, {?})",
+ $login, Post::s('pwhash'), $email, $full_name, $full_name, $sex,
+ $directory_name);
+ }
+ }
+
+ $uf = new UserFilter(new UFC_AccountType('ax'));
+ $page->assign('users', $uf->iterUsers(new PlLimit(10)));
+
+ }
+
function handler_account_types(&$page, $action = 'list', $id = null)
{
$page->setTitle('Administration - Types de comptes');
@@ -1344,7 +1378,7 @@ class AdminModule extends PLModule
$page->assign('icons', $icons);
}
- function handler_accounts(&$page)
+ function handler_account_watch(&$page)
{
$page->changeTpl('admin/accounts.tpl');
$page->assign('disabled', XDB::iterator('SELECT a.hruid, FIND_IN_SET(\'watch\', a.flags) AS watch,
diff --git a/templates/admin/account_watch.tpl b/templates/admin/account_watch.tpl
new file mode 100644
index 0000000..a696a16
--- /dev/null
+++ b/templates/admin/account_watch.tpl
@@ -0,0 +1,58 @@
+{**************************************************************************}
+{* *}
+{* Copyright (C) 2003-2010 Polytechnique.org *}
+{* http://opensource.polytechnique.org/ *}
+{* *}
+{* This program is free software; you can redistribute it and/or modify *}
+{* it under the terms of the GNU General Public License as published by *}
+{* the Free Software Foundation; either version 2 of the License, or *}
+{* (at your option) any later version. *}
+{* *}
+{* This program is distributed in the hope that it will be useful, *}
+{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
+{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
+{* GNU General Public License for more details. *}
+{* *}
+{* You should have received a copy of the GNU General Public License *}
+{* along with this program; if not, write to the Free Software *}
+{* Foundation, Inc., *}
+{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
+{* *}
+{**************************************************************************}
+
+