예제 #1
0
 public function regsAction()
 {
     $model = new PageModel();
     if (isPost()) {
         $regCode = $model->getRegCode(post('code'));
         if ($regCode->id or true) {
             // TODO забрати "OR true"
             $data['nickname'] = post('nickname');
             if (checkLenght(post('nickname'), 3, 16) && !$model->getUserByNickname(post('nickname'))) {
                 $data['nickname'] = post('nickname');
             } else {
                 $this->view->error = 'Incorrect "Nickname" or exist';
             }
             if (checkEmail(post('email')) && !$model->getUserByEmail(post('email'))) {
                 $data['email'] = post('email');
             } else {
                 $this->view->error = 'Incorrect "E-mail" or exist';
             }
             if (checkLenght(post('password'), 6, 20)) {
                 $data['password'] = md5(post('password'));
             } else {
                 $this->view->error = 'Incorrect "Password"';
             }
             if (checkLenght(post('password_re'), 6, 20)) {
                 if (post('password') != post('password_re')) {
                     $this->view->error = 'Passwords do not match';
                 }
             } else {
                 $this->view->error = 'Incorrect "Repeat password"';
             }
             if (post('rules') != 'yes') {
                 $this->view->error = 'You must agree to Rules';
             }
             if (post('terms') != 'yes') {
                 $this->view->error = 'You must accept Terms and Conditions';
             }
             //$data['referral'] = $regCode->uid; // TODO ref system
             $data['dateLast'] = time();
             $data['dateReg'] = time();
             if (!$this->view->error) {
                 $uid = $model->insert('users', $data);
                 if ($uid) {
                     setSession('user', $uid, false);
                     //$model->deleteRegCode($regCode->id);
                     redirect(url($uid));
                 } else {
                     $this->view->error = 'Error Registration';
                 }
             }
         } else {
             $this->view->error = 'Incorrect "Registration code"';
         }
     }
     $code = Request::getUriOptions()[0];
     if ($code) {
         $_POST['code'] = $code;
     }
     $this->view->title = Lang::translate('REG_TITLE');
 }