Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. <?php
  2. /**
  3. * @package API
  4. * @subpackage System.sittetokenlogin
  5. *
  6. */
  7.  
  8. defined('_JEXEC') or die('Unauthorized Access');
  9.  
  10. jimport('joomla.filesystem.file');
  11.  
  12.  
  13. class PlgSystemSittetokenlogin extends JPlugin
  14. {
  15. public function __construct(&$subject, $config)
  16. {
  17. parent::__construct($subject, $config);
  18. }
  19.  
  20.  
  21. public function onUserAuthenticate()
  22. {
  23. //die('onUserAuthenticate');
  24.  
  25. }
  26. public function onUserLogin()
  27. {//wykonuje się
  28. //die('onUserLogin');
  29.  
  30. }
  31.  
  32. public function onUserLogout()
  33. {//wykonuje się
  34. //die('onUserLogout');
  35.  
  36. }
  37.  
  38.  
  39. public function onAfterInitialise()
  40. {
  41. //wstępne ustawienie obiektów
  42. $app = JFactory::getApplication();
  43. if ($app->isClient('administrator')) return;
  44. $input = JFactory::getApplication()->input;
  45. $headers = getallheaders ();
  46. $db = JFactory::getDbo();
  47.  
  48. //pobranie danych z rządania
  49. $loginToken = $headers['logintoken']; if(!$loginToken) $loginToken = $input->get->get('logintoken', '', 'STRING');
  50. $suser = $headers['suser']; if(!$suser) $suser = $input->get->get('suser', '', 'STRING');
  51. $spass = $headers['spass']; if(!$spass) $spass = $input->get->get('spass', '', 'STRING');
  52.  
  53. if ($loginToken) // logowanie na bazie tokenu
  54. {
  55. JPluginHelper::importPlugin('user');
  56. $sesja = $db->setQuery('SELECT * FROM `#__session` WHERE `session_id`='.$db->quote($loginToken).' LIMIT 1')->loadObject();
  57. $user = $db->setQuery('SELECT * FROM `#__users` WHERE `id`='.$db->quote($sesja->userid).' LIMIT 1')->loadObject();
  58.  
  59. $response = new JAuthenticationResponse();
  60. $response->type = 'Joomla';
  61. $response->email = $user->email;
  62. $response->fullname = $user->name;
  63. $response->username = $user->username;
  64. $response->password = '';
  65. $response->status = JAuthentication::STATUS_SUCCESS;
  66. $response->error_message = null;
  67. //print_r($response);
  68. $app->triggerEvent('onUserLogin', array((array) $response, array('action' => 'core.login.site')));
  69.  
  70. //$testuser = JFactory::getUser(); die(print_r($testuser,true));
  71. }
  72.  
  73. elseif ($suser && $spass) //logowanie na bazie loginu i hasła
  74. {
  75. $error = $app->login([
  76. 'username' => $suser,
  77. 'password' => $spass,
  78. ]);
  79. $user = JFactory::getUser();
  80. if ($user->id>0) die(JFactory::getSession()->getId());
  81. else die('login_error');
  82. }
  83.  
  84.  
  85. //przekazywanie parametrów
  86. $option = $headers['option']; $input->set('option',$option);
  87. $view = $headers['view']; $input->set('view',$view);
  88. $id = $headers['id']; $input->set('id',$id);
  89. $catid = $headers['catid']; $input->set('catid',$catid);
  90. $Itemid = $headers['Itemid']; $input->set('Itemid',$Itemid);
  91. $tmpl = $headers['tmpl']; $input->set('tmpl',$tmpl);
  92.  
  93. //$input->set('option','com_guru');
  94. //$input->set('view','gurupcategs');
  95.  
  96.  
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement