Файл: adultscript-2.0.3-pro/files/modules/user/components/signup.php
Строк: 175
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_user_signup extends VModule_user
{
public function __construct()
{
parent::__construct();
}
public function render()
{
if (!VUri::match('user/signup/')) {
VModule::load('404', true);
}
$ucfg = VF::cfg('module.user');
$errors = array();
$messages = array();
if ($ucfg['signup_enabled'] == '0') {
$errors[] = __('signup-disabled');
}
if ($ucfg['signup_country'] == '1') {
$countries = VCountry::get();
$this->tpl->countries = $countries;
}
if (VAuth::loggedin()) {
VF::redirect(BASE_URL.'/user/dashboard/');
}
$signup = array(
'username' => '', 'email' => '', 'gender' => '', 'birth_date' => '0000-00-00', 'country' => '',
'age_confirm' => 'off', 'terms_confirm' => 'off', 'city' => '', 'zip' => '', 'name' => ''
);
if (isset($_POST['submit-signup']) && !$errors) {
$filter = VF::factory('filter');
$username = $filter->get('username');
$password = trim($_POST['password']);
$password_c = trim($_POST['password_confirm']);
$email = $filter->get('email');
$name = (isset($_POST['name'])) ? $filter->get('name') : '';
$gender = (isset($_POST['gender'])) ? $filter->get('gender') : 'hidden';
$birth_day = $filter->get('Date_day', 'INT');
$birth_month = $filter->get('Date_month', 'INT');
$birth_year = $filter->get('Date_year', 'INT');
$birth_date = '0000-00-00';
$country = (isset($_POST['country'])) ? $filter->get('country') : '';
$city = (isset($_POST['city'])) ? $filter->get('city') : '';
$zip = (isset($_POST['zip'])) ? $filter->get('zip') : '';
$terms_confirm = (isset($_POST['terms_confirm'])) ? 'on' : 'off';
$age_confirm = (isset($_POST['age_confirm'])) ? 'on' : 'off';
if ($username == '') {
$errors[] = __('username-empty');
} elseif (!VValid::length($username, 1, 16)) {
$errors[] = __('username-length', array(16));
} elseif (!VValid::aldash($username)) {
$errors[] = __('username-invalid');
} else {
$this->db->query("SELECT user_id FROM #__user WHERE username = '".$this->db->escape($username)."' LIMIT 1");
if ($this->db->affected_rows()) {
$errors[] = __('username-used');
} else {
$signup['username'] = $username;
}
}
if ($email == '') {
$errors[] = __('email-empty');
} elseif (!VValid::email($email)) {
$errors[] = __('email-invalid');
} else {
$this->db->query("SELECT user_id FROM #__user WHERE email = '".$this->db->escape($email)."' LIMIT 1");
if ($this->db->affected_rows()) {
$errors[] = __('email-used');
} else {
$signup['email'] = $email;
}
}
if ($password == '') {
$errors[] = __('password-empty');
} elseif ($password != $password_c) {
$errors[] = __('password-mismatch');
} elseif (!VValid::length($password, $ucfg['pwd_min_length'], $ucfg['pwd_max_length'])) {
$errors[] = __('password-length', array($ucfg['pwd_min_length'], $ucfg['pwd_max_length']));
}
if ($ucfg['signup_gender'] == '1') {
if ($gender == '') {
$errors[] = __('gender-empty');
} else {
$gender = ($gender == 'male') ? 'male' : 'female';
$signup['gender'] = $gender;
}
}
if ($ucfg['signup_name'] == '1') {
if ($name == '') {
$errors[] = __('name-empty');
} elseif (!VValid::length($name, 3, 100)) {
$errors[] = __('name-length');
} else {
$signup['name'] = $name;
}
}
if ($ucfg['signup_birth_date'] == '1') {
if ($birth_day === 0 OR $birth_month === 0 OR $birth_year === 0) {
$errors[] = __('birthdate-empty');
} else {
if (!checkdate($birth_month, $birth_day, $birth_year)) {
$errors[] = __('birthdate-invalid');
} else {
$birth_date = $signup['birth_date'] = $birth_year.'-'.sprintf('%02d', $birth_month).'-'.sprintf('%02d', $birth_day);
}
}
}
if ($ucfg['signup_country'] == '1') {
if ($country == '') {
$errors[] = __('country-empty');
} else {
$country = (isset($countries[$country])) ? $countries[$country] : '';
if ($country == '') {
$errors[] = __('country-invalid');
} else {
$signup['country'] = $country;
}
}
}
if ($ucfg['signup_city'] == '1') {
if ($city == '') {
$errors[] = __('city-empty');
} else {
$signup['city'] = $city;
}
}
if ($age_confirm == 'off') {
$errors[] = __('age-empty', array($ucfg['signup_age']));
} else {
$signup['age_confirm'] = 'on';
}
if ($terms_confirm == 'off') {
$errors[] = __('terms-empty');
} else {
$signup['terms_confirm'] = 'on';
}
if ($ucfg['signup_captcha'] == '1') {
$code = $filter->get('code');
if (strtoupper($code) != $_SESSION['captcha_code']) {
$errors[] = __('captcha-invalid');
}
}
if (!$errors) {
$status = (VCfg::get('user.user_approve')) ? 2 : 1;
$verified = (VCfg::get('user.user_confirm')) ? 0 : 1;
$umodel = VModel::load('user', 'user', true);
if ($user_id = $umodel->add(array(
'username' => $username,
'password' => $password,
'email' => $email,
'name' => $name,
'gender' => $gender,
'birth_date' => $birth_date,
'country' => $country,
'city' => $city,
'zip' => $zip))) {
if ($status === 1) {
if ($verified) {
$_SESSION['user_id'] = $user_id;
$_SESSION['group_id'] = 5;
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
$_SESSION['name'] = $name;
$_SESSION['gender'] = $gender;
$_SESSION['birth_date'] = $birth_date;
$_SESSION['avatar'] = '';
$_SESSION['country'] = $country;
$_SESSION['city'] = $city;
$_SESSION['zip'] = '';
$_SESSION['login_date'] = date('Y-m-d H:i:s');
$_SESSION['verified'] = 1;
$_SESSION['status'] = 1;
$_SESSION['message'] = __('signup-success', array($username));
$_URL = BASE_URL.'/user/dashboard/';
} else {
$_URL = BASE_URL;
$_SESSION['message'] = __('signup-confirm', array($username));
}
} elseif ($status === 2) {
$_URL = BASE_URL;
$_SESSION['message'] = __('signup-approve', array($username));
}
VF::redirect($_URL);
} else {
throw new Exception('Failed to add database entry!');
}
}
}
$this->tpl->menu = 'home';
$this->tpl->meta_title = __('signup-meta-title', array(VCfg::get('site_name')));
$this->tpl->canonical = BASE_URL.'/user/signup/';
$this->tpl->canonicalm = MOBILE_URL.'/user/signup/';
$this->tpl->errors = $errors;
$this->tpl->messages = $messages;
$this->tpl->signup = $signup;
$this->tpl->load(array('header', 'user_signup', 'footer'));
$this->tpl->display();
}
}