当前位置: 首页>>代码示例>>PHP>>正文


PHP User::save方法代码示例

本文整理汇总了PHP中bizley\podium\models\User::save方法的典型用法代码示例。如果您正苦于以下问题:PHP User::save方法的具体用法?PHP User::save怎么用?PHP User::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bizley\podium\models\User的用法示例。


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

示例1: _addAdmin

 /**
  * Adds Administrator account.
  * @return string result message.
  */
 protected function _addAdmin()
 {
     try {
         $podium = PodiumModule::getInstance();
         if ($podium->userComponent == PodiumModule::USER_INHERIT) {
             if (!empty($podium->adminId)) {
                 $this->authManager->assign($this->authManager->getRole('podiumAdmin'), $podium->adminId);
                 return $this->outputSuccess(Yii::t('podium/flash', Messages::ADMINISTRATOR_PRIVILEGES_SET, ['id' => $podium->adminId]));
             } else {
                 return $this->outputWarning(Yii::t('podium/flash', Messages::NO_ADMINISTRATOR_PRIVILEGES_SET));
             }
         } else {
             $admin = new User();
             $admin->setScenario('installation');
             $admin->username = self::DEFAULT_USERNAME;
             $admin->email = self::DEFAULT_USER_EMAIL;
             $admin->status = User::STATUS_ACTIVE;
             $admin->role = User::ROLE_ADMIN;
             $admin->generateAuthKey();
             $admin->setPassword(self::DEFAULT_USERNAME);
             if ($admin->save()) {
                 $this->authManager->assign($this->authManager->getRole('podiumAdmin'), $admin->getId());
                 return $this->outputSuccess(Yii::t('podium/flash', Messages::ADMINISTRATOR_ACCOUNT_CREATED) . ' ' . Html::tag('strong', Yii::t('podium/flash', 'Login') . ':') . ' ' . Html::tag('kbd', self::DEFAULT_USERNAME) . ' ' . Html::tag('strong', Yii::t('podium/flash', 'Password') . ':') . ' ' . Html::tag('kbd', self::DEFAULT_USERNAME));
             } else {
                 $this->setError(true);
                 return $this->outputDanger(Yii::t('podium/flash', Messages::ACCOUNT_CREATING_ERROR) . ': ' . Html::tag('pre', VarDumper::dumpAsString($admin->getErrors())));
             }
         }
     } catch (Exception $e) {
         Yii::error([$e->getName(), $e->getMessage()], __METHOD__);
         $this->setError(true);
         return $this->outputDanger(Yii::t('podium/flash', Messages::ACCOUNT_CREATING_ERROR) . ': ' . Html::tag('pre', $e->getMessage()));
     }
 }
开发者ID:keltstr,项目名称:yii2-podium,代码行数:38,代码来源:Installation.php

示例2: init

 /**
  * Creates inherited user account.
  */
 public function init()
 {
     parent::init();
     if (!Yii::$app->user->isGuest) {
         if (PodiumModule::getInstance()->userComponent == PodiumModule::USER_INHERIT) {
             $user = User::findMe();
             if (empty($user)) {
                 $new = new User();
                 $new->setScenario('installation');
                 $new->inherited_id = Yii::$app->user->id;
                 $new->status = User::STATUS_ACTIVE;
                 $new->role = User::ROLE_MEMBER;
                 $new->timezone = User::DEFAULT_TIMEZONE;
                 if ($new->save()) {
                     $this->success(Yii::t('podium/flash', Messages::ACCOUNT_INHERITED, ['link' => Html::a(Yii::t('podium/layout', 'Profile'))]));
                     Cache::clearAfterActivate();
                     Log::info('Inherited account created', $new->id, __METHOD__);
                 } else {
                     throw new Exception(Yii::t('podium/view', Messages::ACCOUNT_INHERITED_ERROR));
                 }
             } elseif ($user->status == User::STATUS_BANNED) {
                 return $this->redirect(['default/ban']);
             }
         } else {
             $user = Yii::$app->user->identity;
         }
         if ($user && !empty($user->timezone)) {
             Yii::$app->formatter->timeZone = $user->timezone;
         }
     }
 }
开发者ID:Avenger1,项目名称:yii2-podium,代码行数:34,代码来源:BaseController.php

示例3: _addAdmin

 /**
  * Adds Administrator account.
  * @return string result message.
  */
 protected function _addAdmin()
 {
     try {
         $podium = PodiumModule::getInstance();
         if ($podium->userComponent == PodiumModule::USER_INHERIT) {
             if (!empty($podium->adminId)) {
                 $admin = new User();
                 $admin->setScenario('installation');
                 $admin->inherited_id = $podium->adminId;
                 $admin->username = self::DEFAULT_USERNAME;
                 $admin->status = User::STATUS_ACTIVE;
                 $admin->role = User::ROLE_ADMIN;
                 $admin->timezone = User::DEFAULT_TIMEZONE;
                 if ($admin->save()) {
                     $this->authManager->assign($this->authManager->getRole(Rbac::ROLE_ADMIN), $podium->adminId);
                     return $this->outputSuccess(Yii::t('podium/flash', 'Administrator privileges have been set for the user of ID {id}.', ['id' => $podium->adminId]));
                 } else {
                     $this->setError(true);
                     return $this->outputDanger(Yii::t('podium/flash', 'Error during account creating') . ': ' . Html::tag('pre', VarDumper::dumpAsString($admin->getErrors())));
                 }
             } else {
                 return $this->outputWarning(Yii::t('podium/flash', 'No administrator privileges have been set.'));
             }
         } else {
             $admin = new User();
             $admin->setScenario('installation');
             $admin->username = self::DEFAULT_USERNAME;
             $admin->status = User::STATUS_ACTIVE;
             $admin->role = User::ROLE_ADMIN;
             $admin->timezone = User::DEFAULT_TIMEZONE;
             $admin->generateAuthKey();
             $admin->setPassword(self::DEFAULT_USERNAME);
             if ($admin->save()) {
                 $this->authManager->assign($this->authManager->getRole(Rbac::ROLE_ADMIN), $admin->getId());
                 return $this->outputSuccess(Yii::t('podium/flash', 'Administrator account has been created.') . ' ' . Html::tag('strong', Yii::t('podium/flash', 'Login') . ':') . ' ' . Html::tag('kbd', self::DEFAULT_USERNAME) . ' ' . Html::tag('strong', Yii::t('podium/flash', 'Password') . ':') . ' ' . Html::tag('kbd', self::DEFAULT_USERNAME));
             } else {
                 $this->setError(true);
                 return $this->outputDanger(Yii::t('podium/flash', 'Error during account creating') . ': ' . Html::tag('pre', VarDumper::dumpAsString($admin->getErrors())));
             }
         }
     } catch (Exception $e) {
         Yii::error([$e->getName(), $e->getMessage()], __METHOD__);
         $this->setError(true);
         return $this->outputDanger(Yii::t('podium/flash', 'Error during account creating') . ': ' . Html::tag('pre', $e->getMessage()));
     }
 }
开发者ID:aekkapun,项目名称:yii2-podium,代码行数:50,代码来源:Installation.php

示例4: createInheritedAccount

 /**
  * Creates inherited account.
  * @return boolean
  * @since 0.2
  */
 public static function createInheritedAccount()
 {
     try {
         if (!Yii::$app->user->isGuest) {
             $new = new User();
             $new->scenario = 'installation';
             $new->inherited_id = Yii::$app->user->id;
             $new->status = self::STATUS_ACTIVE;
             $new->role = self::ROLE_MEMBER;
             $new->timezone = self::DEFAULT_TIMEZONE;
             if (!$new->save()) {
                 throw new Exception('Account creating error');
             }
             Yii::$app->authManager->assign(Yii::$app->authManager->getRole(Rbac::ROLE_USER), $new->id);
             Cache::clearAfter('activate');
             Log::info('Inherited account created', $new->id, __METHOD__);
             return true;
         }
     } catch (Exception $e) {
         Log::error($e->getMessage(), null, __METHOD__);
     }
     return false;
 }
开发者ID:pezisc,项目名称:yii2-podium,代码行数:28,代码来源:User.php

示例5: init

 /**
  * Creates inherited user account.
  */
 public function init()
 {
     parent::init();
     if (!Yii::$app->user->isGuest) {
         if (PodiumModule::getInstance()->userComponent == PodiumModule::USER_INHERIT) {
             $user = User::findMe();
             if (empty($user)) {
                 $new = new User();
                 $new->setScenario('installation');
                 $new->inherited_id = Yii::$app->user->id;
                 $new->status = User::STATUS_ACTIVE;
                 $new->role = User::ROLE_MEMBER;
                 $new->timezone = User::DEFAULT_TIMEZONE;
                 if ($new->save()) {
                     $this->success(Yii::t('podium/flash', 'Hey! Your new forum account has just been automatically created! Go to {link} to complement it.', ['link' => Html::a(Yii::t('podium/view', 'Profile'))]));
                     Cache::clearAfterActivate();
                     Log::info('Inherited account created', $new->id, __METHOD__);
                 } else {
                     throw new Exception(Yii::t('podium/view', 'There was an error while creating inherited user account. Podium can not run with the current configuration. Please contact administrator about this problem.'));
                 }
             } elseif ($user->status == User::STATUS_BANNED) {
                 return $this->redirect(['default/ban']);
             }
         } else {
             $user = Yii::$app->user->identity;
         }
         if ($user && !empty($user->timezone)) {
             Yii::$app->formatter->timeZone = $user->timezone;
         }
     }
 }
开发者ID:gitter-badger,项目名称:yii2-podium,代码行数:34,代码来源:BaseController.php


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