Skip to content

Commit 4120bb9

Browse files
committed
Redirect fixes
1 parent d836123 commit 4120bb9

File tree

10 files changed

+428
-787
lines changed

10 files changed

+428
-787
lines changed

helper.php

Lines changed: 29 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?php
22
/**
3-
* @package Login Register module for joomla
4-
* @subpackage mod_loginregister
3+
* @package Register Login Joomla Module
4+
* @version 1.9
55
* @author www.joomdev.com
6-
* @author Created on March 2016
7-
* @copyright Copyright (C) 2009 - 2016 www.joomdev.com. All rights reserved.
8-
* @license GNU GPL2 or later; see LICENSE.txt
6+
* @copyright Copyright (C) 2009 - 2018 www.joomdev.com. All rights reserved.
7+
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
98
*/
109

1110
defined('_JEXEC') or die;
@@ -16,7 +15,6 @@ public static function getUserLoginAjax(){
1615
$username = JRequest::getVar('username');
1716
$password = JRequest::getVar('password');
1817
$remember = JRequest::getVar('remember');
19-
2018
$result = JFactory::getApplication()->login(array('username'=>$username,'password'=>$password), array('remember' => $remember));$userid = JFactory::getUser()->id;
2119
if(isset($userid) && !empty($userid)){
2220
$data['message'] = '<div class="alert alert-success"><a data-dismiss="alert" class="close">x</a><div><p>'.JText::_('MOD_REGISTERLOGIN_LOGIN_SUCCESS').'</p></div></div>';
@@ -28,37 +26,34 @@ public static function getUserLoginAjax(){
2826
echo json_encode($data);
2927
exit;
3028
}
31-
3229
public static function getUserlogin($params = array()){
3330
$username = JRequest::getVar('username');
3431
$password = JRequest::getVar('password');
3532
$remember = JRequest::getVar('remember');
36-
$result = JFactory::getApplication()->login(array('username'=>$username,'password'=>$password), array('remember' =>$remember));
33+
$result = JFactory::getApplication()->login(array('username'=>$username,'password'=>$password), array('remember' =>$remember));
3734
if(isset($result) && !empty($result)){
3835
$response['error'] = false;
3936
$response['error_message'] = JText::_('MOD_REGISTERLOGIN_LOGIN_SUCCESS');
4037
}else{
4138
$response['error'] = true;
4239
$response['error_message'] = JText::_('MOD_REGISTERLOGIN_WRONG_LOGIN_MESSAGE');
4340
}
44-
return $response;
41+
return $response;
4542
}
46-
47-
// ajax registeration
43+
// ajax registeration
4844
public static function getUserRegisterAjax($params = array()){
4945
$language = JFactory::getLanguage();
5046
$language->load('com_users');
5147
$app = JFactory::getApplication();
52-
$userParams = JComponentHelper::getParams('com_users');
53-
$data = $app->input->post->get('jform', array(), 'array');
54-
$user = new JUser;
55-
48+
$userParams = JComponentHelper::getParams('com_users');
49+
$data = $app->input->post->get('jform', array(), 'array');
50+
$user = new JUser;
5651
jimport( 'joomla.application.module.helper' );
5752
$module = JModuleHelper::getModule('mod_registerlogin');
5853
$params = new JRegistry($module->params);
5954
$publickey = $params->get('public');
6055
$privatekey = $params->get('private');
61-
56+
6257
//check captcha validate
6358
$captch_enable = $params->get('enablecap_on_register');
6459
if($captch_enable){
@@ -69,15 +64,12 @@ public static function getUserRegisterAjax($params = array()){
6964
echo $msg;
7065
exit;
7166
}
72-
}
67+
}
7368
JPluginHelper::importPlugin('user');
74-
7569
$data['email'] = JStringPunycode::emailToPunycode($data['email1']);
7670
$data['password'] = $data['password1'];
77-
7871
$useractivation = $params->get('useractivation');
7972
$sendpassword = $userParams->get('sendpassword', 1);
80-
8173
if (($useractivation == 1)){
8274
$data['activation'] = JApplicationHelper::getHash(JUserHelper::genRandomPassword());
8375
$data['block'] = 1;
@@ -88,18 +80,16 @@ public static function getUserRegisterAjax($params = array()){
8880
// Bind the data.
8981
if (!$user->bind($data)){
9082
}
91-
9283
// Load the users plugin group.
9384
JPluginHelper::importPlugin('user');
94-
9585
// Store the data.
9686
if (!$user->save())
9787
{
9888
if($user->getError() == 'Username in use.'){
9989
$errorMessage = JText::_('COM_USERS_REGISTER_USERNAME_MESSAGE');
10090
}else{
10191
$errorMessage = $user->getError();
102-
}
92+
}
10393
$data['message'] = $errorMessage;
10494
$msg = $data['message'];
10595
$data['success'] = false;
@@ -108,12 +98,10 @@ public static function getUserRegisterAjax($params = array()){
10898
}else{
10999
$id = $user->id;
110100
$gId = $userParams->get('new_usertype');
111-
112-
$db = JFactory::getDBO();
113-
$query = $db->getQuery(true);
114-
101+
$db = JFactory::getDBO();
102+
$query = $db->getQuery(true);
115103
$columns = array('user_id', 'group_id');
116-
$values = array($id,$gId);
104+
$values = array($id,$gId);
117105
$query
118106
->insert($db->quoteName('#__user_usergroup_map'))
119107
->columns($db->quoteName($columns))
@@ -142,7 +130,6 @@ public static function getUserRegisterAjax($params = array()){
142130
'COM_USERS_EMAIL_ACCOUNT_DETAILS',
143131
$data['name'],
144132
$data['sitename'] );
145-
146133
if ($sendpassword){
147134
$emailBody = JText::sprintf(
148135
'COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY',
@@ -195,7 +182,6 @@ public static function getUserRegisterAjax($params = array()){
195182
catch(Exception $e){
196183
echo $e;
197184
}
198-
199185
// Send Notification mail to administrators
200186
if (($params->get('useractivation') < 2) && ($params->get('mail_to_admin') == 1))
201187
{
@@ -241,30 +227,27 @@ public static function getUserRegisterAjax($params = array()){
241227
exit;
242228
}
243229
}
244-
245230
// register user without ajax
246231
public static function getUserRegister($params = array()){
247232
$app = JFactory::getApplication();
248233
$session = JFactory::getApplication();
249-
$userParams = JComponentHelper::getParams('com_users');
250-
$data = $app->input->post->get('jform', array(), 'array');
251-
$user = new JUser;
234+
$userParams = JComponentHelper::getParams('com_users');
235+
$data = $app->input->post->get('jform', array(), 'array');
236+
$user = new JUser;
252237
$flag = true;
253-
$response = array();
238+
$response = array();
254239
jimport( 'joomla.application.module.helper' );
255240
$module = JModuleHelper::getModule('mod_registerlogin');
256241
$params = new JRegistry($module->params);
257242
$publickey = $params->get('public');
258243
$privatekey = $params->get('private');
259-
260244
//check captcha validate
261245
$captch_enable = $params->get('enablecap_on_register');
262246
if($captch_enable){
263247
if (isset($_POST["recaptcha_response_field"]) && !empty($_POST["recaptcha_response_field"])) {
264248
JPluginHelper::importPlugin('captcha');
265249
$dispatcher = JDispatcher::getInstance();
266250
$resp = $dispatcher->trigger('onCheckAnswer',$_REQUEST['recaptcha_response_field']);
267-
268251
if (!$resp[0]) {
269252
$flag = false;
270253
$response['error'] = true;
@@ -280,14 +263,12 @@ public static function getUserRegister($params = array()){
280263
return $response;
281264
exit;
282265
}
283-
}
284-
266+
}
285267
JPluginHelper::importPlugin('user');
286-
$data['email'] = JStringPunycode::emailToPunycode($data['email1']);
287-
$data['password'] = $data['password1'];
268+
$data['email'] = JStringPunycode::emailToPunycode($data['email1']);
269+
$data['password'] = $data['password1'];
288270
$useractivation = $params->get('useractivation');
289271
$sendpassword = $userParams->get('sendpassword', 1);
290-
291272
if (($useractivation == 1)){
292273
$data['activation'] = JApplicationHelper::getHash(JUserHelper::genRandomPassword());
293274
$data['block'] = 1;
@@ -297,11 +278,9 @@ public static function getUserRegister($params = array()){
297278
}
298279
// Bind the data.
299280
if (!$user->bind($data)){
300-
301281
}
302282
// Load the users plugin group.
303283
JPluginHelper::importPlugin('user');
304-
305284
// Store the data.
306285
if (!$user->save()){
307286
$response['error'] = true;
@@ -310,41 +289,35 @@ public static function getUserRegister($params = array()){
310289
}else{
311290
$id = $user->id;
312291
$gId = $userParams->get('new_usertype');
313-
$db = JFactory::getDBO();
314-
$query = $db->getQuery(true);
315-
292+
$db = JFactory::getDBO();
293+
$query = $db->getQuery(true);
316294
$columns = array('user_id', 'group_id');
317-
$values = array($id,$gId);
295+
$values = array($id,$gId);
318296
$query
319297
->insert($db->quoteName('#__user_usergroup_map'))
320298
->columns($db->quoteName($columns))
321299
->values(implode(',', $values));
322300
$db->setQuery($query);
323301
$db->execute();
324-
325302
$config = JFactory::getConfig();
326303
$query = $db->getQuery(true);
327-
328304
// Compile the notification mail values.
329305
$data = $user->getProperties();
330306
$data['fromname'] = $config->get('fromname');
331307
$data['mailfrom'] = $config->get('mailfrom');
332308
$data['sitename'] = $config->get('sitename');
333-
$data['siteurl'] = JUri::root();
334-
309+
$data['siteurl'] = JUri::root();
335310
// Handle account activation/confirmation emails.
336311
if ($useractivation == 1)
337312
{
338313
// Set the link to confirm the user email.
339314
$uri = JUri::getInstance();
340315
$base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
341316
$data['activate'] = $base . JRoute::_('index.php?option=com_users&task=registration.activate&token=' . $data['activation']);
342-
343317
$emailSubject = JText::sprintf(
344318
'COM_USERS_EMAIL_ACCOUNT_DETAILS',
345319
$data['name'],
346320
$data['sitename']);
347-
348321
if ($sendpassword){
349322
$emailBody = JText::sprintf(
350323
'COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY',
@@ -399,7 +372,6 @@ public static function getUserRegister($params = array()){
399372
catch(Exception $e){
400373
echo $e;
401374
}
402-
403375
// Send Notification mail to administrators
404376
if (($params->get('useractivation') < 2) && ($params->get('mail_to_admin') == 1))
405377
{
@@ -414,23 +386,20 @@ public static function getUserRegister($params = array()){
414386
$data['username'],
415387
$data['siteurl']
416388
);
417-
418389
// Get all admin users
419390
$query->clear()
420391
->select($db->quoteName(array('name', 'email', 'sendEmail')))
421392
->from($db->quoteName('#__users'))
422393
->where($db->quoteName('sendEmail') . ' = ' . 1);
423394

424395
$db->setQuery($query);
425-
426396
try{
427397
$rows = $db->loadObjectList();
428398
}
429399
catch (RuntimeException $e){
430400
$app->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500);
431401
return false;
432402
}
433-
434403
// Send mail to all superadministrators id
435404
foreach ($rows as $row)
436405
{
@@ -450,28 +419,22 @@ public static function getReturnUrl($params, $type)
450419
{
451420
$app = JFactory::getApplication();
452421
$item = $app->getMenu()->getItem($params->get($type));
453-
454422
// Stay on the same page
455423
$url = JUri::getInstance()->toString();
456-
457424
if ($item)
458425
{
459426
$lang = '';
460-
461427
if ($item->language !== '*' && JLanguageMultilang::isEnabled())
462428
{
463429
$lang = '&lang=' . $item->language;
464430
}
465-
466-
$url = 'index.php?Itemid=' . $item->id . $lang;
431+
$url = JURI::root().'index.php?Itemid=' . $item->id . $lang;
467432
}
468-
469433
return base64_encode($url);
470434
}
471435
public static function getType()
472436
{
473437
$user = JFactory::getUser();
474-
475438
return (!$user->get('guest')) ? 'logout' : 'login';
476439
}
477-
}
440+
}

mod_registerlogin.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?php
22
/**
3-
* @package Login Register module for joomla
4-
* @subpackage mod_loginregister
3+
* @package Register Login Joomla Module
4+
* @version 1.9
55
* @author www.joomdev.com
6-
* @author Created on March 2016
7-
* @copyright Copyright (C) 2009 - 2016 www.joomdev.com. All rights reserved.
8-
* @license GNU GPL2 or later; see LICENSE.txt
6+
* @copyright Copyright (C) 2009 - 2018 www.joomdev.com. All rights reserved.
7+
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
98
*/
109

1110
defined('_JEXEC') or die;
@@ -42,10 +41,9 @@
4241
}else{
4342
$messge = JText::_('COM_USERS_REGISTRATION_COMPLETE_VERIFY');
4443
}
45-
4644
$app->enqueueMessage($messge, 'Success');
4745
if($params->get('login')){
48-
$app->redirect($return);
46+
$app->redirect(base64_decode($return));
4947
}else{
5048
$app->redirect(JURI::current());
5149
}
@@ -58,7 +56,7 @@
5856
$loginResponse = modRegisterLoginHelper::getUserlogin($params);
5957
if(!$loginResponse['error']){
6058
if($params->get('login')){
61-
$app->redirect($return);
59+
$app->redirect(base64_decode($return));
6260
}else{
6361
$app->redirect(JURI::current());
6462
}
@@ -68,4 +66,4 @@
6866
{
6967
$layout .= '_logout';
7068
}
71-
require JModuleHelper::getLayoutPath('mod_registerlogin', $layout);
69+
require JModuleHelper::getLayoutPath('mod_registerlogin', $layout);

0 commit comments

Comments
 (0)