Moving to GitHub.
[platal.git] / modules / googleapps.php
index bbe1c9f..c898819 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2011 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -29,10 +29,10 @@ class GoogleAppsModule extends PLModule
         }
 
         return array(
-            'googleapps'            => $this->make_hook('index',      AUTH_MDP, 'mail'),
-            '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'),
+            'googleapps'            => $this->make_hook('index',      AUTH_PASSWD, 'gapps'),
+            'admin/googleapps'      => $this->make_hook('admin',      AUTH_PASSWD, 'admin'),
+            'admin/googleapps/job'  => $this->make_hook('admin_job',  AUTH_PASSWD, 'admin'),
+            'admin/googleapps/user' => $this->make_hook('admin_user', AUTH_PASSWD, 'admin'),
         );
     }
 
@@ -49,11 +49,13 @@ class GoogleAppsModule extends PLModule
         // Fills up the 'is Google Apps redirection active' variable.
         $redirect_active = false;
         $redirect_unique = true;
+        $gapps_email = '';
 
         if ($account->active()) {
             $redirect = new Redirect($user);
             foreach ($redirect->emails as $email) {
                 if ($email->type == 'googleapps') {
+                    $gapps_email = $email->email;
                     $redirect_active = $email->active;
                     $redirect_unique = !$redirect->other_active($email->email);
                 }
@@ -68,7 +70,7 @@ class GoogleAppsModule extends PLModule
                 S::assert_xsrf_token();
                 if (Post::v('pwsync') == 'sync') {
                     $account->set_password_sync(true);
-                    $account->set_password(S::v('password'));
+                    $account->set_password($user->password());
                 } else {
                     $account->set_password_sync(false);
                 }
@@ -83,7 +85,7 @@ class GoogleAppsModule extends PLModule
                 if ($account->pending_update_suspension) {
                     $page->trigWarning("Ton compte est déjà en cours de désactivation.");
                 } else {
-                    if ($redirect->modify_one_email('googleapps', false) == SUCCESS) {
+                    if (!$redirect_active || $redirect->modify_one_email($gapps_email, false) == SUCCESS) {
                         $account->suspend();
                         $page->trigSuccess("Ton compte Google Apps est dorénavant désactivé.");
                     } else {
@@ -234,5 +236,5 @@ class GoogleAppsModule extends PLModule
     }
 }
 
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
 ?>