• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP User\Module类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中App\Modules\User\Module的典型用法代码示例。如果您正苦于以下问题:PHP Module类的具体用法?PHP Module怎么用?PHP Module使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Module类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: run

 public function run()
 {
     $request = Yii::$app->request;
     $user = Yii::createObject($this->modelClass, ['scenario' => $this->scenario]);
     $profile = Yii::createObject($this->profileClass);
     $roles = [];
     if ($this->roleArray !== null) {
         $roles = call_user_func($this->roleArray, $this);
     }
     $roleArray = ArrayHelper::map($roles, 'name', 'description');
     $statusArray = [];
     if ($this->statusArray !== null) {
         $statusArray = call_user_func($this->statusArray, $this);
     }
     if ($user->load($request->post()) && $profile->load($request->post())) {
         if ($user->validate() && $profile->validate()) {
             $user->populateRelation('profile', $profile);
             if ($user->save(false)) {
                 $this->trigger('success', new Event(['data' => $user]));
                 return $this->controller->redirect(Url::to([$this->updateRoute, 'id' => $user->id]));
             } else {
                 $this->trigger('success', new Event(['data' => Module::t('admin', 'Failed create user')]));
                 return $this->controller->refresh();
             }
         } elseif ($request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return array_merge(ActiveForm::validate($user), ActiveForm::validate($profile));
         }
     }
     return $this->render(compact(['user', 'profile', 'roleArray', 'statusArray']));
 }
开发者ID:artkost,项目名称:yii2-starter-kit,代码行数:31,代码来源:CreateAction.php


示例2: signup

 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->status = User::STATUS_WAIT;
         $user->generateAuthKey();
         $user->generateEmailConfirmToken();
         if ($user->save()) {
             $auth = Yii::$app->authManager;
             $userRoleDefault = $auth->getRole('user');
             $auth->assign($userRoleDefault, $user->getId());
             $userProfile = new Profile();
             $userProfile->user_id = $user->getId();
             $userProfile->user_agent = Yii::$app->request->getUserAgent();
             $userProfile->user_ip = Yii::$app->request->getUserIP();
             $userProfile->name = $user->username;
             $userProfile->avatar_id = 1;
             //default.png (id = 1)
             $userProfile->save(false);
             Yii::$app->mailer->compose(['text' => '@app/modules/user/mails/emailConfirm'], ['user' => $user])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name . ' robot'])->setTo($this->email)->setSubject(Module::t('app', 'EMAIL_SIGNUP_SUBJECT') . Yii::$app->name)->send();
         }
         return $user;
     }
     return null;
 }
开发者ID:knyazushka,项目名称:z34lot.new,代码行数:28,代码来源:SignupForm.php


示例3: actionInit

 /**
  * Create php file for rbac directory
  * Set directory config common.php
  * section components authManager
  */
 public function actionInit()
 {
     $auth = Yii::$app->authManager;
     $auth->removeAll();
     //удаляем старые данные
     //Создадим права доступа к управлению пользователями
     $blog = $auth->createPermission('manageUsers');
     $blog->description = Module::t('module', 'RBAC_MANAGE_USERS');
     $auth->add($blog);
     //Включаем наш обработчик
     $rule = new UserRoleRule();
     $auth->add($rule);
     //Добавляем роли
     $user = $auth->createRole('user');
     $user->description = Module::t('module', 'USER_ROLE_USER');
     $user->ruleName = $rule->name;
     $auth->add($user);
     $moder = $auth->createRole('moder');
     $moder->description = Module::t('module', 'USER_ROLE_MODERATOR');
     $moder->ruleName = $rule->name;
     $auth->add($moder);
     //Добавляем потомков
     $auth->addChild($moder, $user);
     $auth->addChild($moder, $blog);
     $admin = $auth->createRole('admin');
     $admin->description = Module::t('module', 'USER_ROLE_ADMINISTRATOR');
     $admin->ruleName = $rule->name;
     $auth->add($admin);
     $auth->addChild($admin, $moder);
 }
开发者ID:Dominus77,项目名称:yii2-basic-start,代码行数:35,代码来源:RbacController.php


示例4: isValidToken

 /**
  * Check if token is valid.
  *
  * @return boolean true if token is valid
  */
 public function isValidToken()
 {
     if (SecurityHelper::isValidToken($this->token, Module::param('recoveryWithin', false)) === true) {
         return ($this->_user = User::findByToken($this->token, 'active')) !== null;
     }
     return false;
 }
开发者ID:artkost,项目名称:yii2-starter-kit,代码行数:12,代码来源:RecoveryConfirmation.php


示例5: validateOldPassword

 /**
  * Validates the password.
  * This method serves as the inline validation for password.
  */
 public function validateOldPassword($attribute, $params)
 {
     $user = $this->getUser();
     if (!$user || !$user->validatePassword($this->{$attribute})) {
         $this->addError($attribute, Module::t('model', 'Invalid old password'));
     }
 }
开发者ID:artkost,项目名称:yii2-starter-kit,代码行数:11,代码来源:Password.php


示例6: run

 /**
  * Sign Up page.
  * If record will be successful created, user will be redirected to home page.
  */
 public function run()
 {
     $user = Yii::createObject($this->modelClass, ['scenario' => 'signup']);
     $profile = Yii::createObject($this->profileClass);
     $post = Yii::$app->request->post();
     if ($user->load($post) && $profile->load($post)) {
         if ($user->validate() && $profile->validate()) {
             $user->populateRelation('profile', $profile);
             if ($user->save(false)) {
                 if (Module::param('requireEmailConfirmation', false)) {
                     $this->trigger('success', new Event(['data' => Module::t('model', 'Your account has been created successfully. An email has been sent to you with detailed instructions.', ['url' => Url::to($this->resendRoute)])]));
                 } else {
                     Yii::$app->user->login($user);
                     $this->trigger('success', new Event(['data' => Module::t('model', 'Your account has been created successfully.')]));
                 }
                 return $this->controller->goHome();
             } else {
                 $this->trigger('danger', new Event(['data' => Module::t('model', 'Create account failed. Please try again later.')]));
                 return $this->controller->refresh();
             }
         } elseif (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return array_merge(ActiveForm::validate($user), ActiveForm::validate($profile));
         }
     }
     return $this->render(compact('user', 'profile'));
 }
开发者ID:artkost,项目名称:yii2-starter-kit,代码行数:31,代码来源:SignupAction.php


示例7: actionCreate

 public function actionCreate()
 {
     $username = $this->prompt(Module::t('console', 'Username:'));
     $email = $this->prompt(Module::t('console', 'Email:'));
     $password = $this->prompt(Module::t('console', 'Password:'));
     $name = $this->prompt(Module::t('console', 'First Name:'));
     $surname = $this->prompt(Module::t('console', 'Last Name:'));
     $sex = $this->confirm(Module::t('console', 'Male ?'), 1);
     if ($username && $email && $password) {
         $user = $this->insertUser($username, $email, $password);
         $id = $user->id;
         $this->stdout('Added user with:' . PHP_EOL);
         $this->stdout('ID:', Console::FG_GREY);
         $this->stdout($id . PHP_EOL, Console::FG_YELLOW);
         $this->stdout('Username:', Console::FG_GREY);
         $this->stdout($username . PHP_EOL, Console::FG_YELLOW);
         $this->stdout('Email:', Console::FG_GREY);
         $this->stdout($email . PHP_EOL, Console::FG_YELLOW);
         $this->stdout('Password:', Console::FG_GREY);
         $this->stdout($password . PHP_EOL, Console::FG_YELLOW);
         if ($id && $name && $surname && $sex) {
             $this->insertProfile($id, $name, $surname, $sex);
         }
     }
 }
开发者ID:artkost,项目名称:yii2-starter-kit,代码行数:25,代码来源:ManagerController.php


示例8: recovery

 /**
  * Send a recovery password token.
  *
  * @return boolean true if recovery token was successfully sent
  */
 public function recovery()
 {
     $this->_model = User::findByEmail($this->email, 'active');
     if ($this->_model !== null) {
         return Module::sendRecoveryEmail($this->_model);
     }
     return false;
 }
开发者ID:artkost,项目名称:yii2-starter-kit,代码行数:13,代码来源:Recovery.php


示例9: validatePassword

 /**
  * @param string $attribute
  * @param array $params
  */
 public function validatePassword($attribute, $params)
 {
     if (!$this->hasErrors()) {
         if (!$this->_user->validatePassword($this->{$attribute})) {
             $this->addError($attribute, Module::t('module', 'ERROR_WRONG_CURRENT_PASSWORD'));
         }
     }
 }
开发者ID:oke11o,项目名称:seokeys,代码行数:12,代码来源:PasswordChangeForm.php


示例10: validateIsSent

 /**
  * @param string $attribute
  * @param array $params
  */
 public function validateIsSent($attribute, $params)
 {
     if (!$this->hasErrors() && ($user = $this->getUser())) {
         if (User::isPasswordResetTokenValid($user->{$attribute}, $this->_timeout)) {
             $this->addError($attribute, Module::t('module', 'ERROR_TOKEN_IS_SENT'));
         }
     }
 }
开发者ID:AntonBeletsky,项目名称:seokeys,代码行数:12,代码来源:PasswordResetRequestForm.php


示例11: validatePassword

 /**
  * Validates the password.
  * This method serves as the inline validation for password.
  *
  * @param string $attribute the attribute currently being validated
  * @param array $params the additional name-value pairs given in the rule
  */
 public function validatePassword($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $user = $this->getUser();
         if (!$user || !$user->validatePassword($this->password)) {
             $this->addError($attribute, Module::t('module', 'ERROR_WRONG_LOGIN_OR_PASSWORD'));
         }
     }
 }
开发者ID:MaratCrash,项目名称:3dligatest,代码行数:16,代码来源:LoginForm.php


示例12: run

 /**
  * Activate a new user page.
  *
  * @param string $token Activation token.
  *
  * @return mixed View
  */
 public function run($token)
 {
     $model = Yii::createObject($this->modelClass, ['token' => $token]);
     if ($model->validate() && $model->activate()) {
         $this->trigger('success', new Event(['data' => Module::t('model', 'You successfully activated your account.')]));
     } else {
         $this->trigger('danger', new Event(['data' => Module::t('model', 'Account activation failed.')]));
     }
     return $this->controller->goHome();
 }
开发者ID:artkost,项目名称:yii2-starter-kit,代码行数:17,代码来源:ActivationAction.php


示例13: sendEmail

 /**
  * Sends an email with a link, for resetting the password.
  *
  * @return boolean whether the email was send
  */
 public function sendEmail()
 {
     if ($user = $this->getUser()) {
         $user->generatePasswordResetToken();
         if ($user->save()) {
             return Yii::$app->mailer->compose(['text' => '@app/modules/user/mails/passwordReset'], ['user' => $user])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name . ' robot'])->setTo($this->email)->setSubject(Module::t('module', 'PASSWORD_RESET_FOR {appName}', ['appName' => Yii::$app->name]))->send();
         }
     }
     return false;
 }
开发者ID:Dominus77,项目名称:blog,代码行数:15,代码来源:PasswordResetRequestForm.php


示例14: __construct

 /**
  * Creates a form model given a token.
  *
  * @param  string $token
  * @param  array $config
  * @throws \yii\base\InvalidParamException if token is empty or not valid
  */
 public function __construct($token, $config = [])
 {
     if (empty($token) || !is_string($token)) {
         throw new InvalidParamException(Module::t('app', 'EMAIL_CONFIRM_CONSTRUCT_BLANK_OR_STRING_TOKEN'));
     }
     $this->_user = User::findByEmailConfirmToken($token);
     if (!$this->_user) {
         throw new InvalidParamException(Module::t('app', 'EMAIL_CONFIRM_CONSTRUCT_WRONG_TOKEN'));
     }
     parent::__construct($config);
 }
开发者ID:knyazushka,项目名称:z34lot.new,代码行数:18,代码来源:EmailConfirmForm.php


示例15: actionPassword

 public function actionPassword()
 {
     $user = $this->findModel();
     $model = new PasswordChangeForm($user);
     if ($model->load(Yii::$app->request->post()) && $model->changePassword()) {
         Yii::$app->getSession()->setFlash('success', Module::t('app', 'FLASH_PASSWORD_CHANGE_SUCCESS'));
         return $this->redirect(['index']);
     } else {
         return $this->render('password', ['model' => $model]);
     }
 }
开发者ID:knyazushka,项目名称:z34lot.new,代码行数:11,代码来源:ProfileController.php


示例16: actionPasswordReset

 public function actionPasswordReset()
 {
     $model = new PasswordResetForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->resetPasword()) {
             Yii::$app->getSession()->setFlash('success', Module::t('module', 'FLASH_PASSWORD_RESET_EMAIL'));
             return $this->goHome();
         } else {
             Yii::$app->getSession()->setFlash('error', Module::t('module', 'FLASH_PASSWORD_RESET_ERROR'));
         }
     }
     return $this->render('passwordReset', ['model' => $model]);
 }
开发者ID:MaratCrash,项目名称:3dligatest,代码行数:13,代码来源:DefaultController.php


示例17: validatePassword

 /**
  * Validates the username and password.
  * This method serves as the inline validation for password.
  */
 public function validatePassword()
 {
     if (!$this->hasErrors()) {
         $user = $this->getUser();
         if (!$user || !$user->validatePassword($this->password)) {
             $this->addError('password', Module::t('module', 'ERROR_WRONG_USERNAME_OR_PASSWORD'));
         } elseif ($user && $user->status == User::STATUS_BLOCKED) {
             $this->addError('username', Module::t('module', 'ERROR_PROFILE_BLOCKED'));
         } elseif ($user && $user->status == User::STATUS_WAIT) {
             $this->addError('username', Module::t('module', 'ERROR_PROFILE_NOT_CONFIRMED'));
         }
     }
 }
开发者ID:Dominus77,项目名称:blog,代码行数:17,代码来源:LoginForm.php


示例18: actionActivate

 public function actionActivate($token)
 {
     try {
         $model = new EmailConfirmForm($token);
     } catch (InvalidParamException $e) {
         throw new BadRequestHttpException($e->getMessage());
     }
     if ($model->confirmEmail()) {
         Yii::$app->getSession()->setFlash('success', Module::t('app', 'FLASH_ACTIVATE_TRUE'));
     } else {
         Yii::$app->getSession()->setFlash('error', Module::t('app', 'FLASH_ACTIVATE_FALSE'));
     }
     return $this->goHome();
 }
开发者ID:knyazushka,项目名称:z34lot.new,代码行数:14,代码来源:SecureController.php


示例19: signup

 /**
  * 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->status = User::STATUS_WAIT;
         $user->generateAuthKey();
         $user->generateEmailConfirmToken();
         if ($user->save()) {
             Yii::$app->mailer->compose(['text' => '@app/modules/user/mails/emailConfirm'], ['user' => $user])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name])->setTo($this->email)->setSubject(Module::t('module', 'EMAIL_CONFIRMATION_FOR {appName}', ['appName' => Yii::$app->name]))->send();
         }
         return $user;
     }
     return null;
 }
开发者ID:Dominus77,项目名称:blog,代码行数:22,代码来源:SignupForm.php


示例20: actionUpdate

 /**
  * Update user page.
  *
  * @param integer $id User ID
  *
  * @return mixed View
  */
 public function actionUpdate($id)
 {
     $user = $this->findModel($id);
     $user->setScenario('admin-update');
     $profile = $user->profile;
     $statusArray = User::statusLabels();
     if ($user->load(Yii::$app->request->post()) && $profile->load(Yii::$app->request->post())) {
         if ($user->validate() && $profile->validate()) {
             $user->populateRelation('profile', $profile);
             if (!$user->save(false)) {
                 Yii::$app->session->setFlash('danger', Module::t('admin', 'Failed update user'));
             }
             return $this->refresh();
         } elseif (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return array_merge(ActiveForm::validate($user), ActiveForm::validate($profile));
         }
     }
     return $this->render('update', ['user' => $user, 'profile' => $profile, 'roleArray' => [], 'statusArray' => $statusArray]);
 }
开发者ID:artkost,项目名称:yii2-starter-kit,代码行数:27,代码来源:PeopleController.php



注:本文中的App\Modules\User\Module类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP models\User类代码示例发布时间:2022-05-23
下一篇:
PHP models\Product类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap