/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new User(); $profile = new Profile(); $post = Yii::$app->request->post(); if ($model->load($post) && $profile->load($post)) { $model->loadDefaultValues(true); $validation = $this->performAjaxValidation([$model, $profile]); if ($validation !== false) { return $validation; } $model->activkey = Yii::$app->security->generateRandomString(); $profile->user_id = 0; if ($model->validate()) { $model->password = Module::getInstance()->encrypting($model->password); if ($model->save()) { $profile->user_id = $model->id; $profile->loadDefaultValues(true); if ($profile->save(true)) { Yii::$app->user->setFlash('success', Module::t("User has been created successfully.")); return $this->redirect(['view', 'id' => $model->id]); } } } } return $this->render('create', ['model' => $model, 'profile' => $profile]); }
/** * Registration user */ public function actionRegistration() { Profile::$regMode = true; $model = new RegistrationForm(); $profile = new Profile(); $module = Module::getInstance(); // ajax validator // if (Yii::$app->request->isAjax) { // if ($model->load(Yii::$app->request->post()) && $profile->load(Yii::$app->request->post())) { // Yii::$app->response->format = Response::FORMAT_JSON; // return ActiveForm::validateMultiple([$model, $profile]); // } // } if (Yii::$app->user->id) { $this->redirect($module->profileUrl); } else { if ($model->load(Yii::$app->request->post())) { $profile->load(Yii::$app->request->post()); if ($model->validate() && $profile->validate()) { $model->activkey = Module::encrypting(microtime() . $model->password); $model->superuser = 0; $model->status = $module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE; if ($model->save(false)) { $profile->user_id = $model->id; $profile->save(false); if ($module->sendActivationMail) { $url = Url::to(array_merge($module->activationUrl, ["activkey" => $model->activkey, "email" => $model->email]), true); $activation_url = Html::a($url, $url); Module::sendMail($model->email, Module::t("{site_name} account activation", ['site_name' => Yii::$app->name]), 'register', ['activation_url' => $activation_url]); } if (($module->loginNotActiv || $module->activeAfterRegister && $module->sendActivationMail == false) && $module->autoLogin) { Yii::$app->user->login($model); $this->redirect($module->returnUrl); } else { if (!$module->activeAfterRegister && !$module->sendActivationMail) { Yii::$app->user->setFlash('success', Module::t("Thank you for your registration. Contact Admin to activate your account.")); } elseif ($module->activeAfterRegister && $module->sendActivationMail == false) { Yii::$app->user->setFlash('success', Module::t("Thank you for your registration. Please {{login}}.", ['{{login}}' => Html::a(Module::t('Login'), $module->loginUrl)])); } elseif ($module->loginNotActiv) { Yii::$app->user->setFlash('success', Module::t("Thank you for your registration. Please check your email or login.")); } else { Yii::$app->user->setFlash('success', Module::t("Thank you for your registration. Please check your email.")); } return $this->refresh(); } } } else { $profile->validate(); } } return $this->render('/user/registration', ['model' => $model, 'profile' => $profile]); } }