Ejemplo n.º 1
0
 public function actionIndex()
 {
     $this->pageTitle = Lang::t('Register');
     $user_model = new Users(Users::SCENARIO_SIGNUP);
     $user_model->activation_code = Common::generateHash(microtime());
     $user_model->user_level = UserLevels::LEVEL_MEMBER;
     $user_model->timezone = SettingsTimezone::DEFAULT_TIME_ZONE;
     $user_model_class_name = $user_model->getClassName();
     $person_model = new Person();
     $person_model_class_name = $person_model->getClassName();
     $person_address = new PersonAddress();
     $person_address_class_name = $person_address->getClassName();
     if (Yii::app()->request->isPostRequest) {
         $verifyPhoneCode = isset($_POST['verifyPhoneCode']) ? $_POST['verifyPhoneCode'] : null;
         $verifyMailCode = isset($_POST['verifyMailCode']) ? $_POST['verifyMailCode'] : null;
         if (isset($_POST[$user_model_class_name])) {
             $user_model->validatorList->add(CValidator::createValidator('CaptchaExtendedValidator', $user_model, 'verifyCode', array('allowEmpty' => !CCaptcha::checkRequirements())));
             $user_model->attributes = $_POST[$user_model_class_name];
             $user_model->status = 'Active';
             $user_model->answer = strtoupper($user_model->answer);
             $user_model->validate();
         }
         if (isset($_POST[$person_model_class_name])) {
             $person_model->attributes = $_POST[$person_model_class_name];
             $person_model->married = 'n';
             $person_model->havechildren = 'n';
             $person_model->validate();
         }
         if (isset($_POST['PersonAddress'])) {
             $person_address->attributes = $_POST[$person_address_class_name];
             $person_address->validate(array('phone1'));
         }
         if (!$user_model->hasErrors() && !$person_model->hasErrors() && !$person_address->hasErrors()) {
             if ($user_model->save(FALSE)) {
                 $person_model->id = $user_model->id;
                 $person_model->save(FALSE);
                 $person_address->person_id = $person_model->id;
                 $person_address->save(FALSE);
                 Yii::app()->user->setFlash('success', Lang::t('Account created successfullly. Please enter your login details.'));
                 $this->redirect($this->createUrl('/users/default/view', array('id' => $user_model->id)));
                 //$this->redirect('../default/login');
             }
         }
     }
     $this->render('index', array('user_model' => $user_model, 'person_model' => $person_model, 'person_address' => $person_address, 'verifyPhoneCode' => isset($verifyPhoneCode) ? $verifyPhoneCode : null, 'verifyMailCode' => isset($verifyMailCode) ? $verifyMailCode : null));
 }
Ejemplo n.º 2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($dept_id = NULL, $user_level = NULL)
 {
     $this->hasPrivilege(Acl::ACTION_CREATE);
     $this->pageTitle = Lang::t('Add ' . $this->resourceLabel);
     //account information
     $user_model = new Users(ActiveRecord::SCENARIO_CREATE);
     $user_model->status = Users::STATUS_ACTIVE;
     $user_model_class_name = $user_model->getClassName();
     //personal information
     $person_model = new Person();
     $person_model_class_name = $person_model->getClassName();
     //personal address information
     $person_address = new PersonAddress();
     $person_address_class_name = $person_address->getClassName();
     if (Yii::app()->request->isPostRequest) {
         $user_model->attributes = $_POST[$user_model_class_name];
         $person_model->attributes = $_POST[$person_model_class_name];
         $person_address->attributes = $_POST[$person_address_class_name];
         $user_model->validate();
         $person_model->validate();
         $person_address->validate(array('phone1'));
         if (!$user_model->hasErrors() && !$person_model->hasErrors() && !$person_address->hasErrors()) {
             if ($user_model->save(FALSE)) {
                 $person_model->id = $user_model->id;
                 $person_model->save(FALSE);
                 $person_address->person_id = $person_model->id;
                 $person_address->save(FALSE);
                 $user_model->updateDeptUser();
                 if (!empty($user_model->dept_id)) {
                     Dept::model()->updateContactPerson($user_model->dept_id, $person_model->id);
                 }
                 Yii::app()->user->setFlash('success', Lang::t('SUCCESS_MESSAGE'));
                 $this->redirect(Controller::getReturnUrl($this->createUrl('view', array('id' => $user_model->id))));
             }
         }
     }
     $user_model->timezone = Yii::app()->settings->get(Constants::CATEGORY_GENERAL, Constants::KEY_DEFAULT_TIMEZONE, SettingsTimezone::DEFAULT_TIME_ZONE);
     if (!empty($dept_id)) {
         $user_model->dept_id = $dept_id;
     }
     if (!empty($user_level)) {
         $user_model->user_level = $user_level;
     }
     $this->render('create', array('user_model' => $user_model, 'person_model' => $person_model, 'person_address' => $person_address));
 }