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 permissions() { $templateData = array('template' => 'accounts/permissions', 'title' => 'Migrate - Permissions', 'bodyId' => 'accounts-update', 'styles' => array('accounts.css'), 'scripts' => array('accounts.js'), 'heading' => 'Select your services', 'description' => 'These are the current available services that can be used in our operations. You can select any time which services are we allowed to use. If you roll-over a service name you can see all the permissions and what action can we performe.', 'services' => ServicesModel::withPermissions(), 'servicesSoon' => ServicesModel::all(array('status' => ServicesModel::STATUS_SOON))->toArray(), 'selectedServices' => UsersServicesModel::all(array('user_id' => $_SESSION['current']['username']['id']))->column('service_id'), 'skipUrl' => 'accounts/add', 'step' => 1); \Render::layout('template', $templateData); }
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); }