function create_account($dirty_email)
{
    $email = escape($dirty_email);
    if (user_count($email) != 0) {
        echo "signup-failure";
        return;
    }
    if (validate_email($email) == false) {
        echo "signup-failure";
        return;
    }
    $pending_verification = "pending-verification";
    $sql1 = "INSERT INTO account_head (account, email, status)";
    $sql1 .= " VALUES (null, '{$email}', '{$pending_verification}');";
    query($sql1);
    if (user_count($email) == 1) {
        $new_account_num = account_id_from_email($email);
        $time = time();
        $signupString = generate_string();
        $sql2 = "INSERT INTO account_signup (account, code, date_requested)";
        $sql2 .= " VALUES ({$new_account_num}, '{$signupString}', {$time});";
        query($sql2);
        $sql3 = "SELECT * FROM account_signup WHERE account={$new_account_num}";
        $result = query($sql3);
        $count = mysqli_num_rows($result);
        //mail($email,"ProjectPortfolio - Complete signup", "This is the msg telling you to sign up, fart.");
        send_signup_email($email, $signupString);
        if ($count == 1) {
            echo "signup-success";
            return;
        } else {
            $sql4 = "DELETE FROM account_signup WHERE account={$new_account_num}";
            $sql5 = "DELETE FROM account_head WHERE account={$new_account_num}";
            query($sql4);
            query($sql5);
        }
    } else {
        echo "deleting head table failed";
        $sql6 = "DELETE FROM account_head WHERE email={$email}";
        query($sql6);
    }
    echo "signup-failure";
}
Esempio n. 2
0
function generate_token($username, $deep = 0)
{
    global $db;
    $deep++;
    if ($deep > 3) {
        return false;
    }
    $token_string = generate_string(64);
    // 检测有效性
    $token = $db->get('token', array('token', 'username', 'expired_time'), array('AND' => array('token' => $token_string, 'expired_time[>]' => time())));
    if ($token) {
        return generate_token($username, $deep);
    } else {
        $result = $db->insert('token', array('token' => $token_string, 'username' => $username, 'expired_time' => time() + 3600 * 2));
        $active = $db->insert('active', array('content' => "登录创建 token:{$token_string} 经过 {$deep} 次", 'username' => $username, 'time' => date('Y-m-d H:i:s', time())));
        return $token_string;
    }
}
Esempio n. 3
0
 public function token($token_password)
 {
     if ($this->session->userdata('logged_user')) {
         redirect(base_url() . 'home');
     }
     $query = $this->db->query('SELECT mbr.* FROM ' . $this->db->dbprefix('members') . ' AS mbr WHERE mbr.token_password = ? GROUP BY mbr.mbr_id', array($token_password));
     if ($query->num_rows() > 0) {
         $member = $query->row();
         $mbr_password = generate_string(6);
         $this->db->set('mbr_password', $this->readerself_library->set_salt_password($mbr_password));
         $this->db->set('token_password', '');
         $this->db->where('mbr_id', $member->mbr_id);
         $this->db->update('members');
         $data = array();
         $data['mbr_password'] = $mbr_password;
         $content = $this->load->view('password_token', $data, TRUE);
         $this->readerself_library->set_content($content);
     } else {
         redirect(base_url());
     }
 }
Esempio n. 4
0
 function do_login($login_options, $template)
 {
     global $_CLASS, $_CORE_CONFIG;
     $error = '';
     $login_array = array('redirect' => false, 'explain' => false, 'success' => '', 'admin_login' => false, 'full_login' => true, 'full_screen' => false);
     if (is_array($login_options)) {
         $login_array = array_merge($login_array, $login_options);
     }
     if (isset($_POST['login'])) {
         $user_name = get_variable('username', 'POST');
         $user_password = get_variable('password', 'POST');
         if (!$user_name || !$user_password) {
             $error = 'INCOMPLETE_LOGIN_INFO';
         }
         if (!$error && $_CORE_CONFIG['user']['enable_confirm']) {
             $code = $_CLASS['core_user']->session_data_get('confirmation_code');
             $confirm_code = get_variable('confirm_code', 'POST', false);
             if (!$code || !$confirm_code || $code !== $confirm_code) {
                 //	$error = 'CONFIRM_CODE_WRONG';
             }
         }
         if (!$error) {
             $result = $this->user_auth($user_name, $user_password);
             if (is_numeric($result)) {
                 $_CLASS['core_user']->login($result, $login_array['admin_login'], !empty($_POST['hidden']), !empty($_POST['auto_login']));
                 $login_array['redirect'] = generate_link(get_variable('redirect', 'POST', $login_array['redirect']), array('admin' => $login_array['admin_login']));
                 $_CLASS['core_display']->meta_refresh(5, $login_array['redirect']);
                 $message = ($login_array['success'] ? $_CLASS['core_user']->get_lang($login_array['success']) : $_CLASS['core_user']->lang['LOGIN_REDIRECT']) . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_PAGE'], '<a href="' . $login_array['redirect'] . '">', '</a> ');
                 trigger_error($message);
             }
             $error = is_string($result) ? $result : 'LOGIN_ERROR';
         }
     }
     if (!$login_array['redirect']) {
         $login_array['redirect'] = htmlspecialchars($_CLASS['core_user']->url);
     }
     $s_hidden_fields = '<input type="hidden" name="redirect" value="' . $login_array['redirect'] . '" />';
     if ($_CORE_CONFIG['user']['enable_confirm']) {
         $confirm_image = '<img src="' . generate_link('system&amp;mode=confirmation_image') . '" alt="" title="" />';
         $_CLASS['core_user']->session_data_set('confirmation_code', generate_string(6));
     } else {
         $confirm_image = false;
     }
     $_CLASS['core_template']->assign_array(array('LOGIN_ERROR' => $_CLASS['core_user']->get_lang($error), 'LOGIN_EXPLAIN' => $_CLASS['core_user']->get_lang($login_array['explain']), 'U_SEND_PASSWORD' => $_CORE_CONFIG['email']['email_enable'] ? generate_link('Control_Panel&amp;mode=sendpassword') : '', 'U_RESEND_ACTIVATION' => $_CORE_CONFIG['user']['activation'] != USER_ACTIVATION_NONE && $_CORE_CONFIG['email']['email_enable'] ? generate_link('Control_Panel&amp;mode=resend_act') : '', 'U_TERMS_USE' => generate_link('Control_Panel&amp;mode=terms'), 'U_PRIVACY' => generate_link('Control_Panel&amp;mode=privacy'), 'U_REGISTER' => generate_link('Control_Panel&amp;mode=register'), 'U_CONFIRM_IMAGE' => $confirm_image, 'USERNAME' => isset($data['user_name']) ? $data['user_name'] : '', 'S_DISPLAY_FULL_LOGIN' => $login_array['full_login'], 'S_LOGIN_ACTION' => !$login_array['admin_login'] ? generate_link($_CLASS['core_user']->url) : generate_link(false, array('admin' => true)), 'S_HIDDEN_FIELDS' => $s_hidden_fields));
     if (!$template && $login_array['full_screen']) {
         $template = 'login_body_full.html';
     }
     $_CLASS['core_template']->display($template ? $template : 'login_body.html');
     script_close();
 }
function display_confirmation($message = '', $hidden = '', $template = false, $image = false)
{
    global $_CLASS;
    // Add user entered confirmation code as a choose, maybe ...
    if (isset($_POST['cancel'])) {
        return false;
    }
    if (isset($_POST['confirm'])) {
        $code = $_CLASS['core_user']->session_data_get('confirmation_code');
        $confirm_code = get_variable('confirm_code', 'POST', false);
        if ($code && $confirm_code && $code === $confirm_code) {
            return true;
        }
        return false;
    }
    $confirmation_code = generate_string(6);
    if (is_array($hidden)) {
        $hidden = generate_hidden_fields($hidden);
    }
    if ($image) {
        $confirm_image = '<img src="' . generate_link('system&amp;mode=confirmation_image') . '" alt="" title="" />';
    } else {
        $confirm_image = false;
        $hidden .= '<input type="hidden" name="confirm_code" value="' . $confirmation_code . '" />';
    }
    $_CLASS['core_user']->session_data_set('confirmation_code', $confirmation_code);
    $_CLASS['core_template']->assign_array(array('MESSAGE' => $message ? $message : 'Are you sure you want to perform this action ?', 'CONFIRM_ACTION' => $_CLASS['core_user']->url ? generate_link($_CLASS['core_user']->url) : '', 'CONFIRM_IMAGE' => $confirm_image, 'HIDDEN_FIELDS' => $hidden));
    $_CLASS['core_template']->display($template ? $template : 'confirmation.html');
    script_close(false);
}
Esempio n. 6
0
    } else {
        if (!empty($id_email)) {
            $sql .= " WHERE email='{$id_email}' ";
        }
    }
    if (!($result = mysql_query($sql))) {
        showerror();
    }
    if (mysql_num_rows($result) !== 1) {
        message($ttf_label, $ttf_msg["fatal_error"], $ttf_msg["nomatchuser"]);
        die;
    }
    list($user_id, $username, $email) = mysql_fetch_array($result);
    // now that we have a matching user, do things!
    $password = generate_string(16);
    $passkey = generate_string(32);
    $sql = "INSERT INTO ttf_recover             " . "SET date=UNIX_TIMESTAMP(),          " . "    ip='{$_SERVER["REMOTE_ADDR"]}', " . "    user_id='{$user_id}',             " . "    password=SHA1('{$password}'),     " . "    passkey='{$passkey}'              ";
    if (!($result = mysql_query($sql))) {
        showerror();
    }
    $subject = "{$ttf_cfg["forum_name"]} account recovery information";
    $message = <<<EOF
hello,

here is your account recovery information for {$ttf_cfg["forum_name"]}:

username: {$username}
password: {$password}
passkey: {$passkey}

to begin using this new password, you'll need to activate it using the passkey.
 function ucp_register($id, $mode)
 {
     global $site_file_root, $config, $_CLASS, $_CORE_CONFIG;
     $coppa = isset($_REQUEST['coppa']) ? (int) $_REQUEST['coppa'] : null;
     $submit = isset($_POST['submit']);
     if ($_CORE_CONFIG['user']['activation'] == USER_ACTIVATION_DISABLE || ($coppa || $_CORE_CONFIG['user']['activation'] == USER_ACTIVATION_SELF || $_CORE_CONFIG['user']['activation'] == USER_ACTIVATION_ADMIN) && !$_CORE_CONFIG['email']['email_enable']) {
         trigger_error('UCP_REGISTER_DISABLE');
     }
     $_CLASS['core_template']->assign('S_UCP_ACTION', generate_link('Control_Panel&amp;mode=register'));
     $error = $data = array();
     $s_hidden_fields = '';
     if (!isset($_POST['agreed'])) {
         if ($_CORE_CONFIG['user']['coppa_enable'] && is_null($coppa)) {
             $now = explode(':', gmdate('m:j:Y'));
             $coppa_birthday = $_CLASS['core_user']->format_date(mktime(12, 0, 0, $now[0], $now[1], $now[2] - 13), 'D M d, Y');
             $_CLASS['core_template']->assign_array(array('L_COPPA_NO' => sprintf($_CLASS['core_user']->lang['UCP_COPPA_BEFORE'], $coppa_birthday), 'L_COPPA_YES' => sprintf($_CLASS['core_user']->lang['UCP_COPPA_ON_AFTER'], $coppa_birthday), 'U_COPPA_NO' => generate_link('Control_Panel&amp;mode=register&amp;coppa=0'), 'U_COPPA_YES' => generate_link('Control_Panel&amp;mode=register&amp;coppa=1'), 'S_SHOW_COPPA' => true, 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_REGISTER_ACTION' => generate_link('Control_Panel&amp;mode=register')));
         } else {
             $s_hidden_fields .= '<input type="hidden" name="coppa" value="' . $coppa . '" />';
             $_CLASS['core_template']->assign_array(array('S_SHOW_COPPA' => false, 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_REGISTER_ACTION' => generate_link('Control_Panel&amp;mode=register')));
         }
         $this->display($_CLASS['core_user']->lang['REGISTER'], 'ucp_agreement.html');
         script_close();
     }
     if ($submit) {
         require_once $site_file_root . 'includes/functions_user.php';
         $error = array();
         $username = get_variable('username', 'POST', false);
         $password = get_variable('password', 'POST', false);
         $email = get_variable('email', 'POST', false);
         $email_confirm = get_variable('email_confirm', 'POST', '');
         //when we add this make sure to confirm that it's one of the installed langs
         $lang = $_CORE_CONFIG['global']['default_lang'];
         $tz = get_variable('tz', 'POST', false);
         if (strpos($username, "\n")) {
             die;
         }
         $username_validate = validate_username($username);
         if ($username_validate !== true) {
             $error[] = $_CLASS['core_user']->get_lang($username_validate);
         }
         if (!$password || $password !== get_variable('password_confirm', 'POST', '')) {
             $error[] = $_CLASS['core_user']->get_lang('PASSWORD_ERROR');
         }
         if (!$email || $email !== $email_confirm) {
             $error[] = $_CLASS['core_user']->get_lang('EMAIL_ERROR');
         } elseif (!check_email($email)) {
             $error[] = $_CLASS['core_user']->get_lang('EMAIL_INVALID');
         }
         if (!$tz || !in_array($tz, tz_array())) {
             $tz = null;
         }
         if ($_CORE_CONFIG['user']['enable_confirm']) {
             $confirmation_code = $_CLASS['core_user']->session_data_get('confirmation_code');
             $confirm_code = trim(get_variable('confirm_code', 'POST', false));
             if (!$confirm_code || !$confirmation_code || $confirm_code != $confirmation_code) {
                 $error[] = $_CLASS['core_user']->get_lang('CONFIRM_CODE_WRONG');
             }
             // we don't need this any more
             $_CLASS['core_user']->user_data_kill('confirmation_code');
         }
         if (empty($error)) {
             $password = encode_password($password, $_CORE_CONFIG['user']['password_encoding']);
             if (!$password) {
                 //do some admin contact thing here
                 die('Activation disabled: Passwaord encoding problem');
             }
             if ($coppa || $_CORE_CONFIG['user']['activation'] == USER_ACTIVATION_SELF || $_CORE_CONFIG['user']['activation'] == USER_ACTIVATION_ADMIN) {
                 if (!$_CORE_CONFIG['email']['email_enable']) {
                     //do some admin contact thing here
                     die('Activation disabled: Email Disabled');
                 }
                 $user_status = STATUS_PENDING;
                 $user_act_key = generate_string(10);
                 if ($coppa) {
                     $message = $_CLASS['core_user']->lang['ACCOUNT_COPPA'];
                     $email_template = 'coppa_welcome_inactive';
                 } elseif ($_CORE_CONFIG['user']['activation'] == USER_ACTIVATION_SELF) {
                     $message = $_CLASS['core_user']->lang['ACCOUNT_INACTIVE'];
                     $email_template = 'user_welcome_inactive';
                 } elseif ($_CORE_CONFIG['user']['activation'] == USER_ACTIVATION_ADMIN) {
                     $message = $_CLASS['core_user']->lang['ACCOUNT_INACTIVE_ADMIN'];
                     $email_template = 'admin_welcome_inactive';
                 }
             } else {
                 $user_status = STATUS_ACTIVE;
                 $user_act_key = null;
                 $email_template = 'user_welcome';
                 $message = $_CLASS['core_user']->lang['ACCOUNT_ADDED'];
             }
             $data = array('username' => (string) $username, 'user_email' => (string) $email, 'user_group' => $coppa ? 3 : 2, 'user_reg_date' => (int) $_CLASS['core_user']->time, 'user_timezone' => (string) $tz, 'user_password' => (string) $password, 'user_password_encoding' => (string) $_CORE_CONFIG['user']['password_encoding'], 'user_lang' => $lang ? (string) $lang : null, 'user_type' => USER_NORMAL, 'user_status' => (int) $user_status, 'user_act_key' => (string) $user_act_key, 'user_ip' => (string) $_CLASS['core_user']->ip);
             user_add($data);
             if ($data['user_status'] === STATUS_ACTIVE) {
                 set_core_config('user', 'newest_user_id', $data['user_id'], false);
                 set_core_config('user', 'newest_username', $data['username'], false);
                 set_core_config('user', 'total_users', $_CORE_CONFIG['user']['total_users'] + 1, false);
             }
             require_once $site_file_root . 'includes/mailer.php';
             $mailer = new core_mailer();
             $mailer->to($email, $username);
             $mailer->subject($subject);
             $_CLASS['core_template']->assign_array(array('SITENAME' => $_CORE_CONFIG['global']['site_name'], 'WELCOME_MSG' => sprintf($_CLASS['core_user']->lang['WELCOME_SUBJECT'], $_CORE_CONFIG['global']['site_name']), 'USERNAME' => $username, 'PASSWORD' => $password, 'EMAIL_SIG' => '', 'U_ACTIVATE' => generate_link('system&amp;mode=activate&user_id=' . $data['user_id'] . '&key=' . $user_act_key, array('sid' => false, 'full' => true))));
             if ($coppa) {
                 $_CLASS['core_template']->assign_array(array('FAX_INFO' => $_CORE_CONFIG['user']['coppa_fax'], 'MAIL_INFO' => $_CORE_CONFIG['user']['coppa_mail'], 'EMAIL_ADDRESS' => $email, 'SITENAME' => $_CORE_CONFIG['global']['site_name']));
             }
             $mailer->message = trim($_CLASS['core_template']->display('modules/Control_Panel/email/' . $email_template, true));
             $mailer->send();
             $message = $message . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_INDEX'], '<a href="' . generate_link() . '">', '</a>');
             trigger_error($message);
         }
     }
     $s_hidden_fields .= '<input type="hidden" name="coppa" value="' . $coppa . '" />';
     $s_hidden_fields .= '<input type="hidden" name="agreed" value="true" />';
     if ($_CORE_CONFIG['user']['enable_confirm']) {
         $_CLASS['core_user']->session_data_set('confirmation_code', generate_string(6));
         $confirm_image = '<img src="' . generate_link('system&amp;mode=confirmation_image') . '" alt="" title="" />';
     } else {
         $confirm_image = false;
     }
     if ($submit) {
         if ($_CORE_CONFIG['user']['max_reg_attempts']) {
             $attempts = (int) $_CLASS['core_user']->session_data_get('reg_attempts', 0);
             if ($attempts > $_CORE_CONFIG['user']['max_reg_attempts']) {
                 trigger_error($_CLASS['core_user']->lang['TOO_MANY_REGISTERS']);
             }
             $_CLASS['core_user']->session_data_get('reg_attempts', $attempts + 1);
         }
     }
     switch ($_CORE_CONFIG['user']['activation']) {
         case USER_ACTIVATION_SELF:
             $l_reg_cond = $_CLASS['core_user']->lang['UCP_EMAIL_ACTIVATE'];
             break;
         case USER_ACTIVATION_ADMIN:
             $l_reg_cond = $_CLASS['core_user']->lang['UCP_ADMIN_ACTIVATE'];
             break;
         default:
             $l_reg_cond = '';
             break;
     }
     $user_char_ary = array('.*' => 'USERNAME_CHARS_ANY', '[\\w]+' => 'USERNAME_ALPHA_ONLY', '[\\w_\\+\\. \\-\\[\\]]+' => 'USERNAME_ALPHA_SPACERS');
     $_CLASS['core_template']->assign_array(array('ERROR' => empty($error) ? false : implode('<br />', $error), 'USERNAME' => isset($username) ? $username : '', 'PASSWORD' => isset($password) ? $password : '', 'EMAIL' => isset($email) ? $email : '', 'EMAIL_CONFIRM' => isset($email_confirm) ? $email_confirm : '', 'CONFIRM_IMG' => $confirm_image, 'SELECT_TZ' => select_tz(isset($tz) ? $tz : $_CORE_CONFIG['global']['default_timezone']), 'L_CONFIRM_EXPLAIN' => sprintf($_CLASS['core_user']->lang['CONFIRM_EXPLAIN'], '<a href="mailto:' . htmlentities($config['board_contact']) . '">', '</a>'), 'L_ITEMS_REQUIRED' => $l_reg_cond, 'L_USERNAME_EXPLAIN' => sprintf($_CLASS['core_user']->lang[$user_char_ary[$_CORE_CONFIG['user']['allow_name_chars']] . '_EXPLAIN'], $_CORE_CONFIG['user']['min_name_chars'], $_CORE_CONFIG['user']['max_name_chars']), 'L_NEW_PASSWORD_EXPLAIN' => sprintf($_CLASS['core_user']->lang['NEW_PASSWORD_EXPLAIN'], $_CORE_CONFIG['user']['min_pass_chars'], $_CORE_CONFIG['user']['max_pass_chars']), 'S_COPPA' => $coppa, 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_UCP_ACTION' => generate_link("Control_Panel&amp;mode=register")));
     $this->display($_CLASS['core_user']->lang['REGISTER'], 'ucp_register.html');
 }
Esempio n. 8
0
    if ($username == substr($username, 0, 15)) {
        // if the username is not blank
        if (!empty($username)) {
            // if the username is clean
            if ($username == $_POST["garbage"]) {
                $email0 = clean($_POST["email0"]);
                $email1 = clean($_POST["email1"]);
                // if the email addresses match
                if ($email0 == $email1) {
                    // if the email address isn't blank
                    if (!empty($email0)) {
                        // if the email address is clean
                        if ($email0 == $_POST["email0"]) {
                            //  <<<<<<<<<<<<<<<<<<<<<<<<<<  shift indents back in   <<<<<<<<<<<<<<<<<<<<<<
                            // generate a 12-character password
                            $password = generate_string(12);
                            // insert the new user into the ttf_user table
                            $sql = "INSERT INTO ttf_user SET username='******', password=SHA1('{$password}'), " . "email='{$email0}', register_date=UNIX_TIMESTAMP(), register_ip='{$_SERVER["REMOTE_ADDR"]}'";
                            if (!($result = mysql_query($sql))) {
                                // if unsuccessful, a user with the same username probably exists
                                message("register an account", "fatal error", "no account was created. perhaps an " . "account already exists with a matching username or e-mail address.");
                            } else {
                                // if successful, send the email with the login information
                                $subject = "{$ttf_cfg["forum_name"]} account information";
                                $message = <<<EOF
hi--

here is your account information for {$ttf_cfg["forum_name"]}:

username: {$username}
password: {$password}
Esempio n. 9
0
$str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$code = "";
$str_num = "0123456789";
if (isset($_POST['count'])) {
    $count = $_POST['count'];
    $num = (int) $_POST['num'];
    if ($num == 1) {
        $code = generate_string($str_num, $count);
    }
    if ($num == 2) {
        $code = generate_string($str, $count);
        //this is a comment - new comment
    }
    if ($num == 3) {
        $code = generate_string($str . $str_num, $count);
    }
}
function generate_string($arr, $count)
{
    $temp = "";
    for ($i = 0; $i < $count; $i++) {
        $r = rand(0, strlen($arr) - 1);
        $temp .= $arr[$r];
    }
    return $temp;
}
/*
   $alphasu = range('A', 'Z');
   $alphasm = range('a', 'z');
   $alphaplus = array_merge($alphasu, $alphasm);
Esempio n. 10
0
 public function index()
 {
     if ($this->config->item('salt_password') || $this->axipi_session->userdata('setup_done')) {
         redirect(base_url() . 'home');
     }
     $data = array();
     $data['pdo_drivers'] = PDO::getAvailableDrivers();
     $data['types'] = array();
     if (function_exists('mysqli_connect')) {
         $data['types']['mysqli'] = 'MySQL (Improved Extension)';
     }
     if (in_array('mysql', $data['pdo_drivers'])) {
         $data['types']['pdo_mysql'] = 'MySQL (PDO)';
     }
     if (in_array('sqlite', $data['pdo_drivers'])) {
         $data['types']['pdo_sqlite'] = 'SQLite (PDO)';
     }
     $this->load->library(array('form_validation'));
     if (is_writable('application/config')) {
         if (!file_exists('application/config/database.php')) {
             $fp = fopen('application/config/database.php', 'w');
             fclose($fp);
         }
         if (!file_exists('application/config/readerself_config.php')) {
             $fp = fopen('application/config/readerself_config.php', 'w');
             fclose($fp);
         }
     }
     $this->form_validation->set_rules('database_type', 'lang:database_type', 'required|callback_database_type');
     $this->form_validation->set_rules('mbr_email', 'lang:mbr_email', 'required|valid_email|max_length[255]');
     $this->form_validation->set_rules('mbr_email_confirm', 'lang:mbr_email_confirm', 'required|valid_email|max_length[255]|matches[mbr_email]');
     $this->form_validation->set_rules('mbr_password', 'lang:mbr_password', 'required');
     $this->form_validation->set_rules('mbr_password_confirm', 'lang:mbr_password_confirm', 'required|matches[mbr_password]');
     if ($this->form_validation->run() == FALSE) {
         $content = $this->load->view('setup_index', $data, TRUE);
         $this->readerself_library->set_content($content);
     } else {
         $parameters = array();
         if ($this->input->post('database_type') == 'mysqli') {
             $parameters['dsn'] = '';
             $parameters['hostname'] = $this->input->post('database_hostname');
             $parameters['username'] = $this->input->post('database_username');
             $parameters['password'] = $this->input->post('database_password');
             $parameters['database'] = $this->input->post('database_name');
             $parameters['dbdriver'] = 'mysqli';
         }
         if ($this->input->post('database_type') == 'pdo_mysql') {
             $parameters['dsn'] = 'mysql:dbname=' . $this->input->post('database_name') . ';host=' . $this->input->post('database_hostname');
             $parameters['hostname'] = '';
             $parameters['username'] = $this->input->post('database_username');
             $parameters['password'] = $this->input->post('database_password');
             $parameters['database'] = '';
             $parameters['dbdriver'] = 'pdo';
         }
         if ($this->input->post('database_type') == 'pdo_sqlite') {
             $parameters['dsn'] = 'sqlite:application/database/readerself.sqlite';
             $parameters['hostname'] = '';
             $parameters['username'] = '';
             $parameters['password'] = '';
             $parameters['database'] = '';
             $parameters['dbdriver'] = 'pdo';
         }
         $content_view = $this->load->view('setup_database', $parameters, TRUE);
         $fp = fopen('application/config/database.php', 'w');
         fwrite($fp, '<?php' . "\n");
         fwrite($fp, $content_view);
         fclose($fp);
         if (function_exists('opcache_invalidate')) {
             opcache_invalidate('application/config/database.php', true);
         }
         $this->load->database();
         if ($this->input->post('database_type') == 'mysqli' || $this->input->post('database_type') == 'pdo_mysql') {
             $queries = explode(';', trim(file_get_contents('application/database/installation-mysql.sql')));
         }
         if ($this->input->post('database_type') == 'pdo_sqlite') {
             $queries = explode(';', trim(file_get_contents('application/database/installation-sqlite.sql')));
         }
         foreach ($queries as $query) {
             if ($query != '') {
                 $this->db->query(str_replace('NOW()', '\'' . date('Y-m-d H:i:s') . '\'', $query));
             }
         }
         $parameters = array();
         $parameters['salt_password'] = generate_string(10);
         $content_view = $this->load->view('setup_config', $parameters, TRUE);
         $fp = fopen('application/config/readerself_config.php', 'w');
         fwrite($fp, '<?php' . "\n");
         fwrite($fp, $content_view);
         fclose($fp);
         if (function_exists('opcache_invalidate')) {
             opcache_invalidate('application/config/readerself_config.php', true);
         }
         $this->config->load('readerself_config', false, true);
         $this->db->set('mbr_email', $this->input->post('mbr_email'));
         $this->db->set('mbr_password', $this->readerself_library->set_salt_password($this->input->post('mbr_password')));
         if ($this->readerself_model->count_members() == 0) {
             $this->db->set('mbr_administrator', 1);
         }
         $this->db->set('mbr_datecreated', date('Y-m-d H:i:s'));
         $this->db->insert('members');
         $mbr_id = $this->db->insert_id();
         $this->axipi_session->set_userdata('setup_done', true);
         $this->readerself_model->connect($mbr_id);
         redirect(base_url() . 'setup/confirm');
     }
 }
Esempio n. 11
0
 public function index()
 {
     if ($this->config->item('salt_password') || $this->session->userdata('mbr_id')) {
         redirect(base_url() . 'home');
     }
     $this->load->library(array('form_validation'));
     if (!file_exists('application/config/readerself_config.php')) {
         $fp = fopen('application/config/readerself_config.php', 'w');
         fclose($fp);
     }
     $this->form_validation->set_rules('mbr_email', 'lang:mbr_email', 'required|valid_email|max_length[255]');
     $this->form_validation->set_rules('mbr_email_confirm', 'lang:mbr_email_confirm', 'required|valid_email|max_length[255]|matches[mbr_email]');
     $this->form_validation->set_rules('mbr_password', 'lang:mbr_password', 'required');
     $this->form_validation->set_rules('mbr_password_confirm', 'lang:mbr_password_confirm', 'required|matches[mbr_password]');
     if ($this->form_validation->run() == FALSE) {
         $data = array();
         $content = $this->load->view('setup_index', $data, TRUE);
         $this->readerself_library->set_content($content);
     } else {
         if ($this->db->dbdriver == 'pdo' && $this->db->hostname == 'sqlite:application/database/readerself.sqlite') {
             $queries = explode(';', trim(file_get_contents('application/database/installation-sqlite.sql')));
         }
         if ($this->db->dbdriver == 'mysqli') {
             $queries = explode(';', trim(file_get_contents('application/database/installation-mysql.sql')));
         }
         foreach ($queries as $query) {
             if ($query != '') {
                 $this->db->query(str_replace('NOW()', '\'' . date('Y-m-d H:i:s') . '\'', $query));
             }
         }
         $lines = array();
         $lines['salt_password'] = generate_string(10);
         $lines['ldap'] = FALSE;
         $lines['ldap_server'] = 'ldap://localhost';
         $lines['ldap_port'] = 389;
         $lines['ldap_protocol'] = 3;
         $lines['ldap_rootdn'] = 'cn=Manager,dc=my-domain,dc=com';
         $lines['ldap_rootpw'] = 'secret';
         $lines['ldap_basedn'] = 'dc=my-domain,dc=com';
         $lines['ldap_filter'] = 'mail=[email]';
         $lines['email_protocol'] = 'mail';
         //mail or smtp
         $lines['smtp_host'] = '';
         $lines['smtp_user'] = '';
         $lines['smtp_pass'] = '';
         $lines['smtp_port'] = 25;
         $fp = fopen('application/config/readerself_config.php', 'w');
         fwrite($fp, '<?php' . "\n");
         foreach ($lines as $cfg_path => $cfg_value) {
             $this->config->set_item($cfg_path, $cfg_value);
             if (is_numeric($cfg_value)) {
                 fwrite($fp, '$config[\'' . $cfg_path . '\'] = ' . $cfg_value . ';' . "\n");
             } else {
                 fwrite($fp, '$config[\'' . $cfg_path . '\'] = \'' . $cfg_value . '\';' . "\n");
             }
         }
         fclose($fp);
         $this->config->set_item('salt_password', $lines['salt_password']);
         $this->db->set('mbr_email', $this->input->post('mbr_email'));
         $this->db->set('mbr_password', $this->readerself_library->set_salt_password($this->input->post('mbr_password')));
         if ($this->readerself_model->count_members() == 0) {
             $this->db->set('mbr_administrator', 1);
         }
         $this->db->set('mbr_datecreated', date('Y-m-d H:i:s'));
         $this->db->insert('members');
         $mbr_id = $this->db->insert_id();
         $this->readerself_model->connect($mbr_id);
         redirect(base_url() . 'home');
     }
 }