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.
 
 
 
 
 
 

283 lines
8.5 KiB

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