plugin.hybridauth.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. switch ($modx->event->name) {
  3. case 'OnHandleRequest':
  4. if ($modx->context->key != 'web' && !$modx->user->id) {
  5. if ($user = $modx->getAuthenticatedUser($modx->context->key)) {
  6. $modx->user = $user;
  7. $modx->getUser($modx->context->key);
  8. }
  9. }
  10. if ($modx->user->isAuthenticated($modx->context->key)) {
  11. if (!$modx->user->active || $modx->user->Profile->blocked) {
  12. $modx->runProcessor('security/logout');
  13. $modx->sendRedirect($modx->makeUrl($modx->getOption('site_start'), '', '', 'full'));
  14. }
  15. }
  16. if (!empty($_REQUEST['hauth_action']) || !empty($_REQUEST['hauth_done'])) {
  17. $config = !empty($_SESSION['HybridAuth'][$modx->context->key])
  18. ? $_SESSION['HybridAuth'][$modx->context->key]
  19. : array();
  20. $path = MODX_CORE_PATH . 'components/hybridauth/model/hybridauth/';
  21. /** @var HybridAuth $HybridAuth */
  22. if ($HybridAuth = $modx->getService('HybridAuth', 'HybridAuth', $path, $config)) {
  23. if (!empty($_REQUEST['hauth_action'])) {
  24. switch ($_REQUEST['hauth_action']) {
  25. case 'login':
  26. if (!empty($_REQUEST['provider'])) {
  27. $HybridAuth->Login($_REQUEST['provider']);
  28. } else {
  29. $HybridAuth->Refresh();
  30. }
  31. break;
  32. case 'logout':
  33. $HybridAuth->Logout();
  34. break;
  35. case 'unbind':
  36. if (!empty($_REQUEST['provider'])) {
  37. $HybridAuth->runProcessor('web/service/remove', array(
  38. 'provider' => $_REQUEST['provider'],
  39. ));
  40. }
  41. $HybridAuth->Refresh();
  42. break;
  43. }
  44. } else {
  45. $HybridAuth->Login($_REQUEST['hauth_done']);
  46. }
  47. }
  48. }
  49. break;
  50. case 'OnWebAuthentication':
  51. $modx->event->_output = !empty($_SESSION['HybridAuth']['verified']);
  52. unset($_SESSION['HybridAuth']['verified']);
  53. break;
  54. case 'OnUserFormPrerender':
  55. /** @var modUser $user */
  56. if (!isset($user) || $user->get('id') < 1) {
  57. return;
  58. }
  59. $path = MODX_CORE_PATH . 'components/hybridauth/model/hybridauth/';
  60. if ($HybridAuth = $modx->getService('HybridAuth', 'HybridAuth', $path)) {
  61. $HybridAuth->regManagerTab($modx->controller, $user);
  62. }
  63. break;
  64. }