X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fuser.php;h=a05bd831a8e7d81aa19344d3853846acc363ee36;hb=9f2196aa1aa0dc112e3fc238832828d4e22fe137;hp=33ff46ee643b3a25bd8ab5707fccf40bf6a11f90;hpb=2356d6a9aed4dda8995114a218eb4035ad9f05ae;p=friendica.git diff --git a/include/user.php b/include/user.php index 33ff46ee64..a05bd831a8 100644 --- a/include/user.php +++ b/include/user.php @@ -1,5 +1,7 @@ identity = $openid_url; - $openid->returnUrl = $a->get_baseurl() . '/openid'; + $openid->returnUrl = System::baseUrl() . '/openid'; $openid->required = array('namePerson/friendly', 'contact/email', 'namePerson'); $openid->optional = array('namePerson/first','media/image/aspect11','media/image/default'); try { @@ -97,13 +99,6 @@ function create_user($arr) { if(mb_strlen($username) < 3) $result['message'] .= t('Name too short.') . EOL; - // I don't really like having this rule, but it cuts down - // on the number of auto-registrations by Russian spammers - - // Using preg_match was completely unreliable, due to mixed UTF-8 regex support - // $no_utf = get_config('system','no_utf'); - // $pat = (($no_utf) ? '/^[a-zA-Z]* [a-zA-Z]*$/' : '/^\p{L}* \p{L}*$/u' ); - // So now we are just looking for a space in the full name. $loose_reg = get_config('system','no_regfullname'); @@ -130,7 +125,7 @@ function create_user($arr) { $r = q("SELECT * FROM `user` WHERE `email` = '%s' LIMIT 1", dbesc($email) ); - if(count($r)) + if (dbm::is_result($r)) $result['message'] .= t('Cannot use that email.') . EOL; } @@ -138,21 +133,22 @@ function create_user($arr) { if(! preg_match("/^[a-z0-9][a-z0-9\_]*$/",$nickname)) $result['message'] .= t('Your "nickname" can only contain "a-z", "0-9" and "_".') . EOL; + $r = q("SELECT `uid` FROM `user` - WHERE `nickname` = '%s' LIMIT 1", - dbesc($nickname) + WHERE `nickname` = '%s' LIMIT 1", + dbesc($nickname) ); - if(count($r)) + if (dbm::is_result($r)) $result['message'] .= t('Nickname is already registered. Please choose another.') . EOL; // Check deleted accounts that had this nickname. Doesn't matter to us, // but could be a security issue for federated platforms. $r = q("SELECT * FROM `userd` - WHERE `username` = '%s' LIMIT 1", - dbesc($nickname) + WHERE `username` = '%s' LIMIT 1", + dbesc($nickname) ); - if(count($r)) + if (dbm::is_result($r)) $result['message'] .= t('Nickname was once registered here and may not be re-used. Please choose another.') . EOL; if(strlen($result['message'])) { @@ -181,17 +177,7 @@ function create_user($arr) { $prvkey = $keys['prvkey']; $pubkey = $keys['pubkey']; - /** - * - * Create another keypair for signing/verifying - * salmon protocol messages. We have to use a slightly - * less robust key because this won't be using openssl - * but the phpseclib. Since it is PHP interpreted code - * it is not nearly as efficient, and the larger keys - * will take several minutes each to process. - * - */ - + // Create another keypair for signing/verifying salmon protocol messages. $sres = new_keypair(512); $sprvkey = $sres['prvkey']; $spubkey = $sres['pubkey']; @@ -215,13 +201,13 @@ function create_user($arr) { dbesc($default_service_class) ); - if($r) { + if ($r) { $r = q("SELECT * FROM `user` WHERE `username` = '%s' AND `password` = '%s' LIMIT 1", dbesc($username), dbesc($new_password_encoded) ); - if($r !== false && count($r)) { + if (dbm::is_result($r)) { $u = $r[0]; $newuid = intval($r[0]['uid']); } @@ -237,14 +223,12 @@ function create_user($arr) { */ $r = q("SELECT `uid` FROM `user` - WHERE `nickname` = '%s' ", - dbesc($nickname) + WHERE `nickname` = '%s' ", + dbesc($nickname) ); - if((count($r) > 1) && $newuid) { + if ((dbm::is_result($r)) && (count($r) > 1) && $newuid) { $result['message'] .= t('Nickname is already registered. Please choose another.') . EOL; - q("DELETE FROM `user` WHERE `uid` = %d", - intval($newuid) - ); + dba::delete('user', array('uid' => $newuid)); return $result; } @@ -255,40 +239,21 @@ function create_user($arr) { t('default'), 1, dbesc($username), - dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"), - dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg"), + dbesc(System::baseUrl() . "/photo/profile/{$newuid}.jpg"), + dbesc(System::baseUrl() . "/photo/avatar/{$newuid}.jpg"), intval($publish), intval($netpublish) ); - if($r === false) { + if ($r === false) { $result['message'] .= t('An error occurred creating your default profile. Please try again.') . EOL; // Start fresh next time. - $r = q("DELETE FROM `user` WHERE `uid` = %d", - intval($newuid)); + dba::delete('user', array('uid' => $newuid)); return $result; } - $r = q("INSERT INTO `contact` ( `uid`, `created`, `self`, `name`, `nick`, `photo`, `thumb`, `micro`, `blocked`, `pending`, `url`, `nurl`, - `request`, `notify`, `poll`, `confirm`, `poco`, `name-date`, `uri-date`, `avatar-date`, `closeness` ) - VALUES ( %d, '%s', 1, '%s', '%s', '%s', '%s', '%s', 0, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', 0 ) ", - intval($newuid), - datetime_convert(), - dbesc($username), - dbesc($nickname), - dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"), - dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg"), - dbesc($a->get_baseurl() . "/photo/micro/{$newuid}.jpg"), - dbesc($a->get_baseurl() . "/profile/$nickname"), - dbesc(normalise_link($a->get_baseurl() . "/profile/$nickname")), - dbesc($a->get_baseurl() . "/dfrn_request/$nickname"), - dbesc($a->get_baseurl() . "/dfrn_notify/$nickname"), - dbesc($a->get_baseurl() . "/dfrn_poll/$nickname"), - dbesc($a->get_baseurl() . "/dfrn_confirm/$nickname"), - dbesc($a->get_baseurl() . "/poco/$nickname"), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc(datetime_convert()) - ); + + // Create the self contact + user_create_self_contact($newuid); // Create a group with no members. This allows somebody to use it // right away as a default group for new contacts. @@ -296,23 +261,23 @@ function create_user($arr) { require_once('include/group.php'); group_add($newuid, t('Friends')); - $r = q("SELECT id FROM `group` WHERE uid = %d AND name = '%s'", + $r = q("SELECT `id` FROM `group` WHERE `uid` = %d AND `name` = '%s'", intval($newuid), dbesc(t('Friends')) ); - if($r && count($r)) { + if (dbm::is_result($r)) { $def_gid = $r[0]['id']; - q("UPDATE user SET def_gid = %d WHERE uid = %d", + q("UPDATE `user` SET `def_gid` = %d WHERE `uid` = %d", intval($r[0]['id']), intval($newuid) ); } if(get_config('system', 'newuser_private') && $def_gid) { - q("UPDATE user SET allow_gid = '%s' WHERE uid = %d", - dbesc("<" . $def_gid . ">"), - intval($newuid) + q("UPDATE `user` SET `allow_gid` = '%s' WHERE `uid` = %d", + dbesc("<" . $def_gid . ">"), + intval($newuid) ); } @@ -342,24 +307,27 @@ function create_user($arr) { $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 4 ); - if($r === false) + if ($r === false) { $photo_failure = true; + } $img->scaleImage(80); $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 5 ); - if($r === false) + if ($r === false) { $photo_failure = true; + } $img->scaleImage(48); $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 6 ); - if($r === false) + if ($r === false) { $photo_failure = true; + } - if(! $photo_failure) { + if (! $photo_failure) { q("UPDATE `photo` SET `profile` = 1 WHERE `resource-id` = '%s' ", dbesc($hash) ); @@ -375,6 +343,72 @@ function create_user($arr) { } +/** + * @brief create the "self" contact from data from the user table + * + * @param integer $uid + */ +function user_create_self_contact($uid) { + + // Only create the entry if it doesn't exist yet + $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($uid)); + if (dbm::is_result($r)) { + return; + } + + $r = q("SELECT `uid`, `username`, `nickname` FROM `user` WHERE `uid` = %d", intval($uid)); + if (!dbm::is_result($r)) { + return; + } + + $user = $r[0]; + + q("INSERT INTO `contact` (`uid`, `created`, `self`, `name`, `nick`, `photo`, `thumb`, `micro`, `blocked`, `pending`, `url`, `nurl`, + `addr`, `request`, `notify`, `poll`, `confirm`, `poco`, `name-date`, `uri-date`, `avatar-date`, `closeness`) + VALUES (%d, '%s', 1, '%s', '%s', '%s', '%s', '%s', 0, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', 0)", + intval($user['uid']), + datetime_convert(), + dbesc($user['username']), + dbesc($user['nickname']), + dbesc(System::baseUrl()."/photo/profile/".$user['uid'].".jpg"), + dbesc(System::baseUrl()."/photo/avatar/".$user['uid'].".jpg"), + dbesc(System::baseUrl()."/photo/micro/".$user['uid'].".jpg"), + dbesc(System::baseUrl()."/profile/".$user['nickname']), + dbesc(normalise_link(System::baseUrl()."/profile/".$user['nickname'])), + dbesc($user['nickname'].'@'.substr(System::baseUrl(), strpos(System::baseUrl(),'://') + 3)), + dbesc(System::baseUrl()."/dfrn_request/".$user['nickname']), + dbesc(System::baseUrl()."/dfrn_notify/".$user['nickname']), + dbesc(System::baseUrl()."/dfrn_poll/".$user['nickname']), + dbesc(System::baseUrl()."/dfrn_confirm/".$user['nickname']), + dbesc(System::baseUrl()."/poco/".$user['nickname']), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc(datetime_convert()) + ); +} + +/** + * @brief send registration confiŕmation with the intormation that reg is pending + * + * @param string $email + * @param string $sitename + * @param string $username + * @return NULL|boolean from notification() and email() inherited + */ +function send_register_pending_eml($email, $sitename, $username) { + $body = deindent(t(' + Dear %1$s, + Thank you for registering at %2$s. Your account is pending for approval by the administrator. + ')); + + $body = sprintf($body, $username, $sitename); + + return notification(array( + 'type' => SYSTEM_EMAIL, + 'to_email' => $email, + 'subject'=> sprintf( t('Registration at %s'), $sitename), + 'body' => $body)); +} /* * send registration confirmation. @@ -416,7 +450,7 @@ function send_register_open_eml($email, $sitename, $siteurl, $username, $passwor $body = sprintf($body, $email, $sitename, $siteurl, $username, $password); return notification(array( - 'type' => "SYSTEM_EMAIL", + 'type' => SYSTEM_EMAIL, 'to_email' => $email, 'subject'=> sprintf( t('Registration details for %s'), $sitename), 'preamble'=> $preamble,