Skip to content

Instantly share code, notes, and snippets.

@hissy
Last active October 25, 2015 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hissy/84e352b985502b9ae54b to your computer and use it in GitHub Desktop.
Save hissy/84e352b985502b9ae54b to your computer and use it in GitHub Desktop.
#concrete5 Redirect user to one's own page when the user sign in
<?php
// for 5.7.x
// application/bootstrap/app.php
use Concrete\Core\Routing\RedirectResponse;
Events::addListener('on_user_login', function($event) {
/* @var \Concrete\Core\User\User */
$u = $event->getUserObject();
$pl = new PageList;
$pl->ignorePermissions();
$pl->filterByPageTypeHandle('example_page_type_handle');
$pl->filterByUserID($u->getUserID());
$pages = $pl->getResults();
if (is_array($pages) && count($pages) > 0) {
$url = $pages[0]->getCollectionLink();
$r = new RedirectResponse($url);
$r->send();
exit;
}
});
<?php
// for 5.6.x
// controllers/login.php
defined('C5_EXECUTE') or die("Access Denied.");
class LoginController extends Concrete5_Controller_Login
{
protected function finishLogin( $loginData=array() )
{
$u = new User();
$pl = new PageList();
$pl->ignorePermissions();
$pl->filterByCollectionTypeHandle('example_page_type_handle');
$pl->filterByUserID($u->getUserID());
$pages = $pl->get(1);
if (is_array($pages) && count($pages) > 0) {
$redirectID = $pages[0]->getCollectionID();
$redirect = Page::getByID($redirectID);
$loginData['redirectURL'] = Loader::helper('navigation')->getLinkToCollection($redirect, true);
}
parent::finishLogin($loginData);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment