projects
/
platal.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
User can have several nicknames.
[platal.git]
/
include
/
googleapps.inc.php
diff --git
a/include/googleapps.inc.php
b/include/googleapps.inc.php
index
6dae3b1
..
4302593
100644
(file)
--- a/
include/googleapps.inc.php
+++ b/
include/googleapps.inc.php
@@
-1,6
+1,6
@@
<?php
/***************************************************************************
<?php
/***************************************************************************
- * Copyright (C) 2003-200
8
Polytechnique.org *
+ * Copyright (C) 2003-200
9
Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
@@
-23,38
+23,29
@@
function post_queue_u_create($job) {
global $globals;
function post_queue_u_create($job) {
global $globals;
- // Retrieves the user parameters (
userid and forlife
).
+ // Retrieves the user parameters (
GoogleApps username and user_id
).
$parameters = json_decode($job['j_parameters'], true);
$parameters = json_decode($job['j_parameters'], true);
- $forlife = isset($parameters['username']) ? $parameters['username'] : null;
- $userid = $job['q_recipient_id'];
- if (!$forlife || !$userid) {
+ $username = isset($parameters['username']) ? $parameters['username'] : null;
+ if (!($user = User::getSilent($username))) {
return;
}
// Adds a redirection to the Google Apps delivery address, if requested by
// the user at creation time.
return;
}
// Adds a redirection to the Google Apps delivery address, if requested by
// the user at creation time.
- $account = new GoogleAppsAccount($user
id, $forlife
);
+ $account = new GoogleAppsAccount($user);
if ($account->activate_mail_redirection) {
require_once('emails.inc.php');
if ($account->activate_mail_redirection) {
require_once('emails.inc.php');
- $storage = new EmailStorage($user
id
, 'googleapps');
+ $storage = new EmailStorage($user, 'googleapps');
$storage->activate();
}
// Sends the 'account created' email to the user, with basic documentation.
$storage->activate();
}
// Sends the 'account created' email to the user, with basic documentation.
- $res = XDB::query(
- "SELECT FIND_IN_SET('femme', u.flags), prenom
- FROM auth_user_md5 AS u
- INNER JOIN aliases AS a ON (a.id = u.user_id)
- WHERE a.alias = {?}",
- $forlife);
- list($sexe, $prenom) = $res->fetchOneRow();
-
$mailer = new PlMailer('googleapps/create.mail.tpl');
$mailer->assign('account', $account);
$mailer = new PlMailer('googleapps/create.mail.tpl');
$mailer->assign('account', $account);
- $mailer->assign('email', $
forlife . '@' . $globals->mail->domain
);
+ $mailer->assign('email', $
user->bestEmail()
);
$mailer->assign('googleapps_domain', $globals->mailstorage->googleapps_domain);
$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();
}
$mailer->send();
}
@@
-66,36
+57,27
@@
function post_queue_u_update($job) {
// to the Google Apps delivery address, provided the account is active (it might
// have been deleted between the unsuspension and the post-queue processing).
$parameters = json_decode($job['j_parameters'], true);
// to the Google Apps delivery address, provided the account is active (it might
// have been deleted between the unsuspension and the post-queue processing).
$parameters = json_decode($job['j_parameters'], true);
- $forlife = isset($parameters['username']) ? $parameters['username'] : null;
- $userid = $job['q_recipient_id'];
- if (!$forlife || !$userid) {
+ $username = isset($parameters['username']) ? $parameters['username'] : null;
+ if (!($user = User::getSilent($username))) {
return;
}
if (isset($parameters['suspended']) && $parameters['suspended'] == false) {
require_once('emails.inc.php');
return;
}
if (isset($parameters['suspended']) && $parameters['suspended'] == false) {
require_once('emails.inc.php');
- $account = new GoogleAppsAccount($user
id, $forlife
);
+ $account = new GoogleAppsAccount($user);
if ($account->active()) {
// Re-adds the email redirection (if the user did request it).
if ($account->activate_mail_redirection) {
if ($account->active()) {
// Re-adds the email redirection (if the user did request it).
if ($account->activate_mail_redirection) {
- $storage = new EmailStorage($user
id
, 'googleapps');
+ $storage = new EmailStorage($user, 'googleapps');
$storage->activate();
}
// Sends an email to the account owner.
$storage->activate();
}
// Sends an email to the account owner.
- $res = XDB::query(
- "SELECT FIND_IN_SET('femme', u.flags), prenom
- FROM auth_user_md5 AS u
- INNER JOIN aliases AS a ON (a.id = u.user_id)
- WHERE a.alias = {?}",
- $forlife);
- list($sexe, $prenom) = $res->fetchOneRow();
-
$mailer = new PlMailer('googleapps/unsuspend.mail.tpl');
$mailer->assign('account', $account);
$mailer = new PlMailer('googleapps/unsuspend.mail.tpl');
$mailer->assign('account', $account);
- $mailer->assign('email', $
forlife . '@' . $globals->mail->domain
);
- $mailer->assign('prenom', $
prenom
);
- $mailer->assign('sexe', $
sexe
);
+ $mailer->assign('email', $
user->bestEmail()
);
+ $mailer->assign('prenom', $
user->displayName()
);
+ $mailer->assign('sexe', $
user->isFemale()
);
$mailer->send();
}
}
$mailer->send();
}
}
@@
-107,8
+89,8
@@
function post_queue_u_update($job) {
// TODO(vincent.zanotti): add the url of gappsd, when available.
class GoogleAppsAccount
{
// TODO(vincent.zanotti): add the url of gappsd, when available.
class GoogleAppsAccount
{
- // User identification: user id, and
forlife
.
- private $u
id
;
+ // User identification: user id, and
hruid
.
+ private $u
ser
;
public $g_account_name;
// Local account parameters.
public $g_account_name;
// Local account parameters.
@@
-139,15
+121,16
@@
class GoogleAppsAccount
// Constructs the account object, by retrieving all informations from the
// GApps account table, from GApps job queue, and from plat/al validation queue.
// Constructs the account object, by retrieving all informations from the
// GApps account table, from GApps job queue, and from plat/al validation queue.
- public function __construct(
$uid, $account_name = NULL
)
+ public function __construct(
User &$user
)
{
{
- if ($account_name == NULL) {
- require_once 'user.func.inc.php';
-
$account_name = get_user_forlife($uid, '_silent_user_callback')
;
+ $this->user = &$user;
+ if (!$this->user || !$this->user->login()) {
+
return
;
}
}
- $this->uid = $uid;
- $this->g_account_name = $account_name;
+ // TODO: switch to multi-domain Google Apps, and use $this->user->forlifeEmail()
+ // as Google Apps idenfiant (requires changes in gappsd).
+ $this->g_account_name = $this->user->login();
$this->g_status = NULL;
$res = XDB::query(
$this->g_status = NULL;
$res = XDB::query(
@@
-157,8
+140,7
@@
class GoogleAppsAccount
UNIX_TIMESTAMP(r_last_login) as r_last_login,
UNIX_TIMESTAMP(r_last_webmail) as r_last_webmail
FROM gapps_accounts
UNIX_TIMESTAMP(r_last_login) as r_last_login,
UNIX_TIMESTAMP(r_last_webmail) as r_last_webmail
FROM gapps_accounts
- WHERE g_account_name = {?}",
- $account_name);
+ WHERE g_account_name = {?}", $this->g_account_name);
if ($account = $res->fetchOneAssoc()) {
$this->sync_password = $account['l_sync_password'];
$this->activate_mail_redirection = $account['l_activate_mail_redirection'];
if ($account = $res->fetchOneAssoc()) {
$this->sync_password = $account['l_sync_password'];
$this->activate_mail_redirection = $account['l_activate_mail_redirection'];
@@
-192,8
+174,7
@@
class GoogleAppsAccount
FROM gapps_queue
WHERE q_recipient_id = {?} AND
p_status IN ('idle', 'active', 'softfail')
FROM gapps_queue
WHERE q_recipient_id = {?} AND
p_status IN ('idle', 'active', 'softfail')
- GROUP BY j_type",
- $this->uid);
+ GROUP BY j_type", $this->user->id());
$pending = $res->fetchOneAssoc();
$this->pending_create = $pending['pending_create'];
$this->pending_update = $pending['pending_update'];
$pending = $res->fetchOneAssoc();
$this->pending_create = $pending['pending_create'];
$this->pending_update = $pending['pending_update'];
@@
-211,7
+192,7
@@
class GoogleAppsAccount
{
require_once('validations.inc.php');
$this->pending_validation_unsuspend =
{
require_once('validations.inc.php');
$this->pending_validation_unsuspend =
- Validate::get_typed_requests_count($this->u
id
, 'gapps-unsuspend');
+ Validate::get_typed_requests_count($this->u
ser->id()
, 'gapps-unsuspend');
}
// Retrieves all the pending update job in the gappsd queue for the current
}
// Retrieves all the pending update job in the gappsd queue for the current
@@
-224,8
+205,7
@@
class GoogleAppsAccount
FROM gapps_queue
WHERE q_recipient_id = {?} AND
p_status IN ('idle', 'active', 'softfail') AND
FROM gapps_queue
WHERE q_recipient_id = {?} AND
p_status IN ('idle', 'active', 'softfail') AND
- j_type = 'u_update'",
- $this->uid);
+ j_type = 'u_update'", $this->user->id());
while ($update = $res->next()) {
$update_data = json_decode($update["j_parameters"], true);
while ($update = $res->next()) {
$update_data = json_decode($update["j_parameters"], true);
@@
-244,7
+224,7
@@
class GoogleAppsAccount
// Creates a queue job of the @p type, for the user represented by this
// GoogleAppsAccount object, using @p parameters. @p parameters is supposed
// to be a one-dimension array of key-value mappings.
// Creates a queue job of the @p type, for the user represented by this
// GoogleAppsAccount object, using @p parameters. @p parameters is supposed
// to be a one-dimension array of key-value mappings.
- // The created job as a '
normal
' priority, and is scheduled for immediate
+ // The created job as a '
immediate
' priority, and is scheduled for immediate
// execution.
private function create_queue_job($type, $parameters) {
$parameters["username"] = $this->g_account_name;
// execution.
private function create_queue_job($type, $parameters) {
$parameters["username"] = $this->g_account_name;
@@
-252,10
+232,10
@@
class GoogleAppsAccount
"INSERT INTO gapps_queue
SET q_owner_id = {?}, q_recipient_id = {?},
p_entry_date = NOW(), p_notbefore_date = NOW(),
"INSERT INTO gapps_queue
SET q_owner_id = {?}, q_recipient_id = {?},
p_entry_date = NOW(), p_notbefore_date = NOW(),
- p_priority = '
normal
',
+ p_priority = '
immediate
',
j_type = {?}, j_parameters = {?}",
S::v('uid'),
j_type = {?}, j_parameters = {?}",
S::v('uid'),
- $this->u
id
,
+ $this->u
ser->id()
,
$type,
json_encode($parameters));
}
$type,
json_encode($parameters));
}
@@
-344,7
+324,7
@@
class GoogleAppsAccount
if (!$this->pending_update_suspension && !$this->pending_validation_unsuspend) {
require_once('validations.inc.php');
if (!$this->pending_update_suspension && !$this->pending_validation_unsuspend) {
require_once('validations.inc.php');
- $unsuspend = new GoogleAppsUnsuspendReq($this->u
id
);
+ $unsuspend = new GoogleAppsUnsuspendReq($this->u
ser
);
$unsuspend->submit();
$this->pending_validation_unsuspend = true;
}
$unsuspend->submit();
$this->pending_validation_unsuspend = true;
}
@@
-361,9
+341,8
@@
class GoogleAppsAccount
if ($this->sync_password) {
$res = XDB::query(
"SELECT password
if ($this->sync_password) {
$res = XDB::query(
"SELECT password
- FROM auth_user_md5
- WHERE user_id = {?}",
- $this->uid);
+ FROM accounts
+ WHERE uid = {?}", $this->user->id());
$password = ($res->numRows() > 0 ? $res->fetchOneCell() : false);
} else {
$password = false;
$password = ($res->numRows() > 0 ? $res->fetchOneCell() : false);
} else {
$password = false;
@@
-388,11
+367,11
@@
class GoogleAppsAccount
if (!$this->pending_create) {
// Retrieves information on the new account.
if (!$this->pending_create) {
// Retrieves information on the new account.
+ // TODO: retreive first_name and last_name from the profile.
$res = XDB::query(
"SELECT nom, nom_usage, prenom
FROM auth_user_md5
$res = XDB::query(
"SELECT nom, nom_usage, prenom
FROM auth_user_md5
- WHERE user_id = {?}",
- $this->uid);
+ WHERE user_id = {?}", $this->user->id());
list($nom, $nom_usage, $prenom) = $res->fetchOneRow();
// Adds an 'unprovisioned' entry in the gapps_accounts table.
list($nom, $nom_usage, $prenom) = $res->fetchOneRow();
// Adds an 'unprovisioned' entry in the gapps_accounts table.
@@
-405,7
+384,7
@@
class GoogleAppsAccount
g_first_name = {?},
g_last_name = {?},
g_status = 'unprovisioned'",
g_first_name = {?},
g_last_name = {?},
g_status = 'unprovisioned'",
- $this->u
id
,
+ $this->u
ser->id()
,
$password_sync,
$redirect_mails,
$this->g_account_name,
$password_sync,
$redirect_mails,
$this->g_account_name,
@@
-423,7
+402,7
@@
class GoogleAppsAccount
));
// Updates the GoogleAppsAccount status.
));
// Updates the GoogleAppsAccount status.
- $this->__construct($this->u
id, $this->g_account_name
);
+ $this->__construct($this->u
ser
);
}
}
}
}