/** * Resets password. * * @return boolean if password was reset. */ public function resetPassword() { $user = $this->_user; $user->password = $this->password; $user->scenario = 'resetPass'; $user->auth_key = User::generateNewAuthKey(); $user->password_hash = User::setNewPassword($this->password); $user->removePasswordResetToken(); //echo "<pre>";print_r($user);die; //Here we need to make a password hash string and then we will save ,,but pending due to wait for upload(as password mail will be sending only when site is live) return $user->save(); }
public function actionVerifyEmail($id = NULL, $token = NULL) { if (Yii::$app->request->isAjax) { $model = User::findOne($id); if (isset($model) && !empty($model)) { $model->email_verified = $model->email_verified == VERIFIED ? NOT_VERIFIED : VERIFIED; $model->scenario = 'emailVerification'; Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return $model->update() ? ['status' => 'success', 'recordEmailVerified' => $model->email_verified] : ['status' => 'failure']; } } else { $model = User::find()->onCondition(['id' => $id, 'auth_key' => $token])->one(); if (isset($model) && !empty($model)) { if ($model->email_verified != VERIFIED) { $model->scenario = 'emailVerification'; $model->email_verified = VERIFIED; $model->sms_token = NULL; $model->auth_key = User::generateNewAuthKey(); if ($model->update()) { Yii::$app->session->setFlash("success", FLASH_1026, true); } } else { Yii::$app->session->setFlash("danger", FLASH_1027, true); } } else { Yii::$app->session->setFlash("danger", FLASH_1028, true); } return $this->redirect(['/usermgmt/user/login']); } }
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); } }