Rewrite admin/accounts.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 16 Sep 2010 13:58:28 +0000 (15:58 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 16 Sep 2010 13:58:28 +0000 (15:58 +0200)
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 <florent.bruneau@polytechnique.org>
modules/admin.php
templates/admin/account_watch.tpl [new file with mode: 0644]
templates/admin/accounts.tpl
templates/admin/index.tpl
templates/admin/user.tpl

index bde2161..c98c5bc 100644 (file)
@@ -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 (file)
index 0000000..a696a16
--- /dev/null
@@ -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               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<h1>{$disabled->total()} Comptes désactivés ou surveillés</h1>
+
+<table class="bicol">
+  <tr><th>Nom</th><th>Disabled</th><th>Surveillé</th><th>Commentaire</th></tr>
+  {iterate from=$disabled item=user}
+  <tr class="{cycle values="pair,impair"}">
+    <td>
+      <a href="admin/user/{$user.hruid}">{$user.hruid}</a>
+    </td>
+    <td>
+      <input type="checkbox" disabled="disabled" {if $user.disabled}checked="checked"{/if} />
+    </td>
+    <td>
+      <input type="checkbox" disabled="disabled" {if $user.watch}checked="checked"{/if} />
+    </td>
+    <td>
+      {$user.comment}
+    </td>
+  </tr>
+  {/iterate}
+</table>
+
+<h1>{$admins->total()} Administrateurs du site</h1>
+
+<table class="tinybicol">
+  <tr><th>Utilisateur</th></tr>
+  {iterate from=$admins item=user}
+  <tr class="{cycle values="pair,impair"}">
+    <td>
+      <a href="admin/user/{$user.hruid}">{$user.hruid}</a>
+    </td>
+  </tr>
+  {/iterate}
+</table>
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index a696a16..5488d05 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-<h1>{$disabled->total()} Comptes désactivés ou surveillés</h1>
+{literal}
+<script type="text/javascript">
+/* <![CDATA[ */
+function add_user_to_url(f) {
+  f.action += '/' + f.login.value;
+}
+/* ]]> */
+</script>
+{/literal}
 
-<table class="bicol">
-  <tr><th>Nom</th><th>Disabled</th><th>Surveillé</th><th>Commentaire</th></tr>
-  {iterate from=$disabled item=user}
-  <tr class="{cycle values="pair,impair"}">
-    <td>
-      <a href="admin/user/{$user.hruid}">{$user.hruid}</a>
-    </td>
-    <td>
-      <input type="checkbox" disabled="disabled" {if $user.disabled}checked="checked"{/if} />
-    </td>
-    <td>
-      <input type="checkbox" disabled="disabled" {if $user.watch}checked="checked"{/if} />
-    </td>
-    <td>
-      {$user.comment}
-    </td>
-  </tr>
-  {/iterate}
-</table>
+<fieldset>
+  <legend>{icon name=user_edit} Administrer un compte</legend>
+  <form method="post" action="admin/user" onsubmit="add_user_to_url(this); return true">
+    {xsrf_token_field}
+    <p>
+      Il est possible d'entrer ici n'importe quelle adresse mail&nbsp;: redirection, melix, ou alias.
+    </p>
+    <p>
+      <input type="text" name="login" size="40" maxlength="255"
+             value="{if t($smarty.request.login)}{$smarty.request.login}{/if}" />
+      <input type="submit" name="select" value="edit" />
+      <input type="submit" name="su_account" value="su" />
+      <input type="submit" name="log_account" value="logs" />
+    </p>
+  </form>
+</fieldset>
 
-<h1>{$admins->total()} Administrateurs du site</h1>
+<fieldset>
+  <legend>Liste des comptes manuels</legend>
 
-<table class="tinybicol">
-  <tr><th>Utilisateur</th></tr>
-  {iterate from=$admins item=user}
-  <tr class="{cycle values="pair,impair"}">
-    <td>
-      <a href="admin/user/{$user.hruid}">{$user.hruid}</a>
-    </td>
-  </tr>
-  {/iterate}
-</table>
+  <ul>
+    {iterate item=user from=$users}
+    <li>
+      <a href="admin/user/{$user->hruid}">{$user->fullName()} ({$user->hruid} - {$user->type})</a>
+    </li>
+    {/iterate}
+  </ul>
+</fieldset>
+
+<fieldset>
+  <legend>Nouveau compte</legend>
+
+  <ul>
+    <li><a href="admin/add_accounts">Ajout d'un ensemble d'utilisateurs</a></li>
+    <li>Ajouter une secrétaire de l'AX:</li>
+  </ul>
+  <p>
+    <form action="admin/accounts" method="post">
+      {xsrf_token_field}
+      <table style="width: 75%; margin-left: auto; margin-right: auto">
+        <tr>
+          <td class="titre">Nom</td>
+          <td><input type="text" name="firstname" size=60 maxlength="255" value="" /></td>
+        </tr>
+        <tr>
+          <td class="titre">Prénom</td>
+          <td><input type="text" name="lastname" size=60" maxlength="255" value="" /></td>
+        </tr>
+        <tr>
+          <td class="titre">Sexe</td>
+          <td><input type="checkbox" name="sex" checked="checked" /></td>
+        </tr>
+        <tr>
+          <td class="titre">Email</td>
+          <td><input type="text" name="email" size="60" maxlength="255" value="" /></td>
+        </tr>
+        <tr>
+          <td class="titre">Mot de passe</td>
+          <td>
+            <div style="float: left">
+              <input type="password" name="password" size="10" maxlength="256" />
+              <input type="hidden" name="pwhash" value="" />
+            </div>
+            <div style="float: left; margin-top: 5px">
+              {checkpasswd prompt="password" submit="create_account" text="Créer le compte"}
+            </div>
+          </td>
+        </tr>
+        <tr>
+          <td colspan="2" class="center">
+            <input type="submit" name="create_account" value="Créer le compte"
+                   onclick="return hashResponse('password', false, false);" />
+          </td>
+        </tr>
+      </table>
+    </form>
+  </p>
+</fieldset>
 
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index e982af0..d8ef364 100644 (file)
     <td>
       <a href="admin/account/types">Types de comptes</a>
       &nbsp;&nbsp;|&nbsp;&nbsp;
-      <a href="admin/add_accounts">Ajout de comptes</a>
-      &nbsp;&nbsp;|&nbsp;&nbsp;
-      <a href="admin/user">Édition</a>
+      <a href="admin/accounts">Gestion des comptes</a>
       &nbsp;&nbsp;|&nbsp;&nbsp;
       <a href="admin/homonyms">Homonymes</a>
       &nbsp;&nbsp;|&nbsp;&nbsp;
       <a href="admin/deaths">Décès</a>
     </td>
   </tr>
-  <tr class="impair">
+  <tr class="pair">
     <td class="titre">Administration</td>
     <td>
       <a href="admin/dead-but-active">Décédés actifs</a>
       &nbsp;&nbsp;|&nbsp;&nbsp;
-      <a href="admin/accounts">Administrateurs/Désactivations</a>
+      <a href="admin/account/watch">Administrateurs/Désactivations</a>
       &nbsp;&nbsp;|&nbsp;&nbsp;
       <a href="admin/googleapps">Google Apps</a>
     </td>
       <a href="admin/education_degree_set">Niveau par formation</a>
     </td>
   </tr>
-  <tr class="impair">
+  <tr class="pair">
     <td class="titre">Emploi</td>
     <td>
       <a href="admin/sectors">Secteurs</a>
       <a href="admin/corps_rank">Grade</a>
     </td>
   </tr>
-  <tr class="pair">
+  <tr class="impair">
     <td class="titre">Profil</td>
     <td>
       <a href="admin/binets">Binets</a>
       <a href="admin/networking">Networking</a>
     </td>
   </tr>
-  <tr class="impair">
+  <tr class="pair">
     <td class="titre">Compte</td>
     <td>
       <a href="admin/skins">Skins</a>
index b743779..a5a790a 100644 (file)
@@ -30,7 +30,7 @@
     <input type="submit" name="account_deletion_confirmation" value="Confirmer" />
   </div>
 </form>
-{elseif $user}
+{else}
 {literal}
 
 <script type="text/javascript">
@@ -499,46 +499,6 @@ $(document).ready(function() {
   </table>
 </form>
 </div>
-
-{else}
-
-{literal}
-<script type="text/javascript">
-/* <![CDATA[ */
-  function add_user_to_url(f) {
-    f.action += '/' + f.login.value;
-  }
-/* ]]> */
-</script>
-{/literal}
-<form method="post" action="admin/user" onsubmit="add_user_to_url(this); return true">
-  {xsrf_token_field}
-  <table class="tinybicol" cellspacing="0" cellpadding="2">
-    <tr>
-      <th>
-        Administrer
-      </th>
-    </tr>
-    <tr class="pair">
-      <td class="center">
-        Il est possible d'entrer ici n'importe quelle adresse mail&nbsp;: redirection, melix, ou alias.
-      </td>
-    </tr>
-    <tr>
-      <td class="center">
-        <input type="text" name="login" size="40" maxlength="255"
-               value="{if t($smarty.request.login)}{$smarty.request.login}{/if}" />
-      </td>
-    </tr>
-    <tr>
-      <td class="center">
-        <input type="submit" name="select" value=" edit " /> &nbsp;&nbsp;
-        <input type="submit" name="su_account" value=" su " />  &nbsp;&nbsp;
-        <input type="submit" name="log_account" value=" logs " />
-      </td>
-    </tr>
-  </table>
-</form>
 {/if}
 
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}