X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fuser.php;h=983c4a416b32429017ab47817dd8412ac4bdd20b;hb=66902c7956eedba02ea54aea6ea7aa417344ffbb;hp=f8b1578ceb188d0ed3050c3c581baf809c70fb88;hpb=26c82f210ed32139bd4a2fda58d511d275f720da;p=friendica.git diff --git a/include/user.php b/include/user.php index f8b1578ceb..983c4a416b 100644 --- a/include/user.php +++ b/include/user.php @@ -27,11 +27,19 @@ function create_user($arr) { $openid_url = ((x($arr,'openid_url')) ? notags(trim($arr['openid_url'])) : ''); $photo = ((x($arr,'photo')) ? notags(trim($arr['photo'])) : ''); $password = ((x($arr,'password')) ? trim($arr['password']) : ''); + $password1 = ((x($arr,'password1')) ? trim($arr['password1']) : ''); + $confirm = ((x($arr,'confirm')) ? trim($arr['confirm']) : ''); $blocked = ((x($arr,'blocked')) ? intval($arr['blocked']) : 0); $verified = ((x($arr,'verified')) ? intval($arr['verified']) : 0); $publish = ((x($arr,'profile_publish_reg') && intval($arr['profile_publish_reg'])) ? 1 : 0); - $netpublish = ((strlen(get_config('system','directory_submit_url'))) ? $publish : 0); + $netpublish = ((strlen(get_config('system','directory'))) ? $publish : 0); + + if ($password1 != $confirm) { + $result['message'] .= t('Passwords do not match. Password unchanged.') . EOL; + return $result; + } elseif ($password1 != "") + $password = $password1; $tmp_str = $openid_url; @@ -40,7 +48,7 @@ function create_user($arr) { $result['message'] .= t('An invitation is required.') . EOL; return $result; } - $r = q("select * from register where `hash` = '%s' limit 1", dbesc($invite_id)); + $r = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1", dbesc($invite_id)); if(! results($r)) { $result['message'] .= t('Invitation could not be verified.') . EOL; return $result; @@ -58,7 +66,7 @@ function create_user($arr) { require_once('library/openid.php'); $openid = new LightOpenID; $openid->identity = $openid_url; - $openid->returnUrl = $a->get_baseurl() . '/openid'; + $openid->returnUrl = z_root() . '/openid'; $openid->required = array('namePerson/friendly', 'contact/email', 'namePerson'); $openid->optional = array('namePerson/first','media/image/aspect11','media/image/default'); try { @@ -122,29 +130,30 @@ 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; } $nickname = $arr['nickname'] = strtolower($nickname); - if(! preg_match("/^[a-z][a-z0-9\-\_]*$/",$nickname)) - $result['message'] .= t('Your "nickname" can only contain "a-z", "0-9", "-", and "_", and must also begin with a letter.') . EOL; + 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'])) { @@ -207,13 +216,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']); } @@ -229,8 +238,8 @@ 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) { $result['message'] .= t('Nickname is already registered. Please choose another.') . EOL; @@ -247,8 +256,8 @@ 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(z_root() . "/photo/profile/{$newuid}.jpg"), + dbesc(z_root() . "/photo/avatar/{$newuid}.jpg"), intval($publish), intval($netpublish) @@ -260,27 +269,9 @@ function create_user($arr) { intval($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. @@ -288,23 +279,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) ); } @@ -367,6 +358,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(z_root()."/photo/profile/".$user['uid'].".jpg"), + dbesc(z_root()."/photo/avatar/".$user['uid'].".jpg"), + dbesc(z_root()."/photo/micro/".$user['uid'].".jpg"), + dbesc(z_root()."/profile/".$user['nickname']), + dbesc(normalise_link(z_root()."/profile/".$user['nickname'])), + dbesc($user['nickname'].'@'.substr(z_root(), strpos(z_root(),'://') + 3)), + dbesc(z_root()."/dfrn_request/".$user['nickname']), + dbesc(z_root()."/dfrn_notify/".$user['nickname']), + dbesc(z_root()."/dfrn_poll/".$user['nickname']), + dbesc(z_root()."/dfrn_confirm/".$user['nickname']), + dbesc(z_root()."/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.