PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/root/alink.php

https://github.com/laszloh/account_link
PHP | 113 lines | 70 code | 17 blank | 26 comment | 12 complexity | 9237b22edbc76a3ad0aac6df609e4372 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. *
  4. * @author Laszlo Imre Hegedüs laszlo.hegedues@gmail.com
  5. *
  6. * @package alink
  7. * @copyright (c) 2008 Laszlo Imre Hegedüs
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. *
  10. */
  11. /**
  12. * @ignore
  13. */
  14. define('IN_PHPBB', true);
  15. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  16. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  17. include($phpbb_root_path . 'common.' . $phpEx);
  18. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  19. // Start session management
  20. $user->session_begin();
  21. $auth->acl($user->data);
  22. $user->setup('mods/account_link');
  23. // Exclude Bots
  24. if ($user->data['is_bot'])
  25. {
  26. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  27. }
  28. // get all reqired values
  29. $new_user = request_var('i', 0);
  30. $u_redirect = request_var('r', "{$phpbb_root_path}index.$phpEx");
  31. if(preg_match("/alink\.$phpEx/", $u_redirect))
  32. {
  33. $u_redirect = "{$phpbb_root_path}index.$phpEx";
  34. }
  35. // create redirect text
  36. if ($u_redirect === "{$phpbb_root_path}index.$phpEx" || $u_redirect === "index.$phpEx" || $u_redirect === $_SERVER['REQUEST_URI'])
  37. {
  38. $l_redirect = $user->lang['RETURN_INDEX'];
  39. }
  40. else
  41. {
  42. $l_redirect = $user->lang['RETURN_PAGE'];
  43. }
  44. // append/replace SID (may change during the session for AOL users)
  45. $u_redirect = reapply_sid($u_redirect);
  46. $redirect = '<br /><br />' . sprintf($l_redirect, '<a href="' . $u_redirect . '">', '</a>');
  47. // sanitize input
  48. if($new_user === 0)
  49. {
  50. // log a conclusive error
  51. add_log('user', 'LOG_ALINK_SWITCH_NO_UID', $user->data['username']);
  52. // display the default error to the user
  53. meta_refresh(3, $u_redirect);
  54. trigger_error($user->lang['ALINK_GENERAL_ERROR'] . $redirect);
  55. }
  56. // do a basic test, if we need to care for the rest of this file
  57. if($new_user == $user->data['user_id'])
  58. {
  59. // just redirect the user without showing him anything
  60. redirect(reapply_sid($u_redirect));
  61. }
  62. // test if current user and new user are linked together
  63. if (!$alink->is_account_linked(0, $new_user))
  64. {
  65. $id = array($new_user);
  66. user_get_id_name($id, $username_ary);
  67. add_log('user', 'LOG_ACCOUNT_NOT_LINKED', $user->data['username'], implode('', $username_ary));
  68. meta_refresh(3, $u_redirect);
  69. trigger_error(sprintf($user->lang['ACCOUNT_NOT_LINKED'], $user->data['username'], implode('', $username_ary)) . $redirect);
  70. }
  71. $persist_login = false;
  72. if ($user->cookie_data['k'] != '')
  73. {
  74. $persist_login = true;
  75. }
  76. // do the account switching
  77. // Based heavily on CB Connector by geeffland (http://cbconnector.com)
  78. $user->session_begin();
  79. $auth->acl($user->data);
  80. $user->setup(); //'ucp'
  81. $admin = false;
  82. $viewonline = true;
  83. $user->cookie_data['k'] = '';
  84. $result = $user->session_create($new_user, $admin, $persist_login, $viewonline);
  85. // we are done generate output
  86. if ($result === true)
  87. {
  88. meta_refresh(3, reapply_sid($u_redirect));
  89. trigger_error(sprintf($user->lang['ACCOUNT_SWITCH_REDIRECT'], $user->data['username']) . $redirect);
  90. }
  91. else
  92. {
  93. meta_refresh(3, $u_redirect);
  94. trigger_error('ACCT_SWITCH_ERROR' . $redirect);
  95. }
  96. ?>