| 1 | 2 | Manuela | <?php
 | 
      
        | 2 |  |  | /**
 | 
      
        | 3 |  |  |  *
 | 
      
        | 4 |  |  |  * @category        frontend
 | 
      
        | 5 |  |  |  * @package         account
 | 
      
        | 6 |  |  |  * @author          WebsiteBaker Project
 | 
      
        | 7 |  |  |  * @copyright       2004-2009, Ryan Djurovich
 | 
      
        | 8 |  |  |  * @copyright       2009-2011, Website Baker Org. e.V.
 | 
      
        | 9 |  |  |  * @link            http://www.websitebaker2.org/
 | 
      
        | 10 |  |  |  * @license         http://www.gnu.org/licenses/gpl.html
 | 
      
        | 11 |  |  |  * @platform        WebsiteBaker 2.8.3
 | 
      
        | 12 |  |  |  * @requirements    PHP 5.3.6 and higher
 | 
      
        | 13 |  |  |  * @version         $Id$
 | 
      
        | 14 |  |  |  * @filesource      $HeadURL$
 | 
      
        | 15 |  |  |  * @lastmodified    $Date$
 | 
      
        | 16 |  |  |  *
 | 
      
        | 17 |  |  |  */
 | 
      
        | 18 |  |  | // Must include code to stop this file being access directly
 | 
      
        | 19 |  |  | if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
 | 
      
        | 20 |  |  | 
 | 
      
        | 21 |  |  | // Create new frontend object
 | 
      
        | 22 |  |  | if (!isset($wb) || !($wb instanceof frontend)) {
 | 
      
        | 23 |  |  |     if( !class_exists('wb', false) ){ require(WB_PATH."/framework/class.wb.php"); }
 | 
      
        | 24 |  |  |     $wb = new frontend();
 | 
      
        | 25 |  |  | }
 | 
      
        | 26 |  |  | 
 | 
      
        | 27 |  |  | /*
 | 
      
        | 28 |  |  | if (!$wb->checkFTAN())
 | 
      
        | 29 |  |  | {
 | 
      
        | 30 |  |  |     $sInfo = strtoupper(basename(__DIR__).'_'.basename(__FILE__, '.'.PAGE_EXTENSION)).'::';
 | 
      
        | 31 |  |  |     $sDEBUG=(@DEBUG?$sInfo:'');
 | 
      
        | 32 |  |  |     $error[] =  $sDEBUG.$MESSAGE['GENERIC_SECURITY_ACCESS']."\n";
 | 
      
        | 33 |  |  |     return;
 | 
      
        | 34 |  |  | }
 | 
      
        | 35 |  |  | */
 | 
      
        | 36 |  |  | 
 | 
      
        | 37 |  |  | // Get details entered
 | 
      
        | 38 |  |  | $groups_id = FRONTEND_SIGNUP;
 | 
      
        | 39 |  |  | $active = 1;
 | 
      
        | 40 |  |  | $username = strtolower(strip_tags($wb->get_post('username')));
 | 
      
        | 41 |  |  | $display_name = strip_tags($wb->get_post('display_name'));
 | 
      
        | 42 |  |  | $email = $wb->get_post('email');
 | 
      
        | 43 |  |  | /*
 | 
      
        | 44 |  |  | // Check values
 | 
      
        | 45 |  |  | if($groups_id == "") {
 | 
      
        | 46 |  |  |     $wb->print_error($MESSAGE['USERS_NO_GROUP'], $js_back, false);
 | 
      
        | 47 |  |  | }
 | 
      
        | 48 |  |  | */
 | 
      
        | 49 |  |  | 
 | 
      
        | 50 |  |  | // Check if username already exists
 | 
      
        | 51 |  |  | $sql = 'SELECT `user_id` FROM `'.TABLE_PREFIX.'users` '
 | 
      
        | 52 |  |  |      . 'WHERE `username` = \''.$database->escapeString($username).'\'';
 | 
      
        | 53 |  |  | if ($database->get_one($sql)) {
 | 
      
        | 54 |  |  |     $error[] = $MESSAGE['USERS_USERNAME_TAKEN']."\n";
 | 
      
        | 55 |  |  | }
 | 
      
        | 56 |  |  | if(!preg_match('/^[a-z]{1}[a-z0-9_-]{2,}$/i', $username)) {
 | 
      
        | 57 |  |  |     $error[] =  $MESSAGE['USERS_NAME_INVALID_CHARS']."\n";
 | 
      
        | 58 |  |  | }
 | 
      
        | 59 |  |  | $sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'users` '
 | 
      
        | 60 |  |  |      . 'WHERE  `display_name` LIKE \''.$database->escapeString(addcslashes($display_name, '_%')).'\'';
 | 
      
        | 61 |  |  | if ($database->get_one($sql) > 0) {
 | 
      
        | 62 |  |  |     $error[] = $MESSAGE['USERS_DISPLAYNAME_TAKEN'].'';
 | 
      
        | 63 |  |  | }
 | 
      
        | 64 |  |  | if($email != "") {
 | 
      
        | 65 |  |  |     if($wb->validate_email($email) == false) {
 | 
      
        | 66 |  |  |         $error[] = $MESSAGE['USERS_INVALID_EMAIL']."\n";
 | 
      
        | 67 |  |  |     }
 | 
      
        | 68 |  |  | } else {
 | 
      
        | 69 |  |  |     $error[] = $MESSAGE['SIGNUP_NO_EMAIL']."\n";
 | 
      
        | 70 |  |  | }
 | 
      
        | 71 |  |  | 
 | 
      
        | 72 |  |  | $search = array('{SERVER_EMAIL}');
 | 
      
        | 73 |  |  | $replace = array( SERVER_EMAIL);
 | 
      
        | 74 |  |  | // Captcha
 | 
      
        | 75 |  |  | if(ENABLED_CAPTCHA) {
 | 
      
        | 76 |  |  |     $MESSAGE['MOD_FORM_INCORRECT_CAPTCHA'] = str_replace($search,$replace,$MESSAGE['MOD_FORM_INCORRECT_CAPTCHA']);
 | 
      
        | 77 |  |  |     if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
 | 
      
        | 78 |  |  |         // Check for a mismatch
 | 
      
        | 79 |  |  |         if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
 | 
      
        | 80 |  |  |             $error[] = $MESSAGE['MOD_FORM_INCORRECT_CAPTCHA']."\n";
 | 
      
        | 81 |  |  |         }
 | 
      
        | 82 |  |  |     } else {
 | 
      
        | 83 |  |  |         $error[] = $MESSAGE['MOD_FORM_INCORRECT_CAPTCHA']."\n";
 | 
      
        | 84 |  |  |     }
 | 
      
        | 85 |  |  | }
 | 
      
        | 86 |  |  | if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
 | 
      
        | 87 |  |  | 
 | 
      
        | 88 |  |  | // Generate a random password then update the database with it
 | 
      
        | 89 |  |  | $new_pass = '';
 | 
      
        | 90 |  |  | $salt = "abchefghjkmnpqrstuvwxyz0123456789";
 | 
      
        | 91 |  |  | srand((double)microtime()*1000000);
 | 
      
        | 92 |  |  | $i = 0;
 | 
      
        | 93 |  |  | while ($i <= 7) {
 | 
      
        | 94 |  |  |     $num = rand() % 33;
 | 
      
        | 95 |  |  |     $tmp = substr($salt, $num, 1);
 | 
      
        | 96 |  |  |     $new_pass = $new_pass . $tmp;
 | 
      
        | 97 |  |  |     $i++;
 | 
      
        | 98 |  |  | }
 | 
      
        | 99 |  |  | $md5_password = md5($new_pass);
 | 
      
        | 100 |  |  | // Check if the email already exists
 | 
      
        | 101 |  |  | $sql = 'SELECT `user_id` FROM `'.TABLE_PREFIX.'users` '
 | 
      
        | 102 |  |  |      . 'WHERE `email` = \''.$database->escapeString($email).'\'';
 | 
      
        | 103 |  |  | if ($database->get_one($sql)) {
 | 
      
        | 104 |  |  |     if(isset($MESSAGE['USERS_EMAIL_TAKEN'])) {
 | 
      
        | 105 |  |  |         $error[] = $MESSAGE['USERS_EMAIL_TAKEN']."\n";
 | 
      
        | 106 |  |  |     } else {
 | 
      
        | 107 |  |  |         $error[] = $MESSAGE['USERS_INVALID_EMAIL']."\n";
 | 
      
        | 108 |  |  |     }
 | 
      
        | 109 |  |  | }
 | 
      
        | 110 |  |  | 
 | 
      
        | 111 |  |  | if(sizeof($error)==0){
 | 
      
        | 112 |  |  |     // MD5 supplied password
 | 
      
        | 113 |  |  |     $md5_password = md5($new_pass);
 | 
      
        | 114 |  |  |     // Insert the user into the database
 | 
      
        | 115 |  |  |     $sql  = 'INSERT INTO `'.TABLE_PREFIX.'users` SET '
 | 
      
        | 116 |  |  |           . '`group_id` = '.$database->escapeString($groups_id).', '
 | 
      
        | 117 |  |  |           . '`groups_id` = \''.$database->escapeString($groups_id).'\', '
 | 
      
        | 118 |  |  |           . '`active` = '.$database->escapeString($active).', '
 | 
      
        | 119 |  |  |           . '`username` = \''.$database->escapeString($username).'\', '
 | 
      
        | 120 |  |  |           . '`password` = \''.$database->escapeString($md5_password).'\', '
 | 
      
        | 121 |  |  |           . '`display_name` = \''.$database->escapeString($display_name).'\', '
 | 
      
        | 122 |  |  |           . '`home_folder` = \'\', '
 | 
      
        | 123 |  |  |           . '`email` = \''.$database->escapeString($email).'\', '
 | 
      
        | 124 |  |  |           . '`timezone` = \''.$database->escapeString(DEFAULT_TIMEZONE).'\', '
 | 
      
        | 125 |  |  |           . '`language` = \''.$database->escapeString(DEFAULT_LANGUAGE).'\''
 | 
      
        | 126 |  |  |           .'';
 | 
      
        | 127 |  |  |     $database->query($sql);
 | 
      
        | 128 |  |  |     if($database->is_error()) {
 | 
      
        | 129 |  |  |         // Error updating database
 | 
      
        | 130 |  |  |         $message = $database->get_error();
 | 
      
        | 131 |  |  |     } else {
 | 
      
        | 132 |  |  |         // Setup email to send
 | 
      
        | 133 |  |  |         $mail_to = $email;
 | 
      
        | 134 |  |  |         $mail_subject = $MESSAGE['SIGNUP2_SUBJECT_LOGIN_INFO'];
 | 
      
        | 135 |  |  | 
 | 
      
        | 136 |  |  |         // Replace placeholders from language variable with values
 | 
      
        | 137 |  |  |         $search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
 | 
      
        | 138 |  |  |         $replace = array($display_name, WEBSITE_TITLE, $username, $new_pass);
 | 
      
        | 139 |  |  |         $mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2_BODY_LOGIN_INFO']);
 | 
      
        | 140 |  |  | 
 | 
      
        | 141 |  |  |         // Try sending the email
 | 
      
        | 142 |  |  |         if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
 | 
      
        | 143 |  |  |             $display_form = false;
 | 
      
        | 144 |  |  |             $success[] = $MESSAGE['FORGOT_PASS_PASSWORD_RESET'];
 | 
      
        | 145 |  |  |         } else {
 | 
      
        | 146 |  |  |             $sql = 'DELETE FROM `'.TABLE_PREFIX.'users` '
 | 
      
        | 147 |  |  |                  . 'WHERE `username` = \''.$database->escapeString($username).'\'';
 | 
      
        | 148 |  |  |             $database->query($sql);
 | 
      
        | 149 |  |  |             $error[] = $MESSAGE['FORGOT_PASS_CANNOT_EMAIL']."\n";
 | 
      
        | 150 |  |  |         }
 | 
      
        | 151 |  |  |     }
 | 
      
        | 152 |  |  | }
 |