Don't set a default account type when creating an ext account
authorNicolas Iooss <nicolas.iooss_git@polytechnique.org>
Sun, 1 Jun 2014 19:44:19 +0000 (21:44 +0200)
committerNicolas Iooss <nicolas.iooss_git@polytechnique.org>
Sun, 1 Jun 2014 19:56:32 +0000 (21:56 +0200)
In the form to add a new "external account", the type "Personnel de
l'AX" is selected by default, which may lead to incorrect account hruid
when an admin forgets to change this type.  To prevent this issue, a new
empty type is added in the HTML form.

modules/admin.php
templates/admin/accounts.tpl

index d4f1390..a220bcc 100644 (file)
@@ -1515,12 +1515,14 @@ class AdminModule extends PLModule
             $sex = Post::s('sex');
             $email = Post::t('email');
             $type = Post::s('type');
-            $login = PlUser::makeHrid($firstname, $lastname, $type);
-            if (!isvalid_email($email)) {
+            if (!$type) {
+                $page->trigError("Empty account type");
+            } elseif (!isvalid_email($email)) {
                 $page->trigError("Invalid email address: $email");
-            } else if (strlen(Post::s('pwhash')) != 40) {
+            } elseif (strlen(Post::s('pwhash')) != 40) {
                 $page->trigError("Invalid password hash");
             } else {
+                $login = PlUser::makeHrid($firstname, $lastname, $type);
                 $full_name = $firstname . ' ' . $lastname;
                 $directory_name = $lastname . ' ' . $firstname;
                 XDB::execute("INSERT INTO  accounts (hruid, type, state, password,
index a4a91b9..6d1a619 100644 (file)
@@ -75,6 +75,7 @@ function add_user_to_url(f) {
         <td class="titre">Type de compte</td>
         <td>
           <select name="type">
+            <option value="" disabled selected>-</option>
             <option value="ax">Personnel de l'AX</option>
             <option value="fx">Personnel de la FX</option>
             <option value="school">Personnel de l'Ecole</option>