1686 */ |
1686 */ |
1687 |
1687 |
1688 function create_user($username, $password, $email, $real_name = '', $coppa = false) |
1688 function create_user($username, $password, $email, $real_name = '', $coppa = false) |
1689 { |
1689 { |
1690 global $db, $session, $paths, $template, $plugins; // Common objects |
1690 global $db, $session, $paths, $template, $plugins; // Common objects |
|
1691 global $lang; |
1691 |
1692 |
1692 // Initialize AES |
1693 // Initialize AES |
1693 $aes = AESCrypt::singleton(AES_BITS, AES_BLOCKSIZE); |
1694 $aes = AESCrypt::singleton(AES_BITS, AES_BLOCKSIZE); |
1694 |
1695 |
1695 // Since we're recording IP addresses, make sure the user's IP is safe. |
1696 // Since we're recording IP addresses, make sure the user's IP is safe. |
1696 $ip =& $_SERVER['REMOTE_ADDR']; |
1697 $ip =& $_SERVER['REMOTE_ADDR']; |
1697 if ( !is_valid_ip($ip) ) |
1698 if ( !is_valid_ip($ip) ) |
1698 return 'Invalid IP'; |
1699 return 'Invalid IP'; |
1699 |
1700 |
1700 if ( !preg_match('#^'.$this->valid_username.'$#', $username) ) |
1701 if ( !preg_match('#^'.$this->valid_username.'$#', $username) ) |
1701 return 'The username you chose contains invalid characters.'; |
1702 return $lang->get('user_reg_err_username_banned_chars'); |
1702 |
1703 |
1703 $username = str_replace('_', ' ', $username); |
1704 $username = str_replace('_', ' ', $username); |
1704 $user_orig = $username; |
1705 $user_orig = $username; |
1705 $username = $this->prepare_text($username); |
1706 $username = $this->prepare_text($username); |
1706 $email = $this->prepare_text($email); |
1707 $email = $this->prepare_text($email); |
1708 |
1709 |
1709 $nameclause = ( $real_name != '' ) ? ' OR real_name=\''.$real_name.'\'' : ''; |
1710 $nameclause = ( $real_name != '' ) ? ' OR real_name=\''.$real_name.'\'' : ''; |
1710 $q = $this->sql('SELECT * FROM '.table_prefix.'users WHERE ' . ENANO_SQLFUNC_LOWERCASE . '(username)=\''.strtolower($username).'\' OR email=\''.$email.'\''.$nameclause.';'); |
1711 $q = $this->sql('SELECT * FROM '.table_prefix.'users WHERE ' . ENANO_SQLFUNC_LOWERCASE . '(username)=\''.strtolower($username).'\' OR email=\''.$email.'\''.$nameclause.';'); |
1711 if($db->numrows() > 0) |
1712 if($db->numrows() > 0) |
1712 { |
1713 { |
1713 $r = 'The '; |
|
1714 $i=0; |
|
1715 $row = $db->fetchrow(); |
1714 $row = $db->fetchrow(); |
1716 // Wow! An error checker that actually speaks English with the properest grammar! :-P |
1715 $str = 'user_reg_err_dupe'; |
|
1716 |
1717 if ( $row['username'] == $username ) |
1717 if ( $row['username'] == $username ) |
1718 { |
1718 { |
1719 $r .= 'username'; |
1719 $str .= '_username'; |
1720 $i++; |
|
1721 } |
1720 } |
1722 if ( $row['email'] == $email ) |
1721 if ( $row['email'] == $email ) |
1723 { |
1722 { |
1724 if($i) $r.=', '; |
1723 $str .= '_email'; |
1725 $r .= 'e-mail address'; |
|
1726 $i++; |
|
1727 } |
1724 } |
1728 if ( $row['real_name'] == $real_name && $real_name != '' ) |
1725 if ( $row['real_name'] == $real_name && $real_name != '' ) |
1729 { |
1726 { |
1730 if($i) $r.=', and '; |
1727 $str .= '_realname'; |
1731 $r .= 'real name'; |
1728 } |
1732 $i++; |
1729 |
1733 } |
1730 return $lang->get($r); |
1734 $r .= ' that you entered '; |
|
1735 $r .= ( $i == 1 ) ? 'is' : 'are'; |
|
1736 $r .= ' already in use by another user.'; |
|
1737 return $r; |
|
1738 } |
1731 } |
1739 |
1732 |
1740 // Is the password strong enough? |
1733 // Is the password strong enough? |
1741 if ( getConfig('pw_strength_enable') ) |
1734 if ( getConfig('pw_strength_enable') ) |
1742 { |
1735 { |
1743 $min_score = intval( getConfig('pw_strength_minimum') ); |
1736 $min_score = intval( getConfig('pw_strength_minimum') ); |
1744 $pass_score = password_score($password); |
1737 $pass_score = password_score($password); |
1745 if ( $pass_score < $min_score ) |
1738 if ( $pass_score < $min_score ) |
1746 { |
1739 { |
1747 return 'The password you entered did not meet the complexity requirements for this site. Please choose a stronger password.'; |
1740 return $lang->get('user_reg_err_password_too_weak'); |
1748 } |
1741 } |
1749 } |
1742 } |
1750 |
1743 |
1751 $password = $aes->encrypt($password, $this->private_key, ENC_HEX); |
1744 $password = $aes->encrypt($password, $this->private_key, ENC_HEX); |
1752 |
1745 |
1855 */ |
1848 */ |
1856 |
1849 |
1857 function send_activation_mail($u, $actkey = false) |
1850 function send_activation_mail($u, $actkey = false) |
1858 { |
1851 { |
1859 global $db, $session, $paths, $template, $plugins; // Common objects |
1852 global $db, $session, $paths, $template, $plugins; // Common objects |
|
1853 global $lang; |
1860 $q = $this->sql('SELECT username,email FROM '.table_prefix.'users WHERE user_id=2 OR user_level=' . USER_LEVEL_ADMIN . ' ORDER BY user_id ASC;'); |
1854 $q = $this->sql('SELECT username,email FROM '.table_prefix.'users WHERE user_id=2 OR user_level=' . USER_LEVEL_ADMIN . ' ORDER BY user_id ASC;'); |
1861 $un = $db->fetchrow(); |
1855 $un = $db->fetchrow(); |
1862 $admin_user = $un['username']; |
1856 $admin_user = $un['username']; |
1863 $q = $this->sql('SELECT username,activation_key,account_active,email FROM '.table_prefix.'users WHERE username=\''.$db->escape($u).'\';'); |
1857 $q = $this->sql('SELECT username,activation_key,account_active,email FROM '.table_prefix.'users WHERE username=\''.$db->escape($u).'\';'); |
1864 $r = $db->fetchrow(); |
1858 $r = $db->fetchrow(); |
1865 if ( empty($r['email']) ) |
1859 if ( empty($r['email']) ) |
1866 $db->_die('BUG: $session->send_activation_mail(): no e-mail address in row'); |
1860 $db->_die('BUG: $session->send_activation_mail(): no e-mail address in row'); |
1867 $message = 'Dear '.$u.', |
1861 |
1868 Thank you for registering on '.getConfig('site_name').'. Your account creation is almost complete. To complete the registration process, please click the following link or paste it into your web browser: |
1862 $aklink = makeUrlComplete('Special', 'ActivateAccount/'.str_replace(' ', '_', $u).'/'. ( ( is_string($actkey) ) ? $actkey : $r['activation_key'] ) ); |
1869 |
1863 $message = $lang->get('user_reg_activation_email', array( |
1870 '; |
1864 'activation_link' => $aklink, |
1871 if(isset($_SERVER['HTTPS'])) $prot = 'https'; |
1865 'admin_user' => $admin_user, |
1872 else $prot = 'http'; |
1866 'username' => $u |
1873 if($_SERVER['SERVER_PORT'] == '80') $p = ''; |
1867 )); |
1874 else $p = ':'.$_SERVER['SERVER_PORT']; |
1868 |
1875 $sidbak = false; |
|
1876 if($this->sid_super) |
|
1877 $sidbak = $this->sid_super; |
|
1878 $this->sid_super = false; |
|
1879 $aklink = makeUrlNS('Special', 'ActivateAccount/'.str_replace(' ', '_', $u).'/'. ( ( is_string($actkey) ) ? $actkey : $r['activation_key'] ) ); |
|
1880 if($sidbak) |
|
1881 $this->sid_super = $sidbak; |
|
1882 unset($sidbak); |
|
1883 $message .= "$prot://".$_SERVER['HTTP_HOST'].$p.$aklink; |
|
1884 $message .= "\n\nSincerely yours, \n$admin_user and the ".$_SERVER['HTTP_HOST']." administration team"; |
|
1885 error_reporting(E_ALL); |
1869 error_reporting(E_ALL); |
1886 if(getConfig('smtp_enabled') == '1') |
1870 if(getConfig('smtp_enabled') == '1') |
1887 { |
1871 { |
1888 $result = smtp_send_email($r['email'], getConfig('site_name').' website account activation', preg_replace("#(?<!\r)\n#s", "\n", $message), getConfig('contact_email')); |
1872 $result = smtp_send_email($r['email'], $lang->get('user_reg_activation_email_subject'), preg_replace("#(?<!\r)\n#s", "\n", $message), getConfig('contact_email')); |
1889 if($result == 'success') $result = true; |
1873 if($result == 'success') $result = true; |
1890 else { echo $result; $result = false; } |
1874 else { echo $result; $result = false; } |
1891 } else { |
1875 } else { |
1892 $result = mail($r['email'], getConfig('site_name').' website account activation', preg_replace("#(?<!\r)\n#s", "\n", $message), 'From: '.getConfig('contact_email')); |
1876 $result = mail($r['email'], $lang->get('user_reg_activation_email_subject'), preg_replace("#(?<!\r)\n#s", "\n", $message), 'From: '.getConfig('contact_email')); |
1893 } |
1877 } |
1894 return $result; |
1878 return $result; |
1895 } |
1879 } |
1896 |
1880 |
1897 /** |
1881 /** |
1900 * @return bool true on success, false on failure |
1884 * @return bool true on success, false on failure |
1901 */ |
1885 */ |
1902 |
1886 |
1903 function send_coppa_mail($u, $actkey = false) |
1887 function send_coppa_mail($u, $actkey = false) |
1904 { |
1888 { |
1905 |
|
1906 global $db, $session, $paths, $template, $plugins; // Common objects |
1889 global $db, $session, $paths, $template, $plugins; // Common objects |
|
1890 global $lang; |
1907 |
1891 |
1908 $q = $this->sql('SELECT username,email FROM '.table_prefix.'users WHERE user_id=2 OR user_level=' . USER_LEVEL_ADMIN . ' ORDER BY user_id ASC;'); |
1892 $q = $this->sql('SELECT username,email FROM '.table_prefix.'users WHERE user_id=2 OR user_level=' . USER_LEVEL_ADMIN . ' ORDER BY user_id ASC;'); |
1909 $un = $db->fetchrow(); |
1893 $un = $db->fetchrow(); |
1910 $admin_user = $un['username']; |
1894 $admin_user = $un['username']; |
1911 |
1895 |
1925 if($sidbak) |
1909 if($sidbak) |
1926 $this->sid_super = $sidbak; |
1910 $this->sid_super = $sidbak; |
1927 unset($sidbak); |
1911 unset($sidbak); |
1928 $link = "$prot://".$_SERVER['HTTP_HOST'].scriptPath; |
1912 $link = "$prot://".$_SERVER['HTTP_HOST'].scriptPath; |
1929 |
1913 |
1930 $message = 'Dear parent or legal guardian, |
1914 $message = $lang->get( |
1931 A child under the username ' . $u . ' recently registered on our website. The child provided your e-mail address as the one of his or her authorized parent or legal guardian, and to comply with the United States Childrens\' Online Privacy Protection act, we ask that all parents of children ages 13 or under please mail us a written form authorizing their child\'s use of our website. |
1915 'user_reg_activation_email_coppa', |
1932 |
1916 array( |
1933 If you wish for your child to be allowed access to our website, please print and fill out the form below, and mail it to this address: |
1917 'username' => $u, |
1934 |
1918 'admin_user' => $admin_user, |
1935 ' . getConfig('coppa_address') . ' |
1919 'site_link' => $link |
1936 |
1920 ) |
1937 If you do NOT wish for your child to be allowed access to our site, you do not need to do anything - your child will not be able to access our site as a registered user unless you authorize their account activation. |
1921 ); |
1938 |
|
1939 Authorization form: |
|
1940 -------------------------------- Cut here -------------------------------- |
|
1941 |
|
1942 I, _______________________________________, the legal parent or guardian of the child registered on the website "' . getConfig('site_name') . '" as ' . $u . ', hereby give my authorization for the child\'s e-mail address, instant messaging information, location, and real name, to be collected and stored in a database owned and maintained by ' . getConfig('site_name') . ' at the child\'s option, and for the administrators of this website to use this information according to the privacy policy displayed on their website <' . $link . '>. |
|
1943 |
|
1944 Child\'s name: _____________________________________ |
|
1945 |
|
1946 Child\'s e-mail address: _____________________________________ |
|
1947 (optional - if you don\'t provide this, we\'ll just send site-related e-mails to your e-mail address) |
|
1948 |
|
1949 Signature of parent or guardian: |
|
1950 |
|
1951 ____________________________________________________ |
|
1952 |
|
1953 Date (YYYY-MM-DD): ______ / _____ / _____ |
|
1954 |
|
1955 -------------------------------- Cut here --------------------------------'; |
|
1956 $message .= "\n\nSincerely yours, \n$admin_user and the ".$_SERVER['HTTP_HOST']." administration team"; |
|
1957 |
1922 |
1958 error_reporting(E_ALL); |
1923 error_reporting(E_ALL); |
1959 |
1924 |
1960 if(getConfig('smtp_enabled') == '1') |
1925 if(getConfig('smtp_enabled') == '1') |
1961 { |
1926 { |