/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); $user->save(); return $user; } return null; }
/** * 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(); }
/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { /* @var $user User */ $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]); if ($user) { if (!User::isPasswordResetTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } $user->scenario = 'resetPassword'; if ($user->save()) { return \Yii::$app->mailer->compose('passwordResetToken', ['user' => $user])->setFrom([EMAIL_FROM_ADDRESS => EMAIL_FROM_NAME])->setTo($this->email)->setSubject('Password reset for ' . SITE_NAME)->send(); } } return false; }
public function actionDelete() { if (Yii::$app->request->isAjax) { $id = $_POST['id']; $model = User::find()->innerJoinWith('userDetail')->onCondition(['users.id' => $id])->one(); if (isset($model) && !empty($model)) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return $model->delete($id) && UserDetail::deleteAll(['user_id' => $id]) ? ['status' => 'success', 'recordDeleted' => DELETED] : ['status' => 'failure']; } } }
<?php return ['layoutPath' => dirname(__DIR__) . '/views/layouts/', 'components' => ['user' => ['identityClass' => 'vendor\\codefire\\cfusermgmt\\models\\User', 'enableAutoLogin' => true], 'authManager' => ['class' => 'yii\\rbac\\DbManager', 'defaultRoles' => [DEFAULT_ROLE_NAME]], 'custom' => ['class' => 'vendor\\codefire\\cfusermgmt\\components\\Custom']], 'params' => ['home_base_path' => __DIR__ . '/../../../../'], 'modules' => ['usermgmt' => ['class' => 'vendor\\codefire\\cfusermgmt\\Module']], 'aliases' => ['@cfusermgmt' => '@app/../vendor/codefire/cfusermgmt', '@cfusermgmtView' => '@vendor/codefire/cfusermgmt/views', "@cfusermgmtWeb" => "vendor/codefire/cfusermgmt/web", '@SITE_URL' => "Your Site url Goes Here"], 'on beforeAction' => function ($event) { vendor\codefire\cfusermgmt\models\UserActivity::actionSave($event); $permission = \vendor\codefire\cfusermgmt\models\User::CheckPermission($event); if (Yii::$app->user->isGuest && !$permission) { Yii::$app->session->setFlash("danger", FLASH_1041, true); Yii::$app->session->set("currentUrl", yii\helpers\Url::current()); header("location:" . yii\helpers\Url::home(true) . 'usermgmt/user/login'); exit; //return Yii::$app->controller->redirect(['/usermgmt/user/login']); } elseif (!$permission) { return Yii::$app->controller->redirect(['/usermgmt/user/permission-denied']); } $userRoleData = \vendor\codefire\cfusermgmt\models\AuthAssignment::find()->where(['user_id' => Yii::$app->user->getId()])->one(); if (in_array(Yii::$app->controller->module->id, array('usermgmt', 'content'))) { $setLayout =& Yii::$app->controller->module->module; } else { $setLayout =& Yii::$app->controller->module; } if (!empty($userRoleData)) { $userRoleName = $userRoleData->item_name; if (in_array($userRoleName, array(ADMIN_ROLE_ALIAS, SUPERADMIN_ROLE_ALIAS))) { $setLayout->layout = ADMIN_LAYOUT; } else { $setLayout->layout = DEFAULT_LAYOUT; } } else { $setLayout->layout = DEFAULT_LAYOUT; } }];
public static function getAvailableMaxBorrowAmount() { $max = 0; $type = User::find()->select('type')->where(['id' => \Yii::$app->user->getId()])->one(); if ($type->type == REGISTER_AS_INDIVIDUAL) { $max = REGISTER_AS_INDIVIDUAL_MAXLIMIT; } elseif ($type->type == REGISTER_AS_COMPANY) { $max = REGISTER_AS_COMPANY_MAXLIMIT; } return $max; }
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); } }
/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = User::findByUsername($this->username); } return $this->_user; }