Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

286 lines
9.6 KiB

11 years ago
11 years ago
11 years ago
4 years ago
11 years ago
11 years ago
4 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
9 years ago
11 years ago
  1. <?php
  2. /**
  3. * @file mod/register.php
  4. */
  5. use Friendica\App;
  6. use Friendica\BaseModule;
  7. use Friendica\Content\Text\BBCode;
  8. use Friendica\Core\Config;
  9. use Friendica\Core\Hook;
  10. use Friendica\Core\L10n;
  11. use Friendica\Core\Logger;
  12. use Friendica\Core\PConfig;
  13. use Friendica\Core\Renderer;
  14. use Friendica\Core\System;
  15. use Friendica\Core\Worker;
  16. use Friendica\Model;
  17. use Friendica\Module\Tos;
  18. use Friendica\Util\Strings;
  19. function register_post(App $a)
  20. {
  21. BaseModule::checkFormSecurityTokenRedirectOnError('/register', 'register');
  22. $arr = ['post' => $_POST];
  23. Hook::callAll('register_post', $arr);
  24. $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
  25. if ($max_dailies) {
  26. $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
  27. if ($r && $r[0]['total'] >= $max_dailies) {
  28. return;
  29. }
  30. }
  31. switch (Config::get('config', 'register_policy')) {
  32. case REGISTER_OPEN:
  33. $blocked = 0;
  34. $verified = 1;
  35. break;
  36. case REGISTER_APPROVE:
  37. $blocked = 1;
  38. $verified = 0;
  39. break;
  40. default:
  41. case REGISTER_CLOSED:
  42. if (empty($_SESSION['authenticated']) && empty($_SESSION['administrator'])) {
  43. notice(L10n::t('Permission denied.') . EOL);
  44. return;
  45. }
  46. $blocked = 1;
  47. $verified = 0;
  48. break;
  49. }
  50. $netpublish = !empty($_POST['profile_publish_reg']);
  51. $arr = $_POST;
  52. $arr['blocked'] = $blocked;
  53. $arr['verified'] = $verified;
  54. $arr['language'] = L10n::detectLanguage();
  55. try {
  56. $result = Model\User::create($arr);
  57. } catch (Exception $e) {
  58. notice($e->getMessage());
  59. return;
  60. }
  61. $user = $result['user'];
  62. if ($netpublish && intval(Config::get('config', 'register_policy')) !== REGISTER_APPROVE) {
  63. $url = $a->getBaseUrl() . '/profile/' . $user['nickname'];
  64. Worker::add(PRIORITY_LOW, "Directory", $url);
  65. }
  66. $using_invites = Config::get('system', 'invitation_only');
  67. $num_invites = Config::get('system', 'number_invites');
  68. $invite_id = (!empty($_POST['invite_id']) ? Strings::escapeTags(trim($_POST['invite_id'])) : '');
  69. if (intval(Config::get('config', 'register_policy')) === REGISTER_OPEN) {
  70. if ($using_invites && $invite_id) {
  71. Model\Register::deleteByHash($invite_id);
  72. PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
  73. }
  74. // Only send a password mail when the password wasn't manually provided
  75. if (empty($_POST['password1']) || empty($_POST['confirm'])) {
  76. $res = Model\User::sendRegisterOpenEmail(
  77. $user,
  78. Config::get('config', 'sitename'),
  79. $a->getBaseUrl(),
  80. $result['password']
  81. );
  82. if ($res) {
  83. info(L10n::t('Registration successful. Please check your email for further instructions.') . EOL);
  84. $a->internalRedirect();
  85. } else {
  86. notice(
  87. L10n::t('Failed to send email message. Here your accout details:<br> login: %s<br> password: %s<br><br>You can change your password after login.',
  88. $user['email'],
  89. $result['password'])
  90. . EOL
  91. );
  92. }
  93. } else {
  94. info(L10n::t('Registration successful.') . EOL);
  95. $a->internalRedirect();
  96. }
  97. } elseif (intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE) {
  98. if (!strlen(Config::get('config', 'admin_email'))) {
  99. notice(L10n::t('Your registration can not be processed.') . EOL);
  100. $a->internalRedirect();
  101. }
  102. Model\Register::createForApproval($user['uid'], Config::get('system', 'language'), $_POST['permonlybox']);
  103. // invite system
  104. if ($using_invites && $invite_id) {
  105. Model\Register::deleteByHash($invite_id);
  106. PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
  107. }
  108. // send email to admins
  109. $admin_mail_list = "'" . implode("','", array_map(['Friendica\Database\DBA', 'escape'], explode(",", str_replace(" ", "", Config::get('config', 'admin_email'))))) . "'";
  110. $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
  111. $admin_mail_list
  112. );
  113. // send notification to admins
  114. foreach ($adminlist as $admin) {
  115. notification([
  116. 'type' => NOTIFY_SYSTEM,
  117. 'event' => 'SYSTEM_REGISTER_REQUEST',
  118. 'source_name' => $user['username'],
  119. 'source_mail' => $user['email'],
  120. 'source_nick' => $user['nickname'],
  121. 'source_link' => $a->getBaseUrl() . "/admin/users/",
  122. 'link' => $a->getBaseUrl() . "/admin/users/",
  123. 'source_photo' => $a->getBaseUrl() . "/photo/avatar/" . $user['uid'] . ".jpg",
  124. 'to_email' => $admin['email'],
  125. 'uid' => $admin['uid'],
  126. 'language' => $admin['language'] ? $admin['language'] : 'en',
  127. 'show_in_notification_page' => false
  128. ]);
  129. }
  130. // send notification to the user, that the registration is pending
  131. Model\User::sendRegisterPendingEmail(
  132. $user,
  133. Config::get('config', 'sitename'),
  134. $a->getBaseURL(),
  135. $result['password']
  136. );
  137. info(L10n::t('Your registration is pending approval by the site owner.') . EOL);
  138. $a->internalRedirect();
  139. }
  140. return;
  141. }
  142. function register_content(App $a)
  143. {
  144. // logged in users can register others (people/pages/groups)
  145. // even with closed registrations, unless specifically prohibited by site policy.
  146. // 'block_extended_register' blocks all registrations, period.
  147. $block = Config::get('system', 'block_extended_register');
  148. if (local_user() && ($block)) {
  149. notice("Permission denied." . EOL);
  150. return;
  151. }
  152. if ((!local_user()) && (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED)) {
  153. notice("Permission denied." . EOL);
  154. return;
  155. }
  156. $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
  157. if ($max_dailies) {
  158. $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
  159. if ($r && $r[0]['total'] >= $max_dailies) {
  160. Logger::log('max daily registrations exceeded.');
  161. notice(L10n::t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
  162. return;
  163. }
  164. }
  165. if (!empty($_SESSION['theme'])) {
  166. unset($_SESSION['theme']);
  167. }
  168. if (!empty($_SESSION['mobile-theme'])) {
  169. unset($_SESSION['mobile-theme']);
  170. }
  171. $username = defaults($_REQUEST, 'username' , '');
  172. $email = defaults($_REQUEST, 'email' , '');
  173. $openid_url = defaults($_REQUEST, 'openid_url', '');
  174. $nickname = defaults($_REQUEST, 'nickname' , '');
  175. $photo = defaults($_REQUEST, 'photo' , '');
  176. $invite_id = defaults($_REQUEST, 'invite_id' , '');
  177. $noid = Config::get('system', 'no_openid');
  178. if ($noid) {
  179. $fillwith = '';
  180. $fillext = '';
  181. $oidlabel = '';
  182. } else {
  183. $fillwith = L10n::t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
  184. $fillext = L10n::t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
  185. $oidlabel = L10n::t("Your OpenID \x28optional\x29: ");
  186. }
  187. if (Config::get('system', 'publish_all')) {
  188. $profile_publish = '<input type="hidden" name="profile_publish_reg" value="1" />';
  189. } else {
  190. $publish_tpl = Renderer::getMarkupTemplate("profile_publish.tpl");
  191. $profile_publish = Renderer::replaceMacros($publish_tpl, [
  192. '$instance' => 'reg',
  193. '$pubdesc' => L10n::t('Include your profile in member directory?'),
  194. '$yes_selected' => '',
  195. '$no_selected' => ' checked="checked"',
  196. '$str_yes' => L10n::t('Yes'),
  197. '$str_no' => L10n::t('No'),
  198. ]);
  199. }
  200. $r = q("SELECT COUNT(*) AS `contacts` FROM `contact`");
  201. $passwords = !$r[0]["contacts"];
  202. $tpl = Renderer::getMarkupTemplate("register.tpl");
  203. $arr = ['template' => $tpl];
  204. Hook::callAll('register_form', $arr);
  205. $tpl = $arr['template'];
  206. $tos = new Tos();
  207. $o = Renderer::replaceMacros($tpl, [
  208. '$invitations' => Config::get('system', 'invitation_only'),
  209. '$permonly' => intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE,
  210. '$permonlybox' => ['permonlybox', L10n::t('Note for the admin'), '', L10n::t('Leave a message for the admin, why you want to join this node')],
  211. '$invite_desc' => L10n::t('Membership on this site is by invitation only.'),
  212. '$invite_label' => L10n::t('Your invitation code: '),
  213. '$invite_id' => $invite_id,
  214. '$regtitle' => L10n::t('Registration'),
  215. '$registertext' => BBCode::convert(Config::get('config', 'register_text', '')),
  216. '$fillwith' => $fillwith,
  217. '$fillext' => $fillext,
  218. '$oidlabel' => $oidlabel,
  219. '$openid' => $openid_url,
  220. '$namelabel' => L10n::t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
  221. '$addrlabel' => L10n::t("Your Email Address: \x28Initial information will be send there, so this has to be an existing address.\x29"),
  222. '$passwords' => $passwords,
  223. '$password1' => ['password1', L10n::t('New Password:'), '', L10n::t('Leave empty for an auto generated password.')],
  224. '$password2' => ['confirm', L10n::t('Confirm:'), '', ''],
  225. '$nickdesc' => L10n::t('Choose a profile nickname. This must begin with a text character. Your profile address on this site will then be \'<strong>nickname@%s</strong>\'.', $a->getHostName()),
  226. '$nicklabel' => L10n::t('Choose a nickname: '),
  227. '$photo' => $photo,
  228. '$publish' => $profile_publish,
  229. '$regbutt' => L10n::t('Register'),
  230. '$username' => $username,
  231. '$email' => $email,
  232. '$nickname' => $nickname,
  233. '$sitename' => $a->getHostName(),
  234. '$importh' => L10n::t('Import'),
  235. '$importt' => L10n::t('Import your profile to this friendica instance'),
  236. '$showtoslink' => Config::get('system', 'tosdisplay'),
  237. '$tostext' => L10n::t('Terms of Service'),
  238. '$showprivstatement' => Config::get('system', 'tosprivstatement'),
  239. '$privstatement' => $tos->privacy_complete,
  240. '$baseurl' => System::baseurl(),
  241. '$form_security_token' => BaseModule::getFormSecurityToken("register"),
  242. '$explicit_content' => Config::get('system', 'explicit_content', false),
  243. '$explicit_content_note' => L10n::t('Note: This node explicitly contains adult content')
  244. ]);
  245. return $o;
  246. }