X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fxnet.php;h=6964996b128a81aa2deecb86b33b45c04e370463;hb=f311e7ab18d2949b0101060e3c17067d621cb875;hp=607b30ca7a665430055704ed60418355e6acab3c;hpb=b80cbf0db8e7ac7e11ea2bb49bbf3efd79f4fadf;p=platal.git diff --git a/modules/xnet.php b/modules/xnet.php index 607b30c..6964996 100644 --- a/modules/xnet.php +++ b/modules/xnet.php @@ -24,20 +24,19 @@ class XnetModule extends PLModule function handlers() { return array( - 'index' => $this->make_hook('index', AUTH_PUBLIC), - 'exit' => $this->make_hook('exit', AUTH_PUBLIC), - - 'admin' => $this->make_hook('admin', AUTH_MDP, 'admin'), - 'groups' => $this->make_hook('groups', AUTH_PUBLIC), - 'groupes.php' => $this->make_hook('groups2', AUTH_PUBLIC), - 'plan' => $this->make_hook('plan', AUTH_PUBLIC), - 'photo' => $this->make_hook('photo', AUTH_MDP), - 'autologin' => $this->make_hook('autologin', AUTH_MDP), - 'login/ext' => $this->make_hook('login_ext', AUTH_PUBLIC), + 'index' => $this->make_hook('index', AUTH_PUBLIC), + 'exit' => $this->make_hook('exit', AUTH_PUBLIC), + + 'admin' => $this->make_hook('admin', AUTH_PASSWD, 'admin'), + 'groups' => $this->make_hook('groups', AUTH_PUBLIC), + 'groupes.php' => $this->make_hook('groups2', AUTH_PUBLIC), + 'plan' => $this->make_hook('plan', AUTH_PUBLIC), + // Should be removed in a future release as links will have expired anyway. 'register/ext' => $this->make_hook('register_ext', AUTH_PUBLIC), - 'edit' => $this->make_hook('edit', AUTH_MDP, 'user'), - - 'Xnet' => $this->make_wiki_hook(), + 'photo' => $this->make_hook('photo', AUTH_PASSWD, 'groups'), + 'autologin' => $this->make_hook('autologin', AUTH_PASSWD, 'groups'), + 'edit' => $this->make_hook('edit', AUTH_PASSWD, 'groups'), + 'Xnet' => $this->make_wiki_hook(), ); } @@ -227,47 +226,7 @@ class XnetModule extends PLModule exit; } - function handler_login_ext($page) - { - if (!S::logged()) { - $page->changeTpl('xnet/login.tpl'); - } else { - pl_redirect(''); - } - } - - function handler_register_ext($page, $hash = null) - { - XDB::execute('DELETE FROM register_pending_xnet - WHERE DATE_SUB(NOW(), INTERVAL 1 MONTH) > date'); - $res = XDB::fetchOneAssoc('SELECT uid, hruid - FROM register_pending_xnet - WHERE hash = {?}', - $hash); - - if (is_null($hash) || is_null($res)) { - $page->trigErrorRedirect('Cette adresse n\'existe pas ou n\'existe plus sur le serveur.', ''); - } - - if (Post::has('pwhash') && Post::t('pwhash')) { - XDB::query('UPDATE accounts - SET password = {?}, state = \'active\' - WHERE uid = {?} AND state = \'pending\' AND type = \'xnet\'', - Post::t('pwhash'), $res['uid']); - XDB::query('DELETE FROM register_pending_xnet - WHERE uid = {?}', - $res['uid']); - - S::logger($res['uid'])->log('passwd', ''); - $page->changeTpl('xnet/register.success.tpl'); - $page->assign('hruid', $res['hruid']); - } else { - $page->changeTpl('platal/password.tpl'); - $page->assign('xnet', true); - } - } - - function handler_edit(&$page) + function handler_edit($page) { global $globals; @@ -283,13 +242,6 @@ class XnetModule extends PLModule if (Post::has('change')) { S::assert_xsrf_token(); - if ($user->groupCount() == 0 && Post::t('delete') == 'OUI') { - XDB::execute('DELETE FROM accounts - WHERE uid = {?}', - $user->id()); - pl_redirect('index'); - } - // Convert user status to X if (!Post::blank('login_X')) { $forlife = $this->changeLogin($page, $user, Post::t('login_X')); @@ -298,28 +250,47 @@ class XnetModule extends PLModule } } + require_once 'emails.inc.php'; + require_once 'name.func.inc.php'; + // Update user info + $lastname = capitalize_name(Post::t('lastname')); + $firstname = capitalize_name(Post::t('firstname')); + $full_name = build_full_name($firstname, $lastname); + $directory_name = build_directory_name($firstname, $lastname); + $sort_name = build_sort_name($firstname, $lastname); XDB::query('UPDATE accounts - SET full_name = {?}, directory_name = {?}, display_name = {?}, - sex = {?}, email = {?} + SET full_name = {?}, directory_name = {?}, sort_name = {?}, display_name = {?}, + firstname = {?}, lastname = {?}, sex = {?} 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.'); + $full_name, $directory_name, $sort_name, Post::t('display_name'), + Post::t('firstname'), Post::t('lastname'), + (Post::t('sex') == 'male') ? 'male' : 'female', $user->id()); + + // Updates email. + $new_email = strtolower(Post::t('email')); + if (require_email_update($user, $new_email)) { + XDB::query('UPDATE accounts + SET email = {?} + WHERE uid = {?}', + $new_email, $user->id()); + $listClient = new MMList(S::user()); + $listClient->change_user_email($user->forlifeEmail(), $new_email); + update_alias_user($user->forlifeEmail(), $new_email); } + $user = User::getWithUID($user->id()); + S::set('user', $user); + $page->trigSuccess('Données mises à jour.'); } $page->addJsLink('password.js'); $page->assign('user', $user); } + + function handler_register_ext($page, $hash = null) + { + http_redirect(Platal::globals()->xnet->xorg_baseurl . 'register/ext/' . $hash); + } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: