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 oAuthTokensPermissions($tokens = false) { $profile = Rest::get('https://www.googleapis.com/oauth2/v1/userinfo', array('alt' => 'json', 'access_token' => $tokens['access_token'])); $username = UsersModel::first(array('google_id' => $profile['id'], 'status' => UsersModel::STATUS_ACTIVE)) ?: UsersModel::create(); if (!static::showWizard()) { $redirectUrl = BASE_URL . 'accounts/permissions'; } else { $redirectUrl = BASE_URL . 'accounts/add'; } Util::notice(array('type' => 'success', 'text' => 'You have successfully updated your ' . $username->email . ' account permissions.')); $username->last_login = $_SESSION['current']['username']['last_login']; $username->save(); // Credentials update $credentials = UsersCredentialsModel::first(array('user_id' => $username->id)); // Get refresh token $data = array('client_id' => OAUTH_CLIENT_ID, 'client_secret' => OAUTH_CLIENT_SECRET, 'redirect_uri' => 'postmessage', 'code' => $tokens['code'], 'grant_type' => 'authorization_code'); $tokens = Rest::post('https://accounts.google.com/o/oauth2/token', $data); $credentials->refresh_token = $tokens['refresh_token']; $credentials->access_token = $tokens['access_token']; $credentials->expires_at = date(DATE_TIME, time() + $tokens['expires_in']); $credentials->save(); $services = UsersServicesModel::all(array('user_id' => $username->id))->toArray(); $credentials = $credentials->toArray(); // User profile $userProfile = UsersProfilesModel::first(array('user_id' => $username->id))->toArray(); $username = $username->toArray(); $setSession = true; // Session thingie static::setUsername(compact('username', 'services', 'credentials', 'userProfile', 'setSession')); return array('success' => 'true', 'redirectUrl' => $redirectUrl); }