public function actionIndex()
 {
     $this->addBreadcrumb(UserModule::t("Registration"));
     $form = new RegistrationForm();
     if ($this->getRequest()->isPost && $form->populate($_POST)->isValid() && $form->save()) {
         $this->getRequest()->redirect('user:registration_success');
     }
     echo $this->render('user/registration.html', ['form' => $form]);
 }
Esempio n. 2
0
 public function actionRegistration()
 {
     $form = new RegistrationForm();
     if ($form->setAttributes($_POST)->isValid()) {
         $user = $form->save();
         if ($user === false) {
             echo $this->json(['status' => false, 'exception' => "Failed to save model"]);
         } else {
             echo $this->json(['id' => $user->pk, 'status' => true, 'errors' => []]);
         }
         $this->end();
     } else {
         echo $this->json(['status' => false, 'errors' => $form->getErrors()]);
         $this->end();
     }
 }
 public function getFields()
 {
     $fields = parent::getFields();
     $newFields = array_merge($fields, ['last_name' => ['class' => CharField::class, 'label' => UserModule::t('Last name')], 'first_name' => ['class' => CharField::class, 'label' => UserModule::t('First name')], 'middle_name' => ['class' => CharField::class, 'label' => UserModule::t('Middle name')], 'phone' => ['class' => CharField::class, 'label' => UserModule::t('Phone'), 'hint' => 'На данный номер телефона придет смс с подтверждением регистрации', 'validators' => [function ($value) {
         if (User::objects()->filter(['phone' => $value])->count() > 0) {
             return UserModule::t("Phone must be a unique");
         }
         return true;
     }]], 'i_accept_license' => ['class' => CheckboxField::class, 'required' => true, 'label' => UserModule::t('I accept the license')]]);
     if (isset($fields['captcha'])) {
         $captcha = $fields['captcha'];
         unset($fields['captcha']);
         return array_merge($newFields, [$captcha]);
     }
     return $newFields;
 }