Merge branch 'platal-0.9.16'
[platal.git] / modules / googleapps.php
index f02053b..d22f9b2 100644 (file)
@@ -52,10 +52,10 @@ class GoogleAppsModule extends PLModule
 
         if ($account->active()) {
             $redirect = new Redirect(S::v('uid'));
-            $page->assign('redirect_unique', !$redirect->other_active(NULL));
+            $page->assign('redirect_unique', !$redirect->other_active('googleapps'));
 
-            $storage = new MailStorageGoogleApps(S::v('uid'));
-            $page->assign('redirect_active', $storage->active());
+            $storage = new EmailStorage(S::v('uid'), 'googleapps');
+            $page->assign('redirect_active', $storage->active);
         }
 
         // Updates the Google Apps account as required.
@@ -64,20 +64,22 @@ class GoogleAppsModule extends PLModule
                 if ($subaction == 'sync') {
                     $account->set_password_sync(true);
                     $account->set_password(S::v('password'));
-                    $page->trig("Ton mot de passe Google Apps sera dorénavant synchronisé avec ton mot de passe Polytechnique.org.");
+                    pl_redirect('googleapps#password');
                 } else if ($subaction == 'nosync') {
                     $account->set_password_sync(false);
                 } else if (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.");
                 } else {
-                    $storage = new MailStorageGoogleApps(S::v('uid'));
-                    if ($storage->disable()) {
+                    if ($redirect->modify_one_email('googleapps', false) == SUCCESS) {
                         $account->suspend();
                         $page->trig("Ton compte Google Apps est dorénavant désactivé.");
                     } else {
@@ -94,6 +96,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) {
@@ -192,7 +196,7 @@ class GoogleAppsModule extends PLModule
 
         if ($user) {
             $account = new GoogleAppsAccount($user);
-            $storage = new MailStorageGoogleApps($user);
+            $storage = new EmailStorage($user, 'googleapps');
 
             // Force synchronization of plat/al and Google Apps passwords.
             if ($action == 'forcesync' && $account->sync_password) {
@@ -204,7 +208,7 @@ class GoogleAppsModule extends PLModule
             // Displays basic account information.
             $page->assign('account', $account);
             $page->assign('admin_account', GoogleAppsAccount::is_administrator($user));
-            $page->assign('googleapps_storage', $storage->active());
+            $page->assign('googleapps_storage', $storage->active);
             $page->assign('user', $user);
 
             // Retrieves user's pending requests.