X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fgoogleapps.inc.php;h=d63af4d670dc04f4a967e5f3e3c2fc031b621b9e;hb=5660032ac785d410f90e3f5b0d6948dc90b0cfea;hp=fb9d52c98658634b2bd951c7bb2b15e94c3d9f5b;hpb=12a587df92f7bc9efeb91c1a2d27f763070b8609;p=platal.git diff --git a/include/googleapps.inc.php b/include/googleapps.inc.php index fb9d52c..d63af4d 100644 --- a/include/googleapps.inc.php +++ b/include/googleapps.inc.php @@ -1,6 +1,6 @@ id()); - list($sexe, $prenom) = $res->fetchOneRow(); - $mailer = new PlMailer('googleapps/create.mail.tpl'); $mailer->assign('account', $account); $mailer->assign('email', $user->bestEmail()); $mailer->assign('googleapps_domain', $globals->mailstorage->googleapps_domain); - $mailer->assign('prenom', $prenom); - $mailer->assign('sexe', $sexe); + $mailer->assign('prenom', $user->displayName()); + $mailer->assign('sexe', $user->isFemale()); $mailer->send(); } @@ -79,17 +73,11 @@ function post_queue_u_update($job) { } // Sends an email to the account owner. - $res = XDB::query( - "SELECT FIND_IN_SET('femme', u.flags), prenom - FROM auth_user_md5 AS u - WHERE u.user_id = {?}", $user->id()); - list($sexe, $prenom) = $res->fetchOneRow(); - $mailer = new PlMailer('googleapps/unsuspend.mail.tpl'); $mailer->assign('account', $account); $mailer->assign('email', $user->bestEmail()); - $mailer->assign('prenom', $prenom); - $mailer->assign('sexe', $sexe); + $mailer->assign('prenom', $user->displayName()); + $mailer->assign('sexe', $user->isFemale()); $mailer->send(); } } @@ -101,7 +89,7 @@ function post_queue_u_update($job) { // TODO(vincent.zanotti): add the url of gappsd, when available. class GoogleAppsAccount { - // User identification: user id, and forlife. + // User identification: user id, and hruid. private $user; public $g_account_name; @@ -119,6 +107,9 @@ class GoogleAppsAccount public $r_last_webmail; public $reporting_date; + // Nicknames (aliases) registered for that user, lazily loaded. + public $nicknames; + // Pending requests in the gappsd job queue (cf. top note). public $pending_create; public $pending_delete; @@ -272,6 +263,21 @@ class GoogleAppsAccount return $this->g_status == 'disabled'; } + // Loads and returns the list of nicknames for the user. + public function nicknames() + { + if ($this->nicknames == null) { + $res = XDB::query( + "SELECT g_nickname + FROM gapps_nicknames + WHERE g_account_name = {?} + ORDER BY g_nickname", + $this->g_account_name); + $this->nicknames = $res->fetchColumn(); + } + return $this->nicknames; + } + // Changes the GoogleApps password. public function set_password($password) { @@ -351,17 +357,7 @@ class GoogleAppsAccount if (!$this->pending_update_suspension) { if ($this->sync_password) { - $res = XDB::query( - "SELECT password - FROM auth_user_md5 - WHERE user_id = {?}", $this->user->id()); - $password = ($res->numRows() > 0 ? $res->fetchOneCell() : false); - } else { - $password = false; - } - - if ($password) { - $this->create_queue_job('u_update', array('suspended' => false, 'password' => $password)); + $this->create_queue_job('u_update', array('suspended' => false, 'password' => $this->user->password())); } else { $this->create_queue_job('u_update', array('suspended' => false)); } @@ -372,18 +368,22 @@ class GoogleAppsAccount } // Creates a new Google Apps account with the @p local parameters. - public function create($password_sync, $password, $redirect_mails) { + public function create($password_sync, $password, $redirect_mails) + { if ($this->g_status != NULL) { return; } if (!$this->pending_create) { // Retrieves information on the new account. - $res = XDB::query( - "SELECT nom, nom_usage, prenom - FROM auth_user_md5 - WHERE user_id = {?}", $this->user->id()); - list($nom, $nom_usage, $prenom) = $res->fetchOneRow(); + // TODO: retreive first_name and last_name from the profile. + if (!$user->hasProfile()) { + $prenom = $user->displayName(); + $nom = $user->fullName(); + } else { + $prenom = $user->profile()->firstName(); + $nom = $user->profile()->lastName(); + } // Adds an 'unprovisioned' entry in the gapps_accounts table. XDB::execute( @@ -399,8 +399,7 @@ class GoogleAppsAccount $password_sync, $redirect_mails, $this->g_account_name, - $prenom, - ($nom_usage ? $nom_usage : $nom)); + $prenom, $nom); // Adds the creation job in the GApps queue. $this->create_queue_job( @@ -408,7 +407,7 @@ class GoogleAppsAccount array( 'username' => $this->g_account_name, 'first_name' => $prenom, - 'last_name' => ($nom_usage ? $nom_usage : $nom), + 'last_name' => $nom, 'password' => $password, ));