public function indexAction() { $this->acl->checkPermission('is logged in'); $user = $this->auth->getLoggedInUser(); $this->view->user = $user; // Process external authentication providers. $external_providers = UserExternal::getExternalProviders(); if (count($user->external_accounts) > 0) { foreach ($user->external_accounts as $ext) { $external_providers[$ext->provider]['existing'] = $ext; } } $this->view->external_providers = $external_providers; // Create song lists. $song_lists = array('requested' => array('name' => 'Songs I Requested', 'icon' => 'icon-question-sign', 'items' => array()), 'liked' => array('name' => 'Songs I Liked', 'icon' => 'icon-thumbs-up', 'items' => array()), 'disliked' => array('name' => 'Songs I Disliked', 'icon' => 'icon-thumbs-down', 'items' => array())); $liked_raw = $this->em->createQuery('SELECT sv, s, st FROM Entity\\SongVote sv JOIN sv.song s JOIN sv.station st WHERE sv.user_id = :user_id ORDER BY sv.timestamp DESC')->setParameter('user_id', $user->id)->getArrayResult(); foreach ($liked_raw as $row) { $item = array('timestamp' => $row['timestamp'], 'station' => $row['station'], 'song' => $row['song']); if ((int) $row['vote'] > 0) { $song_lists['liked']['items'][] = $item; } else { $song_lists['disliked']['items'][] = $item; } } $requested_raw = $this->em->createQuery('SELECT sr, s, tr, st FROM Entity\\StationRequest sr JOIN sr.station st JOIN sr.track tr JOIN tr.song s WHERE sr.user_id = :user_id ORDER BY sr.timestamp DESC')->setParameter('user_id', $user->id)->getArrayResult(); foreach ($requested_raw as $row) { $item = array('timestamp' => $row['timestamp'], 'station' => $row['station'], 'song' => $row['track']['song']); $song_lists['requested']['items'][] = $item; } $this->view->song_lists = $song_lists; }
public function loginAction() { if (!$_POST) { $this->storeReferrer('login', false); $this->forceSecure(); } $form = new \DF\Form($this->current_module_config->forms->login); if ($this->hasParam('provider')) { $provider_name = $this->getParam('provider'); try { $ha_config = $this->_getHybridConfig(); $hybridauth = new \Hybrid_Auth($ha_config); // try to authenticate with the selected provider $adapter = $hybridauth->authenticate($provider_name); if ($hybridauth->isConnectedWith($provider_name)) { $user_profile = $adapter->getUserProfile(); $user = UserExternal::processExternal($provider_name, $user_profile); $this->auth->setUser($user); } } catch (\Exception $e) { if ($e instanceof \PVL\Exception\AccountNotLinked) { $this->alert('<b>Your social network account is not linked to a PVL account yet!</b><br>Sign in below, or create a new PVL account, then link your social accounts from your profile.', 'red'); } else { $this->alert($e->getMessage(), 'red'); } } } else { if ($_POST) { if ($form->isValid($_POST)) { $login_success = $this->auth->authenticate($form->getValues()); if ($login_success) { $user = $this->auth->getLoggedInUser(); $this->alert('<b>Logged in successfully. Welcome back, ' . $user->name . '!</b><br>For security purposes, log off when your session is complete.', 'green'); if ($this->acl->isAllowed('view administration')) { $default_url = \DF\Url::route(array('module' => 'admin')); } else { $default_url = \DF\Url::route(array('module' => 'default')); } return $this->redirectToStoredReferrer('login', $default_url); } } } } // Auto-bounce back if logged in. if ($this->auth->isLoggedIn()) { return $this->redirectToStoredReferrer('login', \DF\Url::route()); } $this->view->external_providers = UserExternal::getExternalProviders(); $this->view->form = $form; }