Last active
October 25, 2015 22:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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