PageRenderTime 58ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/pages/register.php

https://github.com/eXtreme-Fusion/eXtreme-Fusion-CMS
PHP | 324 lines | 272 code | 34 blank | 18 comment | 39 complexity | 530b6f1936e863c6c79098029e10cd0e MD5 | raw file
  1. <?php defined('EF5_SYSTEM') || exit;
  2. /*********************************************************
  3. | eXtreme-Fusion 5
  4. | Content Management System
  5. |
  6. | Copyright (c) 2005-2013 eXtreme-Fusion Crew
  7. | http://extreme-fusion.org/
  8. |
  9. | This program is released as free software under the
  10. | Affero GPL license. You can redistribute it and/or
  11. | modify it under the terms of this license which you
  12. | can read by viewing the included agpl.txt or online
  13. | at www.gnu.org/licenses/agpl.html. Removal of this
  14. | copyright header is strictly prohibited without
  15. | written permission from the original author(s).
  16. *********************************************************/
  17. if ($_user->isLoggedIn())
  18. {
  19. HELP::redirect(ADDR_SITE);
  20. }
  21. $_locale->load('register');
  22. $theme = array(
  23. 'Title' => __('Register').' » '.$_sett->get('site_name'),
  24. 'Keys' => 'Rejestracja, stwórz konto, uzyskaj dostęp',
  25. 'Desc' => 'Chcesz zarejestrować się na: '.$_sett->get('site_name').'? Możesz to zrobić już teraz.'
  26. );
  27. if ($_sett->get('enable_registration') !== '1')
  28. {
  29. // Rejestracja wyłaczona, wyświetlę komunikat
  30. throw new userException('Rejestra została wyłączona przez Administratora.');
  31. }
  32. $_mail = new Mailer($_sett->get('smtp_username'), $_sett->get('smtp_password'), $_sett->get('smtp_host'), $_sett->get('smtp_port'));
  33. $_protection = NULL;
  34. if ($validate_method = $_sett->getUnserialized('validation', 'register'))
  35. {
  36. $_security = new Security($_pdo, $_request, $_locale);
  37. // Zwraca referencje obiektu klasy zabezpieczejącej
  38. if ($_protection = $_security->getCurrentModule($validate_method))
  39. {
  40. // Przekazywanie referencji do obiektów
  41. $_protection->setObjects($_tpl, $_pdo, $_locale);
  42. }
  43. }
  44. if ($_route->getByID(1) === 'active' && $_route->getByID(2))
  45. {
  46. $valid = $_pdo->getRow('SELECT `id` FROM [users] WHERE `valid_code`= :code',
  47. array(':code', $_route->getByID(2), PDO::PARAM_STR)
  48. );
  49. if ($_sett->get('admin_activation') === '1')
  50. {
  51. $status = 2;
  52. }
  53. else
  54. {
  55. $status = 0;
  56. }
  57. $query = $_pdo->exec('UPDATE [users] SET `valid` = :valid, `valid_code` = \'\', `status` = \''.$status.'\' WHERE `id` = :id',
  58. array(
  59. array(':valid', 1, PDO::PARAM_INT),
  60. array(':id', $valid['id'], PDO::PARAM_INT)
  61. )
  62. );
  63. if ($_sett->get('admin_activation') == 1)
  64. {
  65. $_tpl->assign('active', TRUE);
  66. }
  67. else
  68. {
  69. $_tpl->assign('create', TRUE);
  70. }
  71. }
  72. if ($_request->post('create_account')->show())
  73. {
  74. $error = array();
  75. if ( ! ($_request->post('username')->show() && $_request->post('user_pass')->show() && $_request->post('user_email')->show() && $_request->post('hide_email')->isNum()))
  76. {
  77. $error[] = '1';
  78. }
  79. if ( ! $_user->validLogin($_request->post('username')->show()))
  80. {
  81. $error[] = '2';
  82. }
  83. else
  84. {
  85. if ( ! $_user->availableLogin($_request->post('username')->show()))
  86. {
  87. $error[] = '5';
  88. }
  89. }
  90. if ( ! $_user->validPassword($_request->post('user_pass')->show(), $_request->post('user_pass2')->show()))
  91. {
  92. $error[] = '3';
  93. }
  94. if ( ! $_user->validEmail($_request->post('user_email')->show()))
  95. {
  96. $error[] = '4';
  97. }
  98. else
  99. {
  100. if ( ! $_user->availableEmail($_request->post('user_email')->show()))
  101. {
  102. $error[] = '6';
  103. }
  104. else
  105. {
  106. if ($_user->bannedByEmail($_request->post('user_email')->show()))
  107. {
  108. $error[] = '7';
  109. $_pdo->exec('INSERT INTO [blacklist] (`ip`, `type`, `user_id`, `email`, `reason`, `datestamp`) VALUES (:ip, :type, :user_id, :email, :reason, '.time().')',
  110. array(
  111. array(':ip', $_user->getIP(), PDO::PARAM_STR),
  112. array(':type', $_user->getIPType(), PDO::PARAM_INT),
  113. array(':user_id', 1, PDO::PARAM_INT),
  114. array(':email', $_request->post('user_email')->show(), PDO::PARAM_STR),
  115. array(':reason', __('Gość próbował się rejestrować na zablokowany email lub domenę, jego adres IP został dodany do bazy danych jako podejrzany!'), PDO::PARAM_STR)
  116. )
  117. );
  118. }
  119. }
  120. }
  121. if ($_protection)
  122. {
  123. if ( ! $_protection->isValidAnswer($_security->getUserAnswer($_protection->getResponseInputs())))
  124. {
  125. $error['security'] = '8';
  126. }
  127. }
  128. if ( ! $error)
  129. {
  130. if ($_sett->get('email_verification') === '1')
  131. {
  132. $status = 1;
  133. $valid = md5(uniqid(time()));
  134. }
  135. elseif ($_sett->get('admin_activation') === '1')
  136. {
  137. $status = 2;
  138. $valid = md5(uniqid(time()));
  139. }
  140. else
  141. {
  142. $status = 0;
  143. $valid = '';
  144. }
  145. $salt = substr(sha512(uniqid(rand(), true)), 0, 5);
  146. $password = sha512($salt.'^'.$_request->post('user_pass')->show());
  147. $language = $_request->post('language')->show() ? $_request->post('language')->show() : $_sett->get('locale');
  148. $query = $_pdo->exec('
  149. INSERT INTO [users] (`username`, `password`, `salt`, `link`, `email`, `hide_email`, `valid_code`, `joined`, `status`, `role`, `roles`, `lang`)
  150. VALUES (:username, \''.$password.'\', \''.$salt.'\', :link, :email, :hidemail, :valid, '.time().', \''.$status.'\', 2, \''.serialize(array(2, 3)).'\', :lang)',
  151. array(
  152. array(':username', $_request->post('username')->show(), PDO::PARAM_STR),
  153. array(':link', HELP::Title2Link($_request->post('username')->show()), PDO::PARAM_STR),
  154. array(':email', $_request->post('user_email')->show(), PDO::PARAM_STR),
  155. array(':hidemail', $_request->post('hide_email')->show(), PDO::PARAM_STR),
  156. array(':valid', $valid, PDO::PARAM_STR),
  157. array(':lang', $language, PDO::PARAM_STR)
  158. )
  159. );
  160. if (class_exists('PhpBB', FALSE))
  161. {
  162. if ($_phpbb->bridgeOn())
  163. {
  164. $query = $_phpbb->registerPhpBB($_request->post('username')->show(), $_request->post('user_pass')->show(), $_request->post('user_email')->show());
  165. }
  166. }
  167. $lastuser = $_pdo->getRow('SELECT `id` FROM [users] WHERE `username` = :user',
  168. array(':user', $_request->post('username')->show(), PDO::PARAM_STR)
  169. );
  170. $query = $_pdo->getData('SELECT * FROM [user_fields] WHERE `register` = 1');
  171. $match = $_pdo->getRowsCount($query);
  172. $i = 0; $field = ''; $index_val = ''; $field_val = '';
  173. if($match !== NULL)
  174. {
  175. foreach($query as $data)
  176. {
  177. $index = $data['index'];
  178. $val = $_request->post($index)->show();
  179. $index_val .= '`'.$index.'`'.($i < $match-1 ? ', ' : '');
  180. $field_val .= '"'.$val.'"'.($i < $match-1 ? ', ' : '');
  181. $field .= '`'.$index.'` = "'.$val.'"'.($i < $match-1 ? ', ' : '');
  182. $i++;
  183. }
  184. if ($field)
  185. {
  186. if ($lastuser['id'] === NULL)
  187. {
  188. $_pdo->exec('UPDATE [users_data] SET '.$field);
  189. }
  190. else
  191. {
  192. $_pdo->exec('INSERT INTO [users_data] (`user_id`, '.$index_val.') VALUES ('.$lastuser['id'].', '.$field_val.') ON DUPLICATE KEY UPDATE '.$field.'');
  193. }
  194. }
  195. }
  196. if ($_sett->get('email_verification') === '1')
  197. {
  198. $message = 'Witaj '.$_request->post('username')->show().'!<br /><br />
  199. Dane dla Twojego konta na portalu '.$_sett->get('site_name').':<br />
  200. <strong>Login:</strong> '.$_request->post('username')->show().'<br />
  201. <strong>Hasło:</strong> '.$_request->post('user_pass')->show().'<br />
  202. <br />
  203. Żeby w pełni korzystać z portalu musisz aktywować swoje konto za pomocą poniższego linki:<br />
  204. <br />
  205. <a href="'.$_route->path(array('controller' => 'register', 'action' => 'active', $valid)).'">'.$_route->path(array('controller' => 'register', 'action' => 'active', $valid)).'</a><br />
  206. <br />
  207. <strong>Pozdrawiam</strong><br />
  208. <em>'.$_sett->get('site_username').'</em><br />
  209. <br />
  210. <hr />
  211. Wiadomość wysłana automatycznie. Proszę nie odpisywać.';
  212. if ($_mail->send($_request->post('user_email')->show(), $_sett->get('contact_email'), __('Aktywacja konta'), $message, array(), TRUE))
  213. {
  214. $_tpl->assign('email_send', TRUE);
  215. }
  216. else
  217. {
  218. $_tpl->assign('email_not_send', TRUE);
  219. }
  220. }
  221. elseif ($_sett->get('admin_activation') === '1')
  222. {
  223. $_tpl->assign('active', TRUE);
  224. }
  225. else
  226. {
  227. $_tpl->assign('create', TRUE);
  228. }
  229. }
  230. else
  231. {
  232. $_tpl->assignGroup(array(
  233. 'error' => $error,
  234. 'username' => $_request->post('username')->show(),
  235. 'email' => $_request->post('user_email')->show(),
  236. 'hide_email' => $_request->post('hide_email')->show()
  237. ));
  238. }
  239. }
  240. $result = $_pdo->getData('SELECT `id`, `name`, `index`, `type`, `option` FROM [user_fields] WHERE `register` = 1 ORDER by `id`');
  241. if ($result)
  242. {
  243. if ($_pdo->getRowsCount($result))
  244. {
  245. $i = 0; $data = array();
  246. foreach ($result as $row)
  247. {
  248. if ($row['type'] == 3)
  249. {
  250. $n = 0;
  251. foreach(unserialize($row['option']) as $keys => $val)
  252. {
  253. $option[$i][$keys] = array(
  254. 'value' => $val,
  255. 'n' => $n
  256. );
  257. $n++;
  258. }
  259. $_tpl->assign('option', $option);
  260. }
  261. $data[] = array(
  262. 'row_color' => $i % 2 == 0 ? 'tbl2' : 'tbl1',
  263. 'id' => $row['id'],
  264. 'name' => $row['name'],
  265. 'index' => $row['index'],
  266. 'type' => $row['type'],
  267. 'value' => NULL,
  268. );
  269. $i++;
  270. }
  271. }
  272. $_tpl->assignGroup(array(
  273. 'data' => $data,
  274. 'i' => $i
  275. ));
  276. }
  277. if ($_sett->get('enable_terms') === '1')
  278. {
  279. $_tpl->assign('license_agreement', $_sett->get('license_agreement'));
  280. }
  281. $_tpl->assignGroup(array(
  282. 'portal' => $_sett->get('site_name'),
  283. 'validation' => (bool) $_protection,
  284. 'enable_terms' => $_sett->get('enable_terms'),
  285. 'locale_set' => $_tpl->createSelectOpts($_files->createFileList(DIR_SITE.'locale', array(), TRUE, 'folders'), $_user->getLang(), FALSE, TRUE, Html::SELECT_NO_SELECTION)
  286. ));
  287. if ($_protection)
  288. {
  289. $_tpl->assign('security', isset($error['security']) ? $_protection->getView_wrongAnswer() : $_protection->getView());
  290. }