Stub for a account administration form (admin/user).
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Wed, 31 Dec 2008 13:45:45 +0000 (14:45 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Wed, 31 Dec 2008 13:45:45 +0000 (14:45 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/user.php
include/validations.inc.php
modules/admin.php
templates/admin/utilisateurs.tpl

index f97db1d..2e23ff0 100644 (file)
@@ -132,7 +132,7 @@ class User extends PlUser
     {
         if ($this->hruid !== null && $this->forlife !== null
             && $this->bestalias !== null && $this->display_name !== null
-            && $this->full_name !== null && $this->promo !== null && $this->perms !== null
+            && $this->full_name !== null && $this->perms !== null
             && $this->gender !== null && $this->email_format !== null) {
             return;
         }
@@ -140,15 +140,17 @@ class User extends PlUser
         global $globals;
         /** TODO: promo stuff again */
         /** TODO: fix perms field to fit new perms system */
-        $res = XDB::query("SELECT  a.hruid, d.promo,
+        $res = XDB::query("SELECT  a.hruid, a.registration_date,
                                    CONCAT(af.alias, '@{$globals->mail->domain}') AS forlife,
                                    CONCAT(ab.alias, '@{$globals->mail->domain}') AS bestalias,
                                    a.full_name, a.display_name, a.sex = 'female' AS gender,
                                    IF(a.state = 'active', at.perms, '') AS perms,
-                                   a.email_format, a.is_admin
+                                   a.email_format, a.is_admin, a.state, a.type, a.skin,
+                                   FIND_IN_SET('watch', a.flags) AS watch, a.comment,
+                                   a.weak_password IS NOT NULL AS weak_access,
+                                   a.token IS NOT NULL AS token_access
                              FROM  accounts AS a
                        INNER JOIN  account_types AS at ON (at.type = a.type)
-                       INNER JOIN  profile_display AS d ON (d.pid = a.uid)
                         LEFT JOIN  aliases AS af ON (af.id = a.uid AND af.type = 'a_vie')
                         LEFT JOIN  aliases AS ab ON (ab.id = a.uid AND FIND_IN_SET('bestalias', ab.flags))
                             WHERE  a.uid = {?}", $this->user_id);
@@ -214,6 +216,17 @@ class User extends PlUser
                                    WHERE  a.uid = {?}', $this->id());
     }
 
+    /** Overload PlUser::promo(): there no promo defined for a user in the current
+     * schema. The promo is a field from the profile.
+     */
+    public function promo()
+    {
+        if (!$this->hasProfile()) {
+            return '';
+        }
+        return $this->profile()->promo();
+    }
+
     /** Return the main profile attached with this account if any.
      */
     public function profile()
@@ -237,12 +250,27 @@ class User extends PlUser
     public function emailAlias()
     {
         global $globals;
-        return  XDB::fetchOneCell("SELECT  v.alias
-                                     FROM  virtual AS v
-                               INNER JOIN  virtual_redirect AS vr ON (v.vid = vr.vid)
-                                    WHERE  (vr.redirect = {?} OR vr.redirect = {?})
-                                           AND alias LIKE '%@{$globals->mail->alias_dom}'",
-                          $this->forlifeEmail(), $this->m4xForlifeEmail(), $this->id());
+        $data = $this->emailAliases($globals->mail->alias_dom);
+        if (count($data) > 0) {
+            return array_pop($data);
+        }
+        return null;
+    }
+
+    /** Get all the aliases the user belongs to.
+     */
+    public function emailAliases($domain = null)
+    {
+        $where = '';
+        if (!is_null($domain)) {
+            $where = XDB::format(' AND alias LIKE CONCAT("%@", {?})', $domain);
+        }
+        return XDB::fetchColumn('SELECT  v.alias
+                                   FROM  virtual AS v
+                             INNER JOIN  virtual_redirect AS vr ON (v.vid = vr.vid)
+                                  WHERE  (vr.redirect = {?} OR vr.redirect = {?})
+                                         ' . $where,
+                               $this->forlifeEmail(), $this->m4xForlifeEmail());
     }
 
     /** Get the alternative forlife email
index ce0b12d..3ab4f0f 100644 (file)
@@ -85,10 +85,7 @@ abstract class Validate
         $this->stamp  = date('YmdHis');
         $this->unique = $_unique;
         $this->type   = $_type;
-        $res = XDB::query("SELECT  promo
-                             FROM  profile_display
-                            WHERE  pid={?}", $this->user->id());
-        $this->promo = $res->fetchOneCell();
+        $this->promo  = $this->user->promo();
     }
 
     // }}}
index 4a9350e..b7d3c02 100644 (file)
@@ -49,6 +49,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/types'          => $this->make_hook('account_types', AUTH_MDP, 'admin'),
         );
     }
 
@@ -668,21 +669,14 @@ class AdminModule extends PLModule
         $page->assign('host', $host);
 
         // Display active aliases.
-        $page->assign('virtuals', XDB::iterator(
-                "SELECT  alias
-                   FROM  virtual
-             INNER JOIN  virtual_redirect USING (vid)
-                  WHERE  type = 'user' AND (redirect = {?} OR redirect = {?})",
-                $user->forlifeEmail(),
-                // TODO: remove this über-ugly hack. The issue is that you need
-                // to remove all @m4x.org addresses in virtual_redirect first.
-                $user->login() . '@' . $globals->mail->domain2));
-
+        $page->assign('virtuals', $user->emailAliases());
         $page->assign('aliases', XDB::iterator(
                 "SELECT  alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire
                    FROM  aliases
                   WHERE  id = {?} AND type != 'homonyme'
                ORDER BY  type != 'a_vie'", $user->id()));
+        $page->assign('account_types', XDB::iterator('SELECT * FROM account_types ORDER BY type'));
+        $page->assign('skins', XDB::iterator('SELECT id, name FROM skins ORDER BY name'));
 
         // Displays email redirection and the general profile.
         if ($registered && $redirect) {
@@ -1070,7 +1064,8 @@ class AdminModule extends PLModule
         $table_editor->apply($page, $action, $id);
     }
 
-    function handler_downtime(&$page, $action = 'list', $id = null) {
+    function handler_downtime(&$page, $action = 'list', $id = null)
+    {
         $page->setTitle('Administration - Coupures');
         $page->assign('title', 'Gestion des coupures');
         $table_editor = new PLTableEditor('admin/downtime','coupures','id');
@@ -1082,6 +1077,16 @@ class AdminModule extends PLModule
         $table_editor->apply($page, $action, $id);
     }
 
+    function handler_account_types(&$page, $action = 'list', $id = null) 
+    {
+        $page->setTitle('Administration - Types de comptes');
+        $page->assign('title', 'Gestion des types de comptes');
+        $table_editor = new PLTableEditor('admin/account/types', 'account_types', 'type', true);
+        $table_editor->describe('type', 'Catégorie', true);
+        $table_editor->describe('perms', 'Permissions associées', true);
+        $table_editor->apply($page, $action, $id);
+    }
+
     function handler_wiki(&$page, $action = 'list', $wikipage = null, $wikipage2 = null)
     {
         if (S::hasAuthToken()) {
index 5d3c207..4ed0a4e 100644 (file)
 {**************************************************************************}
 
 
-<h1>
-  Gestion des utilisateurs
-</h1>
-
-
 {if $smarty.post.u_kill_conf}
 <form method="post" action="admin/user">
   {xsrf_token_field}
     <input type="submit" name="u_kill" value="continuer" />
   </div>
 </form>
-{else}
-
-<form method="post" action="admin/user">
-  {xsrf_token_field}
-  <table class="tinybicol" cellspacing="0" cellpadding="2">
-    <tr>
-      <th>
-        Administrer
-      </th>
-    </tr>
-    {if !$smarty.request.login && !$mr.hruid}
-    <tr class="pair">
-      <td class="center">
-        Il est possible d'entrer ici n'importe quelle adresse email&nbsp;: redirection, melix, ou alias.
-      </td>
-    </tr>
-    {/if}
-    <tr>
-      <td class="center">
-        <input type="text" name="login" size="40" maxlength="255" value="{$smarty.request.login|default:$mr.hruid}" />
-      </td>
-    </tr>
-    <tr>
-      <td class="center">
-        <input type="hidden" name="hashpass" value="" />
-        <input type="submit" name="select" value=" edit " /> &nbsp;&nbsp;
-        <input type="submit" name="suid_button" value=" su " />  &nbsp;&nbsp;
-        <input type="submit" name="ax_button" value=" AX " /> &nbsp;&nbsp;
-        <input type="submit" name="logs_button" value=" logs " />
-      </td>
-    </tr>
-  </table>
-</form>
-
-{if $mr}
-
-<p class="smaller">
-Dernière connexion le <strong>{$lastlogin|date_format:"%d %B %Y, %T"}</strong>
-depuis <strong>{$host}</strong>.
-</p>
+{elseif $user}
 
 {literal}
 <script type="text/javascript">
@@ -118,30 +74,46 @@ function ban_read()
 </script>
 {/literal}
 
-<form id="auth" method="post" action="admin/user">
+<form id="auth" method="post" action="admin/user/{$user->login()}">
   {xsrf_token_field}
-  <table cellspacing="0" cellpadding="2" class="tinybicol">
+  <h1>Informations sur le compte</h1>
+  <p class="smaller">
+    Dernière connexion le <strong>{$lastlogin|date_format:"%d %B %Y, %T"}</strong>
+    depuis <strong>{$host}</strong>.
+  </p>
+
+  <table class="tinybicol">
     <tr>
       <th colspan="2">
         <div style="float: right; text-align: right">
-          Matricule = {$mr.matricule}<br />
-          Matricule AX = {$mr.matricule_ax}
+          Inscrit le {$user->registration_date|date_format}
         </div>
         <div style="float: left; text-align: left">
-          UID = {$mr.user_id}<br />
-          Inscription = {$mr.date_ins|date_format}
+          {icon name=user_gray} {$mr.hruid} (uid {$user->id()})
         </div>
-        <input type="hidden" name="user_id" value="{$mr.user_id}" />
+        <input type="hidden" name="uid" value="{$user->id()}" />
       </th>
     </tr>
-    <tr class="pair">
-      <td class="titre">
-        Mot de passe
+    <tr>
+      <td class="titre">Nom complet</td>
+      <td><input type="text" name="full_name" maxlength="255" value="{$user->fullName()}" /></td>
+    </tr>
+    <tr>
+      <td class="titre">Nom affiché</td>
+      <td><input type="text" name="display_name" maxlength="255" value="{$user->displayName()}" /></td>
+    </tr>
+    <tr>
+      <td class="titre">Sexe</td>
+      <td>
+        <label>femme <input type="radio" name="sex" value="female" {if $user->isFemale()}checked="checked"{/if} /></label>
+        <label><input type="radio" name="sexe" value="male" {if !$user->isFemale()}checked="checked"{/if} /> homme</label>
       </td>
+    </tr>
+    <tr class="impair">
+      <td class="titre">Mot de passe</td>
       <td>
         <div style="float: left">
-          <input type="text" name="newpass_clair" size="10" maxlength="10" value="********" />
-          <input type="hidden" name="passw" size="32" maxlength="32" value="{$mr.password}" />
+          <input type="text" name="newpass_clair" size="10" maxlength="255" value="********" />
           <input type="hidden" name="hashpass" value="" />
         </div>
         <div style="float: left; margin-top: 5px;">
@@ -149,6 +121,104 @@ function ban_read()
         </div>
       </td>
     </tr>
+    <tr class="impair">
+      <td class="titre">Mot de passe SMTP</td>
+      <td>
+        <div style="float: left">
+          <input type="password" name="weak_password" size="10" maxlength="256" value="" />
+          {if $user->weak_access}
+          <input type="submit" name="disable_weak_access" value="Supprimer" />
+          {/if}
+        </div>
+      </td>
+    </tr>
+    <tr class="impair">
+      <td class="titre">Accès RSS</td>
+      <td>
+        <label>
+          <input type="checkbox" name="token_access" {if $user->token_access}checked="checked"{/if} />
+          activer l'accès
+        </label>
+      </td>
+    </tr>
+    <tr class="impair">
+      <td class="titre">Skin</td>
+      <td>
+        <select name="skin">
+          <option value="" {if !$user->skin}selected="selected"{/if}>Aucune (défaut du système)</option>
+          {iterate from=$skins item=skin}
+          <option value="{$skin.id}" {if $user->skin eq $skin.id}selected="selected"{/if}>{$skin.name}</option>
+          {/iterate}
+        </select>
+      </td>
+    </tr>
+    <tr class="pair">
+      <td class="titre">Etat du compte</td>
+      <td>
+        <select name="state">
+          <option value="pending" {if $user->state eq 'pending'}selected="selected"{/if}>pending (Non-inscrit)</option>
+          <option value="active" {if $user->state eq 'active'}selected="selected"{/if}>active (Inscrit, peu se logguer)</option>
+          <option value="disabled" {if $user->state eq 'disabled'}selected="selected"{/if}>disabled (Inscrit, accès interdit)</option>
+        </select><br />
+        <label>
+          <input type="checkbox" name="is_admin" value="1" {if $user->is_admin}checked="checked"{/if} />
+          administrateur du site
+        </label>
+      </td>
+    </tr>
+    <tr class="pair">
+      <td class="titre">Type de compte</td>
+      <td>
+        <select name="type">
+          {iterate from=$account_types item=type}
+          <option value="{$type.type}" {if $user->type eq $type.type}selected="selected"{/if}>{$type.type} ({$type.perms})</option>
+          {/iterate}
+        </select>
+        <a href="admin/account/types">gérer</a>
+      </td>
+    </tr>
+    <tr class="pair">
+      <td class="titre">
+        Surveillance
+      </td>
+      <td>
+        <label><input type="checkbox" name="watch" {if $user->watch}checked="checked"{/if} />
+        Surveiller l'activité de ce compte</label><br />
+        <span class="smaller">Cette option permet d'avoir des logs complets de l'activité
+        du compte via le logger, et d'être alerté lors des connexions de l'utilisateur.</span>
+      </td>
+    </tr>
+    <tr class="pair">
+      <td class="titre">
+        Commentaire
+      </td>
+      <td>
+        <input type="text" name="comment" size="40" maxlength="64" value="{$user->comment}" />
+      </td>
+    </tr>
+  </table>
+  <div class="center">
+    <input type="submit" name="update_account" value="Mettre à jour" /><br />
+    <input type="submit" name="su_account" value="Prendre l'identité" />
+    <input type="submit" name="log_account" value="Consulter les logs" />
+  </div>
+
+<!--
+  <h1>Informations sur la fiche</h1>
+  <table cellspacing="0" cellpadding="2" class="tinybicol">
+    <tr>
+      <th colspan="2">
+        <div style="float: right; text-align: right">
+          Matricule = {$mr.matricule}<br />
+          Matricule AX = {$mr.matricule_ax}
+        </div>
+        <div style="float: left; text-align: left">
+          UID = {$mr.user_id}<br />
+          Inscription = {$mr.date_ins|date_format}
+        </div>
+        <input type="hidden" name="user_id" value="{$mr.user_id}" />
+      </th>
+    </tr>
     <tr class="pair">
       <td class="titre">
         Nom
@@ -228,25 +298,6 @@ function ban_read()
         <input type="text" name="promoN" size="4" maxlength="4" value="{$mr.promo}" />
       </td>
     </tr>
-    <tr class="impair">
-      <td class="titre">
-        Surveillance
-      </td>
-      <td>
-        <label><input type="checkbox" name="watchN" {if $mr.watch}checked="checked"{/if} />
-        Surveiller l'activité de ce compte</label><br />
-        <span class="smaller">Cette option permet d'avoir des logs complets de l'activité
-        du compte via le logger, et d'être alerté lors des connexions de l'utilisateur.</span>
-      </td>
-    </tr>
-    <tr class="impair">
-      <td class="titre">
-        Commentaire
-      </td>
-      <td>
-        <input type="text" name="commentN" size="40" maxlength="64" value="{$mr.comment}" />
-      </td>
-    </tr>
     {if $mr.perms eq 'pending'}
     <tr class="center">
       <td colspan="2">
@@ -305,13 +356,13 @@ Pour ceci changer ses permissions en 'disabled'.
       {/if}
     </tr>
     {/iterate}
-    {iterate from=$virtuals item=virtual}
+    {foreach from=$virtuals item=virtual}
     <tr class="{cycle values="impair,pair"}">
       <td></td>
-      <td>{$virtual.alias}</td>
+      <td>{$virtual}</td>
       <td></td>
     </tr>
-    {/iterate}
+    {/foreach}
     <tr class="{cycle values="impair,pair"}">
       <td colspan="2" class="detail">
         <input type="text" name="email" size="29" maxlength="60" value="" />
@@ -324,10 +375,11 @@ Pour ceci changer ses permissions en 'disabled'.
     </tr>
   </table>
 </form>
+-->
 
 <p><strong>* à ne modifier qu'avec l'accord express de l'utilisateur !!!</strong></p>
 
-<form id="bans" method="post" action="admin/user">
+<form id="bans" method="post" action="admin/user/{$user->login()}">
   {xsrf_token_field}
   <table cellspacing="0" cellpadding="2" class="tinybicol">
     <tr>
@@ -377,7 +429,7 @@ Pour ceci changer ses permissions en 'disabled'.
 {javascript name="ajax"}
 {test_email hruid=$user->login()}
 
-<form id="fwds" method="post" action="admin/user#fwds">
+<form id="fwds" method="post" action="admin/user/{$user->login()}#fwds">
   {xsrf_token_field}
   <table class="bicol" cellpadding="2" cellspacing="0">
     <tr>
@@ -465,6 +517,5 @@ Pour ceci changer ses permissions en 'disabled'.
 
 {/if}
 {/if}
-{/if}
 
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}