From e22e0752e3af44525d210d0b5c9f8355e190b74f Mon Sep 17 00:00:00 2001 From: Marton Kiss Date: Thu, 22 Jan 2015 14:25:50 +0100 Subject: [PATCH] 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 --- modules/groups/groups_oauth2/groups_oauth2.module | 11 +++++++++++ .../groups_oauth2_picture.module | 3 +++ 2 files changed, 14 insertions(+) diff --git a/modules/groups/groups_oauth2/groups_oauth2.module b/modules/groups/groups_oauth2/groups_oauth2.module index 9f7a342..ae09b5c 100644 --- a/modules/groups/groups_oauth2/groups_oauth2.module +++ b/modules/groups/groups_oauth2/groups_oauth2.module @@ -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); diff --git a/modules/groups/groups_oauth2/groups_oauth2_picture/groups_oauth2_picture.module b/modules/groups/groups_oauth2/groups_oauth2_picture/groups_oauth2_picture.module index 0ccb87e..43a0085 100644 --- a/modules/groups/groups_oauth2/groups_oauth2_picture/groups_oauth2_picture.module +++ b/modules/groups/groups_oauth2/groups_oauth2_picture/groups_oauth2_picture.module @@ -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);