X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fgoogleapps.php;h=246396626c9bea97ecb65e76c63b226da85e35fc;hb=06f4daf9ceb56712582d81330896848a1a262894;hp=fda080fffb42597888ab1b7fbc31aad94e1e3251;hpb=89fcda94efa5fa0eaf7184f0f964430388624ce3;p=platal.git diff --git a/modules/googleapps.php b/modules/googleapps.php index fda080f..2463966 100644 --- a/modules/googleapps.php +++ b/modules/googleapps.php @@ -1,6 +1,6 @@ $this->make_hook('index', AUTH_MDP), - 'admin/googleapps' => $this->make_hook('admin', AUTH_MDP. 'admin'), - 'admin/googleapps/job' => $this->make_hook('admin_job', AUTH_MDP, 'admin'), + 'googleapps' => $this->make_hook('index', AUTH_MDP), + 'admin/googleapps' => $this->make_hook('admin', AUTH_MDP, 'admin'), + 'admin/googleapps/job' => $this->make_hook('admin_job', AUTH_MDP, 'admin'), 'admin/googleapps/user' => $this->make_hook('admin_user', AUTH_MDP, 'admin'), ); } - function handler_index(&$page, $action = null, $subaction = null) + function handler_index(&$page, $action = null) { require_once("emails.inc.php"); require_once("googleapps.inc.php"); $page->changeTpl('googleapps/index.tpl'); $page->addJsLink('motdepasse.js'); - $page->assign('xorg_title', 'Polytechnique.org - Compte Google Apps'); + $page->setTitle('Compte Google Apps'); - $account = new GoogleAppsAccount(S::v('uid'), S::v('forlife')); + $user = S::user(); + $account = new GoogleAppsAccount($user); // Fills up the 'is Google Apps redirection active' variable. $page->assign('redirect_active', false); $page->assign('redirect_unique', true); if ($account->active()) { - $redirect = new Redirect(S::v('uid')); + $redirect = new Redirect($user); $page->assign('redirect_unique', !$redirect->other_active('googleapps')); - $storage = new EmailStorage(S::v('uid'), 'googleapps'); + $storage = new EmailStorage($user, 'googleapps'); $page->assign('redirect_active', $storage->active); } // Updates the Google Apps account as required. if ($action) { - if ($action == 'password') { - if ($subaction == 'sync') { + if ($action == 'password' && Post::has('pwsync')) { + S::assert_xsrf_token(); + if (Post::v('pwsync') == 'sync') { $account->set_password_sync(true); $account->set_password(S::v('password')); - pl_redirect('googleapps#password'); - } else if ($subaction == 'nosync') { + } else { $account->set_password_sync(false); - } else if (Post::has('response2') && !$account->sync_password) { - $account->set_password(Post::v('response2')); } + } elseif ($action == 'password' && Post::has('response2') && !$account->sync_password) { + S::assert_xsrf_token(); + $account->set_password(Post::v('response2')); } if ($action == 'suspend' && Post::has('suspend') && $account->active()) { + S::assert_xsrf_token(); + if ($account->pending_update_suspension) { - $page->trig("Ton compte est déjà en cours de désactivation."); + $page->trigWarning("Ton compte est déjà en cours de désactivation."); } else { if ($redirect->modify_one_email('googleapps', false) == SUCCESS) { $account->suspend(); - $page->trig("Ton compte Google Apps est dorénavant désactivé."); + $page->trigSuccess("Ton compte Google Apps est dorénavant désactivé."); } else { - $page->trig("Ton compte Google Apps est ta seule adresse de redirection. Ton compte ne peux pas être désactivé."); + $page->trigError("Ton compte Google Apps est ta seule adresse de redirection. Ton compte ne peux pas être désactivé."); } } } elseif ($action == 'unsuspend' && Post::has('unsuspend') && $account->suspended()) { $account->unsuspend(Post::b('redirect_mails', true)); - $page->trig("Ta demande de réactivation a bien été prise en compte."); + $page->trigSuccess("Ta demande de réactivation a bien été prise en compte."); } if ($action == 'create') { @@ -93,6 +97,8 @@ class GoogleAppsModule extends PLModule $page->assign('password_sync', Get::b('password_sync', true)); } if ($action == 'create' && Post::has('password_sync') && Post::has('redirect_mails')) { + S::assert_xsrf_token(); + $password_sync = Post::b('password_sync'); $redirect_mails = Post::b('redirect_mails'); if ($password_sync) { @@ -102,7 +108,7 @@ class GoogleAppsModule extends PLModule } $account->create($password_sync, $password, $redirect_mails); - $page->trig("La demande de création de ton compte Google Apps a bien été enregistrée."); + $page->trigSuccess("La demande de création de ton compte Google Apps a bien été enregistrée."); } } @@ -112,7 +118,7 @@ class GoogleAppsModule extends PLModule function handler_admin(&$page, $action = null) { require_once("googleapps.inc.php"); $page->changeTpl('googleapps/admin.tpl'); - $page->assign('xorg_title', 'Polytechnique.org - Administration Google Apps'); + $page->setTitle('Administration Google Apps'); $page->assign('googleapps_admin', GoogleAppsAccount::is_administrator(S::v('uid'))); if ($action == 'ack') { @@ -121,7 +127,7 @@ class GoogleAppsModule extends PLModule XDB::execute( "DELETE FROM gapps_queue WHERE q_id = {?} AND p_status = 'hardfail'", $qid); - $page->trig("La requête échouée a bien été retirée."); + $page->trigSuccess("La requête échouée a bien été retirée."); } } @@ -158,7 +164,7 @@ class GoogleAppsModule extends PLModule function handler_admin_job(&$page, $job = null) { require_once("googleapps.inc.php"); $page->changeTpl('googleapps/admin.job.tpl'); - $page->assign('xorg_title', 'Polytechnique.org - Administration Google Apps'); + $page->setTitle('Administration Google Apps'); $page->assign('googleapps_admin', GoogleAppsAccount::is_administrator(S::v('uid'))); if ($job) { @@ -174,44 +180,53 @@ class GoogleAppsModule extends PLModule } } - function handler_admin_user(&$page, $user = null, $action = null) { + function handler_admin_user(&$page, $user = null) { require_once("emails.inc.php"); require_once("googleapps.inc.php"); $page->changeTpl('googleapps/admin.user.tpl'); - $page->assign('xorg_title', 'Polytechnique.org - Administration Google Apps'); + $page->setTitle('Administration Google Apps'); $page->assign('googleapps_admin', GoogleAppsAccount::is_administrator(S::v('uid'))); if (!$user && Post::has('login')) { $user = Post::v('login'); } - if ($user && !is_numeric($user)) { - $res = XDB::query("SELECT id FROM aliases WHERE alias = {?} AND type != 'homonyme'", $user); - $user = $res->fetchOneCell(); - } + $user = User::get($user); if ($user) { $account = new GoogleAppsAccount($user); $storage = new EmailStorage($user, 'googleapps'); - // Force synchronization of plat/al and Google Apps passwords. - if ($action == 'forcesync' && $account->sync_password) { - $res = XDB::query("SELECT password FROM auth_user_md5 WHERE user_id = {?}", $user); - $account->set_password($res->fetchOneCell()); - $page->trig('Le mot de passe a été synchronisé.'); + // Apply requested actions. + if (Post::has('suspend') && $account->active() && !$account->pending_update_suspension) { + S::assert_xsrf_token(); + $account->suspend(); + $page->trigSuccess('Le compte est en cours de suspension.'); + } else if (Post::has('unsuspend') && $account->suspended() && !$account->pending_update_suspension) { + S::assert_xsrf_token(); + $account->do_unsuspend(); + $page->trigSuccess('Le compte est en cours de réactivation.'); + } else if (Post::has('forcesync') && $account->active() && $account->sync_password) { + $account->set_password($user->password()); + $page->trigSuccess('Le mot de passe est en cours de synchronisation.'); + } else if (Post::has('sync') && $account->active()) { + $account->set_password($user->password()); + $account->set_password_sync(true); + } else if (Post::has('nosync') && $account->active()) { + $account->set_password_sync(false); } // Displays basic account information. $page->assign('account', $account); - $page->assign('admin_account', GoogleAppsAccount::is_administrator($user)); + $page->assign('admin_account', GoogleAppsAccount::is_administrator($user->id())); $page->assign('googleapps_storage', $storage->active); - $page->assign('user', $user); + $page->assign('user', $user->id()); // Retrieves user's pending requests. $res = XDB::iterator( "SELECT q_id, q_recipient_id, p_status, j_type, UNIX_TIMESTAMP(p_entry_date) AS p_entry_date FROM gapps_queue WHERE q_recipient_id = {?} - ORDER BY p_entry_date DESC", $user); + ORDER BY p_entry_date DESC", $user->id()); $page->assign('requests', $res); } }