public static function remove($id = null) { parent::remove($id); UsersProfilesModel::remove(array('user_id' => $id)); UsersServicesModel::remove(array('user_id' => $id)); UsersCredentialsModel::remove(array('user_id' => $id)); }
public static function oAuthRefreshToken($user = array(), $updateSession = false, $force = false) { $expires = time() + 1000; if (isset($user['credentials']['expires_at'])) { $expires = strtotime($user['credentials']['expires_at']); } if ($expires < time() || $force) { $payload = array('client_id' => OAUTH_CLIENT_ID, 'client_secret' => OAUTH_CLIENT_SECRET, 'grant_type' => 'refresh_token', 'refresh_token' => $user['credentials']['refresh_token']); $refreshedToken = Rest::post('https://accounts.google.com/o/oauth2/token', $payload); if ($refreshedToken) { // Credentials $credentials = UsersCredentialsModel::first(array('user_id' => $user['username']['id'])); $credentials->access_token = $refreshedToken['access_token']; $credentials->token_type = $refreshedToken['token_type']; $credentials->expires_at = date(DATE_TIME, time() + $refreshedToken['expires_in']); $credentials->save(); // Refresh session data if ($updateSession) { $_SESSION['usernames'][$user['username']['id']]['credentials']['access_token'] = $credentials->access_token; $_SESSION['usernames'][$user['username']['id']]['credentials']['expires_at'] = $credentials->expires_at; if ($_SESSION['current']['username']['id'] == $user['username']['id']) { $_SESSION['current'] = $_SESSION['usernames'][$user['username']['id']]; } } $user['credentials']['access_token'] = $credentials->access_token; $user['credentials']['expires_at'] = $credentials->expires_at; } return $refreshedToken; } return $user; }