public function actionCreate() { $model = new Staff(); $profile = new Profile(); $this->performAjaxValidation(array($model, $profile), 'staff-form'); if (isset($_POST['Staff'])) { $model->attributes = $_POST['Staff']; $profile->attributes = $_POST['Profile']; $profile->user_id = 0; if ($model->validate() && $profile->validate()) { $realp = PasswordHelper::generateStrongPassword(); $model->password = $realp; $model->activkey = PasswordHelper::hashPassword(microtime() . $model->password); $model->password = PasswordHelper::hashPassword($model->password); $model->status = 0; if ($model->save()) { $profile->user_id = $model->id; $profile->save(); if (!empty($_POST['Profile']['group_id'])) { foreach ($_POST['Profile']['group_id'] as $groupid) { $userGroup = new UserGroup(); $userGroup->profile_id = $model->id; $userGroup->group_id = $groupid; $userGroup->save(); } } $passwordHistory = new PasswordHistory(); $passwordHistory->profile_id = $model->id; $passwordHistory->password = $model->password; $passwordHistory->save(); if (Yii::app()->getModule('user')->sendActivationMail) { $activation_url = $this->createAbsoluteUrl('/user/activation', array("activkey" => $model->activkey, "email" => $model->email)); UserModule::sendMail($model->email, UserModule::t("Your {site_name} account has been created", array('{site_name}' => Yii::app()->name)), UserModule::t("To activate your account, go to <a href='{activation_url}'>{activation_url}</a>.<br/><br/>Username: "******"<br/>Password: "******"<br/>", array('{activation_url}' => $activation_url))); } if (Yii::app()->getRequest()->getIsAjaxRequest()) { $this->renderPartial('_view', array('model' => $model, 'profile' => $profile), false, true); Yii::app()->end(); } $this->redirect(array('view', 'id' => $model->id)); } else { Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, 'An error occured while trying to create new user, please try again.'); if (Yii::app()->getRequest()->getIsAjaxRequest()) { $this->renderPartial('_form', array('model' => $model, 'profile' => $profile), false, true); Yii::app()->end(); } $this->render('create', array('model' => $model, 'profile' => $profile)); } } else { $profile->validate(); } } if (Yii::app()->getRequest()->getIsAjaxRequest()) { $this->renderPartial('_form', array('model' => $model, 'profile' => $profile), false, true); Yii::app()->end(); } $this->render('create', array('model' => $model, 'profile' => $profile)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Customer(); $profile = new Profile(); $address = new CheckoutAddress(); //Yii::app()->session['cid'] = ''; $this->performAjaxValidation(array($model, $profile), 'customer-form'); if (isset($_POST['Customer'])) { $model->attributes = $_POST['Customer']; $profile->attributes = $_POST['Profile']; $profile->user_id = 0; if ($model->validate() && $profile->validate() && $this->validateAddress()) { $realp = PasswordHelper::generateStrongPassword(); $model->password = $realp; $model->activkey = PasswordHelper::hashPassword(microtime() . $model->password); $model->password = PasswordHelper::hashPassword($model->password); $model->status = 0; $model->type = 1; if ($model->save()) { Yii::app()->session['cid'] = $model->id; $profile->user_id = $model->id; $profile->save(); if (!empty($_POST['Customer']['c_group_id'])) { foreach ($_POST['Customer']['c_group_id'] as $groupid) { $customerGroup = new CustomerCGroup(); $customerGroup->user_id = $model->id; $customerGroup->c_group_id = $groupid; $customerGroup->save(); } } $passwordHistory = new PasswordHistory(); $passwordHistory->profile_id = $model->id; $passwordHistory->password = $model->password; $passwordHistory->save(); foreach ($this->_address as $address) { $address->user_id = $model->id; $address->save(); } if (Yii::app()->getModule('user')->sendActivationMail) { $activation_url = $this->createAbsoluteUrl('/user/activation', array("activkey" => $model->activkey, "email" => $model->email)); UserModule::sendMail($model->email, UserModule::t("Your {site_name} account has been created", array('{site_name}' => Yii::app()->name)), UserModule::t("To activate your account, go to <a href='{activation_url}'>{activation_url}</a>.<br/><br/>Username: "******"<br/>Password: "******"<br/>", array('{activation_url}' => $activation_url))); } Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, Yii::t('info', 'Customer was successfully created')); $this->renderPartial('_view', array('model' => $model, 'profile' => $profile, 'address' => $this->_address), false, true); Yii::app()->end(); } else { Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, Yii::t('info', 'An error occurred while trying to create new customer, please try again.')); /*$this->render('create',array( 'model'=>$model, 'profile'=>$profile, ));*/ } } else { $profile->validate(); $this->validateAddress(); //echo GxActiveForm::validateMultiple(array($model,$profile,$address)); //Yii::app()->end(); } } if (Yii::app()->getRequest()->getIsAjaxRequest()) { $this->renderPartial('_form_address', array('model' => $model, 'profile' => $profile, 'address' => $this->_address), false, true); Yii::app()->end(); } $this->render('create', array('model' => $model, 'profile' => $profile, 'address' => $this->_address)); }