X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fgoogleapps.php;h=263a24d3f5156611c95d8b7aa998b14f9c3db855;hb=e48763dcb0ddaa3189273aaec566463945720b8a;hp=05a6990d3ddf5f542e7f0389b73f3f6e84fdc3d9;hpb=25fe4c85de79aa601948d788b5754b5b6070080d;p=platal.git diff --git a/modules/googleapps.php b/modules/googleapps.php index 05a6990..263a24d 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->addJsLink('password.js'); $page->setTitle('Compte Google Apps'); $user = S::user(); @@ -61,17 +61,17 @@ class GoogleAppsModule extends PLModule // 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) { - S::assert_xsrf_token(); - $account->set_password(Post::v('response2')); } + } elseif ($action == 'password' && Post::has('pwhash') && Post::t('pwhash') && !$account->sync_password) { + S::assert_xsrf_token(); + $account->set_password(Post::t('pwhash')); } if ($action == 'suspend' && Post::has('suspend') && $account->active()) { @@ -102,9 +102,9 @@ class GoogleAppsModule extends PLModule $password_sync = Post::b('password_sync'); $redirect_mails = Post::b('redirect_mails'); if ($password_sync) { - $password = S::v('password'); + $password = $user->password(); } else { - $password = Post::v('response2'); + $password = Post::t('pwhash'); } $account->create($password_sync, $password, $redirect_mails); @@ -136,7 +136,7 @@ class GoogleAppsModule extends PLModule "SELECT q_id, q_recipient_id, a.alias, j_type, j_parameters, UNIX_TIMESTAMP(q.p_entry_date) AS p_entry_date FROM gapps_queue AS q - LEFT JOIN aliases AS a ON (a.id = q_recipient_id AND a.type = 'a_vie') + LEFT JOIN aliases AS a ON (a.uid = q_recipient_id AND a.type = 'a_vie') WHERE p_status IN ('idle', 'active', 'softfail') AND p_admin_request IS TRUE ORDER BY p_entry_date"); @@ -154,7 +154,7 @@ class GoogleAppsModule extends PLModule "SELECT q.q_id, q.q_recipient_id, a.alias, q.j_type, q.r_result, UNIX_TIMESTAMP(q.p_entry_date) AS p_entry_date FROM gapps_queue AS q - LEFT JOIN aliases AS a ON (a.id = q.q_recipient_id AND a.type = 'a_vie') + LEFT JOIN aliases AS a ON (a.uid = q.q_recipient_id AND a.type = 'a_vie') WHERE q.p_status = 'hardfail' ORDER BY p_entry_date DESC LIMIT 20"); @@ -171,8 +171,8 @@ class GoogleAppsModule extends PLModule $res = XDB::query( "SELECT q.*, ao.alias AS q_owner, ar.alias AS q_recipient FROM gapps_queue AS q - LEFT JOIN aliases AS ao ON (ao.id = q.q_owner_id AND ao.type = 'a_vie') - LEFT JOIN aliases AS ar ON (ar.id = q.q_recipient_id AND ar.type = 'a_vie') + LEFT JOIN aliases AS ao ON (ao.uid = q.q_owner_id AND ao.type = 'a_vie') + LEFT JOIN aliases AS ar ON (ar.uid = q.q_recipient_id AND ar.type = 'a_vie') WHERE q_id = {?}", $job); $sql_job = $res->fetchOneAssoc(); $sql_job['decoded_parameters'] = var_export(json_decode($sql_job['j_parameters'], true), true); @@ -180,7 +180,7 @@ 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'); @@ -196,11 +196,23 @@ class GoogleAppsModule extends PLModule $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->id()); - $account->set_password($res->fetchOneCell()); - $page->trigSuccess('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.