maddmac Posted March 13, 2017 Share Posted March 13, 2017 I would like to redirect users from a specific role group to a specific URL upon login. Any thought on how to accomplish this? Link to comment Share on other sites More sharing options...
adrian Posted March 13, 2017 Share Posted March 13, 2017 Put this in your site/ready.php file: $this->addHookAfter('Session::loginSuccess', null, function($event) { if($this->wire('user')->hasRole("target-role")) $this->wire('session')->redirect("other-url"); }); 12 1 Link to comment Share on other sites More sharing options...
BitPoet Posted March 13, 2017 Share Posted March 13, 2017 Hook after ProcessLogin::afterLogin and there, if $this->user->roles has a match, do a $this->session->redirect(). 2 Link to comment Share on other sites More sharing options...
maddmac Posted March 13, 2017 Author Share Posted March 13, 2017 4 minutes ago, BitPoet said: Hook after ProcessLogin::afterLogin and there, if $this->user->roles has a match, do a $this->session->redirect(). 24 minutes ago, adrian said: Put this in your site/ready.php file: $this->addHookAfter('Session::loginSuccess', null, function($event) { if($this->wire('user')->hasRole("target-role")) $this->wire('session')->redirect("other-url"); }); That did the trick. Thank you 2 Link to comment Share on other sites More sharing options...
chcs Posted May 31, 2018 Share Posted May 31, 2018 I put the following code into our membership module but it does not seem to redirect. Any ideas why? Thanks. public function init() { parent::init(); // set landing page $this->addHookAfter('Session::loginSuccess', null, function($event) { if (!$this->wire('user')->isSuperuser()) { $path = $this->wire('config')->urls->admin . "membership/"; $this->wire('session')->redirect($path); } }); } Link to comment Share on other sites More sharing options...
flydev Posted May 31, 2018 Share Posted May 31, 2018 2 hours ago, chcs said: I put the following code into our membership module but it does not seem to redirect. Any ideas why? Thanks. Is your module autoload property set to true ? if not, then set 'autoload' => true in the module info or if you want your module to be an autoload only on the admin area, then set autoload to : 'autoload' => function () { return (wire('page')->template == 'admin'); } 1 Link to comment Share on other sites More sharing options...
chcs Posted June 15, 2018 Share Posted June 15, 2018 Setting 'autoload' => true in the module info worked. Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now