public function actionSendVerifyEmail() { $model = Yii::$app->user->getIdentity(); if (!empty($model)) { if (User::sendMail('verifyEmail', $model, $model->email, 'Verify Your Email Address for - ' . SITE_NAME)) { $message = str_replace('%EMAIL%', $model->email, FLASH_1022); Yii::$app->session->setFlash('success', $message); return $this->redirect(['/usermgmt/user/my-profile']); } } else { $model = new User(); $model->scenario = "sendMail"; if ($model->load(Yii::$app->request->post()) && $model->validate()) { $userDetail = User::find()->where(["email" => $model->email])->one(); if (User::sendMail('verifyEmail', $userDetail, $userDetail->email, 'Verify Your Email Address for - ' . SITE_NAME)) { $message = str_replace('%EMAIL%', $userDetail->email, FLASH_1024); Yii::$app->session->setFlash('success', $message, true); } else { Yii::$app->session->setFlash('danger', "Email sending was not successful", true); } return $this->redirect(['/']); } return $this->render("send-verify-email", ["model" => $model]); } }
public function register() { if (NEW_REGISTRATION_IS_ALLOWED) { $modelDetail = new UserDetail(); $model = new User(); $model->scenario = 'addUser'; if ($model->load(Yii::$app->request->post())) { $file = \yii\web\UploadedFile::getInstance($model, 'img_path'); if (isset($file) && !empty($file)) { $filePath = USER_DIRECTORY_PATH . DS . USER_PROFILE_IMAGES_DIRECTORY . DS; $model->img_path = Yii::$app->custom->uploadFile($file, $filePath); } if ($model->validate()) { $model->auth_key = User::generateNewAuthKey(); $model->password_hash = User::setNewPassword($model->password); if (isset($model->phone_number)) { $model->phone_number = str_replace("-", "", $model->phone_number); } if (isset($model->dob)) { $model->dob = date("Y-m-d", strtotime($model->dob)); } if ($model->save(false)) { /** Associated Model linking ***/ $modelDetail->user_id = $model->id; $model->link("userDetail", $modelDetail); $userGroups = RoleAndPermission::find()->onCondition(['type' => '1'])->asArray()->all(); $roleNames = []; foreach ($userGroups as $userGroup) { $roleNames[] = $userGroup['name']; } if (in_array(DEFAULT_ROLE_NAME, $roleNames)) { $userRole = new AuthAssignment(); $userRole->item_name = DEFAULT_ROLE_NAME; $userRole->user_id = $model->id; } $model->link("userRole", $userRole); /** Associated Model linking ***/ if ($model->save(false)) { if (!SEND_REGISTRATION_MAIL) { User::sendMail('welcome-email', $model, $model->email, 'Welcome to - ' . SITE_NAME); } Yii::$app->session->setFlash('success', 'Please verify your Email. A verification link has been sent to your Email Address.'); return array('redirect' => true, 'url' => Url::to(['/usermgmt/user/login'])); } else { Yii::$app->session->setFlash('success', 'Your registration was not successful.'); return array('redirect' => true, 'url' => Yii::$app->homeUrl); } } } } return array('render' => "register", 'model' => $model); } else { Yii::$app->session->setFlash('danger', 'Currently new registrations are not allowed by administrator. Please try later.'); return array('redirect' => true, 'url' => Yii::$app->homeUrl); } }