Guest User

Untitled

a guest
Oct 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. use Backend;
  2. use System\Classes\PluginBase; as PluginBase;
  3. use Event;
  4. use BackendAuth;
  5. use Session;
  6. use Illuminate\Support\Facades\Redirect;
  7.  
  8. class Plugin extends PluginBase
  9. {
  10. public function boot()
  11. {
  12. // ......
  13. // save in session that need redirect
  14. // because in this event can't do redirect
  15. Event::listen('backend.user.login', function($model) {
  16. foreach (BackendAuth::getUser()->roles as $role) {
  17. if ($role->code === 'admin') { // for example redirect only for admins
  18. Session::put('redirectAfterLogin', '/backend/some/url');
  19. }
  20. }
  21. });
  22.  
  23. Event::listen('backend.page.beforeDisplay', function($controller, $action, $params) {
  24. // .....
  25. if ($redirectAfterLogin = Session::pull('redirectAfterLogin', null)) {
  26. return Redirect::to($redirectAfterLogin); // do redirect
  27. }
  28. });
  29.  
  30. // .....
  31. }
  32. }
Add Comment
Please, Sign In to add comment