Esempio n. 1
0
 /**
  * Dashboard index page
  */
 public static function index($finish = false)
 {
     if ($finish) {
         \Auth::showWizard('finish');
     } else {
         if (\Auth::showWizard()) {
             \Router::redirect('accounts/permissions');
         }
     }
     $templateData = array('template' => 'dashboard/content', 'title' => 'Migrate - Dashboard', 'bodyId' => 'dashboard', 'styles' => array('dashboard.css'), 'scripts' => array(), 'queue' => TasksModel::listingFor(array('user_id' => $_SESSION['current']['username']['id'], 'user_affected_id' => $_SESSION['current']['username']['id']), 4), 'services' => ServicesModel::forUser(array('id' => $_SESSION['current']['username']['id'], 'limit' => 4)), 'usernames' => $_SESSION['usernames'], 'intro' => (bool) IntroModel::first(array('page' => 'dashboard', 'group' => $_SESSION['current']['username']['group'])));
     if (!$templateData['intro']) {
         IntroModel::create(array('page' => 'dashboard', 'group' => $_SESSION['current']['username']['group']))->save();
     }
     \Render::layout('template', $templateData);
 }
Esempio n. 2
0
 public static function withCredentials()
 {
     $usernames = static::all()->toArray();
     if ($usernames) {
         foreach ($usernames as $key => $user) {
             $username = static::first($user['id'])->toArray();
             $userProfile = UsersProfilesModel::first(array('user_id' => $user['id']));
             if ($userProfile) {
                 $userProfile = $userProfile->toArray();
             }
             $credentials = UsersCredentialsModel::first(array('user_id' => $user['id']));
             if ($credentials) {
                 $credentials = $credentials->toArray();
             }
             $services = ServicesModel::forUser(array('id' => $user['id']));
             $usernames[$key] = compact('username', 'userProfile', 'credentials', 'services');
         }
     }
     return $usernames;
 }
Esempio n. 3
0
 public static function oAuthTokensLogin($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();
     $redirectUrl = BASE_URL . 'dashboard';
     // Existing (if services > 1 refresh token) + update last_login + update credentials
     if ($username->id) {
         // Credentials update
         $credentials = UsersCredentialsModel::first(array('user_id' => $username->id));
         // Refresh token if needed
         $services = ServicesModel::forUser(array('id' => $username->id));
         if (count($services) > 1) {
             $credentialsArray['username']['id'] = $username->id;
             $credentialsArray['credentials'] = $credentials->toArray();
             $tokens = static::oAuthRefreshToken($credentialsArray, false, 'force');
         }
         $credentials->access_token = $tokens['access_token'];
         $credentials->expires_at = date(DATE_TIME, time() + $tokens['expires_in']);
         $credentials->save();
         $credentials = $credentials->toArray();
         // User profile
         $userProfile = UsersProfilesModel::first(array('user_id' => $username->id))->toArray();
         // Username update
         $username->last_login = date(DATE_TIME);
         $username->save();
         $username = $username->toArray();
         $setSession = true;
         // Session thingie
         static::setUsername(compact('username', 'services', 'credentials', 'userProfile', 'setSession'));
         // New User
     } else {
         // 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);
         $tokens['expires_at'] = date(DATE_TIME, time() + $tokens['expires_in']);
         $gplus = Rest::get('https://www.googleapis.com/plus/v1/people/me', array(), array('credentials' => $tokens));
         $profile = array_merge($profile, $gplus);
         static::_createUser($profile, $tokens, 'setSession');
     }
     return array('success' => 'true', 'redirectUrl' => $redirectUrl);
 }