X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fuser.php;h=8528bfbfa50a72e3e556cc08379cc26df8bc1dfe;hb=30efb0c1e641b0b9d3aa40a5a79897c6d06ac3ef;hp=2477438bf4deab4a4e9806f7df50156ef9753c29;hpb=11974b4d948ae5d9b9fb53970838463bd88bb9f6;p=friendica.git diff --git a/include/user.php b/include/user.php index 2477438bf4..8528bfbfa5 100644 --- a/include/user.php +++ b/include/user.php @@ -7,6 +7,7 @@ require_once('include/text.php'); require_once('include/pgettext.php'); require_once('include/datetime.php'); + function create_user($arr) { // Required: { username, nickname, email } or { openid_url } @@ -30,7 +31,7 @@ function create_user($arr) { $publish = ((x($arr,'profile_publish_reg') && intval($arr['profile_publish_reg'])) ? 1 : 0); $netpublish = ((strlen(get_config('system','directory_submit_url'))) ? $publish : 0); - + $tmp_str = $openid_url; if($using_invites) { @@ -59,7 +60,13 @@ function create_user($arr) { $openid->returnUrl = $a->get_baseurl() . '/openid'; $openid->required = array('namePerson/friendly', 'contact/email', 'namePerson'); $openid->optional = array('namePerson/first','media/image/aspect11','media/image/default'); - goaway($openid->authUrl()); + try { + $authurl = $openid->authUrl(); + } catch (Exception $e){ + $result['message'] .= t("We encountered a problem while logging in with the OpenID you provided. Please check the correct spelling of the ID."). EOL . EOL . t("The error message was:") . $e->getMessage() . EOL; + return $result; + } + goaway($authurl); // NOTREACHED } @@ -89,7 +96,7 @@ function create_user($arr) { // $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'); if(! $loose_reg) { $username = mb_convert_case($username,MB_CASE_TITLE,'UTF-8'); @@ -99,7 +106,7 @@ function create_user($arr) { if(! allowed_email($email)) - $result['message'] .= t('Your email domain is not among those allowed on this site.') . EOL; + $result['message'] .= t('Your email domain is not among those allowed on this site.') . EOL; if((! valid_email($email)) || (! validate_email($email))) $result['message'] .= t('Not a valid email address.') . EOL; @@ -107,7 +114,10 @@ function create_user($arr) { // Disallow somebody creating an account using openid that uses the admin email address, // since openid bypasses email verification. We'll allow it if there is not yet an admin account. - if((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0) && strlen($openid_url)) { + $adminlist = explode(",", str_replace(" ", "", strtolower($a->config['admin_email']))); + + //if((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0) && strlen($openid_url)) { + if((x($a->config,'admin_email')) && in_array(strtolower($email), $adminlist) && strlen($openid_url)) { $r = q("SELECT * FROM `user` WHERE `email` = '%s' LIMIT 1", dbesc($email) ); @@ -147,13 +157,18 @@ function create_user($arr) { require_once('include/crypto.php'); - $keys = new_keypair(1024); + $keys = new_keypair(4096); if($keys === false) { $result['message'] .= t('SERIOUS ERROR: Generation of security keys failed.') . EOL; return $result; } + $default_service_class = get_config('system','default_service_class'); + if(! $default_service_class) + $default_service_class = ''; + + $prvkey = $keys['prvkey']; $pubkey = $keys['pubkey']; @@ -173,8 +188,8 @@ function create_user($arr) { $spubkey = $sres['pubkey']; $r = q("INSERT INTO `user` ( `guid`, `username`, `password`, `email`, `openid`, `nickname`, - `pubkey`, `prvkey`, `spubkey`, `sprvkey`, `register_date`, `verified`, `blocked`, `timezone` ) - VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, 'UTC' )", + `pubkey`, `prvkey`, `spubkey`, `sprvkey`, `register_date`, `verified`, `blocked`, `timezone`, `service_class` ) + VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, 'UTC', '%s' )", dbesc(generate_user_guid()), dbesc($username), dbesc($new_password_encoded), @@ -187,7 +202,8 @@ function create_user($arr) { dbesc($sprvkey), dbesc(datetime_convert()), intval($verified), - intval($blocked) + intval($blocked), + dbesc($default_service_class) ); if($r) { @@ -217,7 +233,7 @@ function create_user($arr) { ); if((count($r) > 1) && $newuid) { $result['message'] .= t('Nickname is already registered. Please choose another.') . EOL; - q("DELETE FROM `user` WHERE `uid` = %d LIMIT 1", + q("DELETE FROM `user` WHERE `uid` = %d", intval($newuid) ); return $result; @@ -271,6 +287,26 @@ 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'", + intval($newuid), + dbesc(t('Friends')) + ); + if($r && count($r)) { + $def_gid = $r[0]['id']; + + 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) + ); + } + } // if we have no OpenID photo try to look up an avatar