From f15d1307ff3829d58f26923e93ff4825b6eb278b Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Sun, 8 Aug 2010 16:46:34 +0200 Subject: [PATCH] Adds data edition for xnet users. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- classes/xnetpage.php | 2 +- htdocs/javascript/password.js | 5 +- modules/xnet.php | 48 ++++++++++++++++++ templates/xnet/edit.tpl | 112 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 templates/xnet/edit.tpl diff --git a/classes/xnetpage.php b/classes/xnetpage.php index 4729c82..12b50df 100644 --- a/classes/xnetpage.php +++ b/classes/xnetpage.php @@ -84,7 +84,7 @@ class XnetPage extends PlPage $sub['tous les groupes'] = 'plan'; $sub['documentation'] = 'Xnet'; if (S::user()->type == 'xnet') { - $sub['mot de passe'] = 'https://www.polytechnique.org/password'; + $sub['mon compte'] = 'member/edit'; } $sub['signaler un bug'] = array('href' => 'send_bug/'.$_SERVER['REQUEST_URI'], 'class' => 'popup_840x600'); $menu["no_title"] = $sub; diff --git a/htdocs/javascript/password.js b/htdocs/javascript/password.js index 578e345..c91a50d 100644 --- a/htdocs/javascript/password.js +++ b/htdocs/javascript/password.js @@ -21,6 +21,9 @@ function hashResponse(password1, password2, hasConfirmation) { pw1 = $('[name=' + password1 + ']').val(); + if (pw1 == '********') { + return true; + } if (hasConfirmation) { pw2 = $('[name=' + password2 + ']').val(); if (pw1 != pw2) { @@ -28,8 +31,6 @@ function hashResponse(password1, password2, hasConfirmation) { return false; } $('[name=' + password2 + ']').val(''); - } else if (pw1 == '********') { - return true; } if (pw1.length < 6) { diff --git a/modules/xnet.php b/modules/xnet.php index 136382c..beb375c 100644 --- a/modules/xnet.php +++ b/modules/xnet.php @@ -33,6 +33,7 @@ class XnetModule extends PLModule 'plan' => $this->make_hook('plan', AUTH_PUBLIC), 'photo' => $this->make_hook('photo', AUTH_MDP), 'autologin' => $this->make_hook('autologin', AUTH_MDP), + 'edit' => $this->make_hook('edit', AUTH_MDP, 'user'), 'Xnet' => $this->make_wiki_hook(), ); @@ -220,6 +221,53 @@ class XnetModule extends PLModule echo '$.ajax({ url: "'.$url.'?forceXml=1", dataType: "xml", success: function(xml) { $("body",xml).insertBefore("body"); $("body:eq(1)").remove(); }});'; exit; } + + function handler_edit(&$page) + { + global $globals; + + $user = S::user(); + if (empty($user)) { + return PL_NOT_FOUND; + } + if ($user->type != 'xnet') { + pl_redirect('index'); + } + + $page->changeTpl('xnet/edit.tpl'); + if (Post::has('change')) { + S::assert_xsrf_token(); + + // Convert user status to X + if (!Post::blank('login_X')) { + $forlife = $this->changeLogin($page, $user, Post::t('login_X')); + if ($forlife) { + pl_redirect('index'); + } + } + + // Update user info + XDB::query('UPDATE accounts + SET full_name = {?}, directory_name = {?}, display_name = {?}, + sex = {?}, email = {?} + WHERE uid = {?}', + Post::t('full_name'), Post::t('directory_name'), Post::t('display_name'), + (Post::t('sex') == 'male') ? 'male' : 'female', Post::t('email'), $user->id()); + // If user is of type xnet and new password is given. + if (!Post::blank('pwhash')) { + XDB::query('UPDATE accounts + SET password = {?} + WHERE uid = {?}', + Post::t('pwhash'), $user->id()); + } + if (XDB::affectedRows()) { + $page->trigSuccess('Données mises à jour.'); + } + } + + $page->addJsLink('password.js'); + $page->assign('user', $user); + } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: diff --git a/templates/xnet/edit.tpl b/templates/xnet/edit.tpl new file mode 100644 index 0000000..4f44cc9 --- /dev/null +++ b/templates/xnet/edit.tpl @@ -0,0 +1,112 @@ +{**************************************************************************} +{* *} +{* 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 *} +{* *} +{**************************************************************************} + +

+ Édition de tes données dans l'annuaire +

+ +
+ {xsrf_token_field} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Nom affiché : + + +
+ Nom complet : + + +
+ Nom annuaire : + + +
+ Sexe : + + +
+ Email : + + +
Mot de passe : + + +
Retape-le une fois : + +
{checkpasswd prompt="password1" submit="dummy_none"}
+ + + + + +
+ +
+
+ +   + +
+
+ +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} -- 2.1.4