Beispiel #1
0
 public function action_registration()
 {
     // Уже авторизован
     if (Auth::instance()->logged_in()) {
         HTTP::redirect("/user/cabinet");
     }
     $model = array();
     // Обработка формы
     if ($_POST) {
         $vData = $_POST;
         $validation = Validation::factory($vData);
         $validation->rule('email', 'not_empty');
         $validation->rule('email', 'min_length', array(':value', '2'));
         $validation->rule('email', 'max_length', array(':value', '250'));
         $validation->rule('password', 'not_empty');
         $validation->rule('password', 'min_length', array(':value', '6'));
         $validation->rule('password', 'max_length', array(':value', '50'));
         $validation->rule('password', 'equal_fields', array(':value', $vData['password_confirm']));
         // не прошёл валидацию
         if (!$validation->check()) {
             $errors = $validation->errors('registrationErrors');
             $model = array("error" => "");
             PC::degug($errors, "errors");
             foreach ($errors as $error) {
                 $model["error"] .= '<div class="alert alert-danger"><p>' . $error . '</p></div>';
             }
         } else {
             $email = Arr::get($_POST, 'email', '');
             $password = Arr::get($_POST, 'password', '');
             $confirm_pass = Arr::get($_POST, 'password_confirm', '');
             $model_register = new Model_Register();
             PC::debug($_POST, "registration form");
             // Регистрация прошла успешно
             if ($model_register->reg($email, $password, 4)) {
                 $model = array("success" => '<div class="alert alert-success">Спасибо за регистрацию! На электронный адрес <b>' . $email . '</b> отправлено письмо для активации аккаунта.</div>');
             } else {
                 $errors = $model_register->errors;
                 $model = array("error" => "");
                 foreach ($errors as $error) {
                     $model["error"] .= '<div class="alert alert-danger"><p>' . $error . '</p></div>';
                 }
             }
         }
     }
     $this->title('Регистрация');
     $this->page_title('Регистрация');
     $this->keywords('Регистрация');
     $this->description('Регистрация');
     $this->render('user/cabinet/registration.php', $model, "response");
 }
Beispiel #2
0
 public function action_checkcode()
 {
     $data = array();
     $code = $this->request->param('id');
     $register = new Model_Register();
     if ($register->obnovlenieparolia($code)) {
         $data["ok"] = "";
     } else {
         $data["error"] = "";
     }
     $this->template->content = View::factory('checkcodeview', $data);
 }
Beispiel #3
0
 public function action_reg()
 {
     $base = new Model_Base();
     $options = $base->getOptions();
     if (!isset($options['room']) || $options['room'] != 'TRUE') {
         Controller::redirect('/');
     }
     $this->template->title = 'Регистрация нового пользователя';
     $this->template->page_title = 'Регистрация нового пользователя';
     $this->template->keywords = 'Регистрация нового пользователя';
     $this->template->description = 'Регистрация нового пользователя';
     //$this->template->styles[] = 'css/registration.css';
     //$this->template->styles = $this->getStyles($this->styles);
     $data = array();
     if (isset($_POST['registration'])) {
         $vData = $_POST;
         $validation = Validation::factory($vData);
         $validation->rule('username', 'not_empty');
         $validation->rule('username', 'min_length', array(':value', '2'));
         $validation->rule('username', 'max_length', array(':value', '250'));
         $validation->rule('password', 'not_empty');
         $validation->rule('password', 'min_length', array(':value', '6'));
         $validation->rule('password', 'max_length', array(':value', '50'));
         $validation->rule('password', 'equal_fields', array(':value', $vData['password_confirm']));
         if (!$validation->check()) {
             $errors = $validation->errors('registrationErrors');
         } else {
             $username = Arr::get($_POST, 'username', '');
             $password = Arr::get($_POST, 'password', '');
             $confirm_pass = Arr::get($_POST, 'password_confirm', '');
             $register = new Model_Register();
             if ($register->reg($username, $password, 4)) {
                 $success = 'Спасибо за регистрацию! На электронный адрес <b>' . $username . '</b> отправлено письмо для активации аккаунта. <a href="/user">Вход в систему</a>';
             } else {
                 $errors = $register->errors;
             }
         }
     }
     if (isset($_GET['token'])) {
         //активируем пользователя
         $vData = $_GET;
         $validation = Validation::factory($vData);
         $validation->rule('user', 'not_empty');
         $validation->rule('user', 'min_length', array(':value', '2'));
         $validation->rule('user', 'max_length', array(':value', '250'));
         $validation->rule('token', 'not_empty');
         $validation->rule('token', 'min_length', array(':value', '6'));
         if (!$validation->check()) {
             $errors = $validation->errors('registrationErrors');
         } else {
             $username = Arr::get($_GET, 'user', '');
             $token = Arr::get($_GET, 'token', '');
             $register = new Model_Register();
             if ($register->activateUser($username, $token)) {
                 $success = 'Активация выполнена успешно! Переходим в личный кабинет';
                 Controller::redirect('/user');
             } else {
                 $errors[] = 'Ошибка активации';
             }
         }
     }
     $widgets = $this->getWidgets(0);
     if (is_array($widgets)) {
         foreach ($widgets as $position => $widget) {
             $this->template->{$position} = $widget;
         }
     }
     $this->template->block_center[] = View::factory('widgets/w_registration')->bind('errors', $errors)->bind('success', $success);
 }