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.
 
 
 
 
 
 

292 lines
9.1 KiB

  1. <?php
  2. require_once('include/email.php');
  3. if(! function_exists('register_post')) {
  4. function register_post(&$a) {
  5. global $lang;
  6. $verified = 0;
  7. $blocked = 1;
  8. $arr = array('post' => $_POST);
  9. call_hooks('register_post', $arr);
  10. $max_dailies = intval(get_config('system','max_daily_registrations'));
  11. if($max_dailies) {
  12. $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
  13. if($r && $r[0]['total'] >= $max_dailies) {
  14. return;
  15. }
  16. }
  17. switch($a->config['register_policy']) {
  18. case REGISTER_OPEN:
  19. $blocked = 0;
  20. $verified = 1;
  21. break;
  22. case REGISTER_APPROVE:
  23. $blocked = 1;
  24. $verified = 0;
  25. break;
  26. default:
  27. case REGISTER_CLOSED:
  28. if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {
  29. notice( t('Permission denied.') . EOL );
  30. return;
  31. }
  32. $blocked = 1;
  33. $verified = 0;
  34. break;
  35. }
  36. require_once('include/user.php');
  37. $arr = $_POST;
  38. $arr['blocked'] = $blocked;
  39. $arr['verified'] = $verified;
  40. $result = create_user($arr);
  41. if(! $result['success']) {
  42. notice($result['message']);
  43. return;
  44. }
  45. $user = $result['user'];
  46. if($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) {
  47. $url = $a->get_baseurl() . '/profile/' . $user['nickname'];
  48. proc_run('php',"include/directory.php","$url");
  49. }
  50. $using_invites = get_config('system','invitation_only');
  51. $num_invites = get_config('system','number_invites');
  52. $invite_id = ((x($_POST,'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
  53. if( $a->config['register_policy'] == REGISTER_OPEN ) {
  54. if($using_invites && $invite_id) {
  55. q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
  56. set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
  57. }
  58. $email_tpl = get_intltext_template("register_open_eml.tpl");
  59. $email_tpl = replace_macros($email_tpl, array(
  60. '$sitename' => $a->config['sitename'],
  61. '$siteurl' => $a->get_baseurl(),
  62. '$username' => $user['username'],
  63. '$email' => $user['email'],
  64. '$password' => $result['password'],
  65. '$uid' => $user['uid'] ));
  66. $res = mail($user['email'], email_header_encode( sprintf( t('Registration details for %s'), $a->config['sitename']),'UTF-8'),
  67. $email_tpl,
  68. 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
  69. . 'Content-type: text/plain; charset=UTF-8' . "\n"
  70. . 'Content-transfer-encoding: 8bit' );
  71. if($res) {
  72. info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
  73. goaway(z_root());
  74. }
  75. else {
  76. notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL );
  77. }
  78. }
  79. elseif($a->config['register_policy'] == REGISTER_APPROVE) {
  80. if(! strlen($a->config['admin_email'])) {
  81. notice( t('Your registration can not be processed.') . EOL);
  82. goaway(z_root());
  83. }
  84. $hash = random_string();
  85. $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language` ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ",
  86. dbesc($hash),
  87. dbesc(datetime_convert()),
  88. intval($user['uid']),
  89. dbesc($result['password']),
  90. dbesc($lang)
  91. );
  92. $adminlist = explode(",", str_replace(" ", "", $a->config['admin_email']));
  93. $r = q("SELECT `language` FROM `user` WHERE `email` = '%s' LIMIT 1",
  94. //dbesc($a->config['admin_email'])
  95. dbesc($adminlist[0])
  96. );
  97. if(count($r))
  98. push_lang($r[0]['language']);
  99. else
  100. push_lang('en');
  101. if($using_invites && $invite_id) {
  102. q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
  103. set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
  104. }
  105. $email_tpl = get_intltext_template("register_verify_eml.tpl");
  106. $email_tpl = replace_macros($email_tpl, array(
  107. '$sitename' => $a->config['sitename'],
  108. '$siteurl' => $a->get_baseurl(),
  109. '$username' => $user['username'],
  110. '$email' => $user['email'],
  111. '$password' => $result['password'],
  112. '$uid' => $user['uid'],
  113. '$hash' => $hash
  114. ));
  115. $res = mail($a->config['admin_email'], email_header_encode( sprintf(t('Registration request at %s'), $a->config['sitename']),'UTF-8'),
  116. $email_tpl,
  117. 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
  118. . 'Content-type: text/plain; charset=UTF-8' . "\n"
  119. . 'Content-transfer-encoding: 8bit' );
  120. pop_lang();
  121. if($res) {
  122. info( t('Your registration is pending approval by the site owner.') . EOL ) ;
  123. goaway(z_root());
  124. }
  125. }
  126. return;
  127. }}
  128. if(! function_exists('register_content')) {
  129. function register_content(&$a) {
  130. // logged in users can register others (people/pages/groups)
  131. // even with closed registrations, unless specifically prohibited by site policy.
  132. // 'block_extended_register' blocks all registrations, period.
  133. $block = get_config('system','block_extended_register');
  134. if(local_user() && ($block)) {
  135. notice("Permission denied." . EOL);
  136. return;
  137. }
  138. if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
  139. notice("Permission denied." . EOL);
  140. return;
  141. }
  142. $max_dailies = intval(get_config('system','max_daily_registrations'));
  143. if($max_dailies) {
  144. $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
  145. if($r && $r[0]['total'] >= $max_dailies) {
  146. logger('max daily registrations exceeded.');
  147. notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
  148. return;
  149. }
  150. }
  151. if(x($_SESSION,'theme'))
  152. unset($_SESSION['theme']);
  153. if(x($_SESSION,'mobile-theme'))
  154. unset($_SESSION['mobile-theme']);
  155. $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
  156. $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
  157. $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
  158. $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
  159. $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
  160. $invite_id = ((x($_POST,'invite_id')) ? $_POST['invite_id'] : ((x($_GET,'invite_id')) ? $_GET['invite_id'] : ''));
  161. $noid = get_config('system','no_openid');
  162. if($noid) {
  163. $oidhtml = '';
  164. $fillwith = '';
  165. $fillext = '';
  166. $oidlabel = '';
  167. }
  168. else {
  169. $oidhtml = '<label for="register-openid" id="label-register-openid" >$oidlabel</label><input type="text" maxlength="60" size="32" name="openid_url" class="openid" id="register-openid" value="$openid" >';
  170. $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
  171. $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
  172. $oidlabel = t("Your OpenID \x28optional\x29: ");
  173. }
  174. // I set this and got even more fake names than before...
  175. $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
  176. if(get_config('system','publish_all')) {
  177. $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
  178. }
  179. else {
  180. $publish_tpl = get_markup_template("profile_publish.tpl");
  181. $profile_publish = replace_macros($publish_tpl,array(
  182. '$instance' => 'reg',
  183. '$pubdesc' => t('Include your profile in member directory?'),
  184. '$yes_selected' => ' checked="checked" ',
  185. '$no_selected' => '',
  186. '$str_yes' => t('Yes'),
  187. '$str_no' => t('No'),
  188. ));
  189. }
  190. $license = '';
  191. $o = get_markup_template("register.tpl");
  192. $arr = array('template' => $o);
  193. call_hooks('register_form',$arr);
  194. $o = $arr['template'];
  195. $o = replace_macros($o, array(
  196. '$oidhtml' => $oidhtml,
  197. '$invitations' => get_config('system','invitation_only'),
  198. '$invite_desc' => t('Membership on this site is by invitation only.'),
  199. '$invite_label' => t('Your invitation ID: '),
  200. '$invite_id' => $invite_id,
  201. '$realpeople' => $realpeople,
  202. '$regtitle' => t('Registration'),
  203. '$registertext' =>((x($a->config,'register_text'))
  204. ? '<div class="error-message">' . $a->config['register_text'] . '</div>'
  205. : "" ),
  206. '$fillwith' => $fillwith,
  207. '$fillext' => $fillext,
  208. '$oidlabel' => $oidlabel,
  209. '$openid' => $openid_url,
  210. '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith' . "\x29" . ': '),
  211. '$addrlabel' => t('Your Email Address: '),
  212. '$nickdesc' => str_replace('$sitename',$a->get_hostname(),t('Choose a profile nickname. This must begin with a text character. Your profile address on this site will then be \'<strong>nickname@$sitename</strong>\'.')),
  213. '$nicklabel' => t('Choose a nickname: '),
  214. '$photo' => $photo,
  215. '$publish' => $profile_publish,
  216. '$regbutt' => t('Register'),
  217. '$username' => $username,
  218. '$email' => $email,
  219. '$nickname' => $nickname,
  220. '$license' => $license,
  221. '$sitename' => $a->get_hostname(),
  222. '$importh' => t('Import'),
  223. '$importt' => t('Import your profile to this friendica instance'),
  224. ));
  225. return $o;
  226. }}