Follow profile picture changes in openstack.org profile

Until the openstackid.org oauth2 not returns the hash of the profile picture
or a ttl of the last change that auth module can check, the pictures
expiring in every 24h. TTL time is stored in user profile as oauth2_picture_ttl
parameter, and authentication retriggers user profile save hooks when the
ttl is expired, resulting of refetch of the user's picture.

Change-Id: I01c84864d61248bf45932d21c21f5b62983d5df2
StoryId: 2000114
This commit is contained in:
Marton Kiss 2015-01-22 14:25:50 +01:00
parent 2655ca269d
commit e22e0752e3
2 changed files with 14 additions and 0 deletions

View File

@ -104,6 +104,17 @@ function groups_oauth2_response_handler() {
$function = $module . '_oauth2_user_save';
$function($account, $userinfo);
}
} else {
// resave user profile if oauth2_picture_ttl expired
$oauth2_picture_ttl = isset($account->data['oauth2_picture_ttl']) ?
$account->data['oauth2_picture_ttl'] : 0;
if (time() >= $oauth2_picture_ttl) {
// Allow other modules to manipulate the user information after save.
foreach (module_implements('oauth2_user_save') as $module) {
$function = $module . '_oauth2_user_save';
$function($account, $userinfo);
}
}
}
$form_state['uid'] = $account->uid;
user_login_submit(array(), $form_state);

View File

@ -15,6 +15,9 @@
*/
function groups_oauth2_picture_oauth2_user_save(&$account, $userinfo) {
$account->data['oauth2_picture'] = $userinfo->picture;
// save profile picture expiration time
$interval = variable_get('groups_oauth2_picture_interval', 60 * 60 * 24);
$account->data['oauth2_picture_ttl'] = time() + $interval;
user_save($account);
if (variable_get('oauth2_fetch_profile_picture', FALSE)) {
$image_path = _groups_oauth2_get_profile_picture_filename($userinfo->picture);