Try to define an exhaustive list of tables to copy.
[platal.git] / modules / googleapps.php
index 1419e22..2463966 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2009 Polytechnique.org                              *
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -29,9 +29,9 @@ class GoogleAppsModule extends PLModule
         }
 
         return array(
-            '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'),
+            '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'),
         );
     }
@@ -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.