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


PHP User::findOne方法代码示例

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


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

示例1: afterSave

 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     if ($this->scenario == self::SCENARIO_EDIT) {
         $managerGuids = explode(",", $this->managerGuids);
         foreach ($managerGuids as $managerGuid) {
             // Ensure guids valid characters
             $managerGuid = preg_replace("/[^A-Za-z0-9\\-]/", '', $managerGuid);
             // Try to load user and get/create the GroupUser relation with isManager
             $user = \humhub\modules\user\models\User::findOne(['guid' => $managerGuid]);
             if ($user != null) {
                 $groupUser = GroupUser::findOne(['group_id' => $this->id, 'user_id' => $user->id]);
                 if ($groupUser != null && !$groupUser->is_group_manager) {
                     $groupUser->is_group_manager = true;
                     $groupUser->save();
                 } else {
                     $this->addUser($user, true);
                 }
             }
         }
         //Remove admins not contained in the selection
         foreach ($this->getManager()->all() as $admin) {
             if (!in_array($admin->guid, $managerGuids)) {
                 $groupUser = GroupUser::findOne(['group_id' => $this->id, 'user_id' => $admin->id]);
                 if ($groupUser != null) {
                     $groupUser->is_group_manager = false;
                     $groupUser->save();
                 }
             }
         }
     }
     parent::afterSave($insert, $changedAttributes);
 }
开发者ID:VasileGabriel,项目名称:humhub,代码行数:35,代码来源:Group.php

示例2: actionEdit

 /** 
  * Edit a karma record
  */
 public function actionEdit()
 {
     $id = (int) Yii::$app->request->get('id');
     $user = User::findOne(['id' => $id]);
     $karma = Karma::findOne(['id' => $id]);
     if ($karma == null) {
         throw new \yii\web\HttpException(404, "Karma record not found!");
     }
     // Build Form Definition
     $definition = array();
     $definition['elements'] = array();
     // Define Form Eleements
     $definition['elements']['Karma'] = array('type' => 'form', 'title' => 'Karma', 'elements' => array('name' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'points' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 10), 'description' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 1000)));
     // Get Form Definition
     $definition['buttons'] = array('save' => array('type' => 'submit', 'label' => 'Save', 'class' => 'btn btn-primary'), 'delete' => array('type' => 'submit', 'label' => 'Delete', 'class' => 'btn btn-danger'));
     $form = new HForm($definition);
     $form->models['Karma'] = $karma;
     if ($form->submitted('save') && $form->validate()) {
         if ($form->save()) {
             return $this->redirect(Url::toRoute(['edit', 'id' => $karma->id]));
         }
     }
     if ($form->submitted('delete')) {
         return $this->redirect(Url::toRoute(['delete', 'id' => $karma->id]));
     }
     return $this->render('edit', array('hForm' => $form));
 }
开发者ID:ConnectedCommunities,项目名称:humhub-modules-karma,代码行数:30,代码来源:AdminController.php

示例3: Get

 /**
  * Gets a user setting
  * 
  * @see \humhub\modules\content\components\ContentContainerSettingsManager::get
  * @param int $userId
  * @param string $name
  * @param string $moduleId
  * @param string $defaultValue
  * @return string the value
  */
 public static function Get($userId, $name, $moduleId = "", $defaultValue = "")
 {
     $user = User::findOne(['id' => $userId]);
     $value = self::getModule($moduleId)->settings->contentContainer($user)->get($name);
     if ($value === null) {
         return $defaultValue;
     }
     return $value;
 }
开发者ID:kreativmind,项目名称:humhub,代码行数:19,代码来源:Setting.php

示例4: actionPopup

 /**
  * Returns an list of all friends of a user
  */
 public function actionPopup()
 {
     $user = User::findOne(['id' => Yii::$app->request->get('userId')]);
     if ($user === null) {
         throw new \yii\web\HttpException(404, 'Could not find user!');
     }
     $query = Friendship::getFriendsQuery($user);
     $title = '<strong>' . Yii::t('FriendshipModule.base', "Friends") . '</strong>';
     return $this->renderAjaxContent(UserListBox::widget(['query' => $query, 'title' => $title]));
 }
开发者ID:VasileGabriel,项目名称:humhub,代码行数:13,代码来源:ListController.php

示例5: actionDelete

 /**
  * Declines or Deletes Friendship
  */
 public function actionDelete()
 {
     $this->forcePostRequest();
     $friend = User::findOne(['id' => Yii::$app->request->get('userId')]);
     if ($friend === null) {
         throw new \yii\web\HttpException(404, 'User not found!');
     }
     Friendship::cancel(Yii::$app->user->getIdentity(), $friend);
     return $this->redirect($friend->getUrl());
 }
开发者ID:VasileGabriel,项目名称:humhub,代码行数:13,代码来源:RequestController.php

示例6: getUrlByUserGuid

 /**
  * Gets usernameby given guid
  * 
  * @param string $guid
  * @return string|null the username
  */
 public static function getUrlByUserGuid($guid)
 {
     if (isset(static::$userUrlMap[$guid])) {
         return static::$userUrlMap[$guid];
     }
     $user = User::findOne(['guid' => $guid]);
     if ($user !== null) {
         static::$userUrlMap[$user->guid] = $user->username;
         return static::$userUrlMap[$user->guid];
     }
     return null;
 }
开发者ID:VasileGabriel,项目名称:humhub,代码行数:18,代码来源:UrlRule.php

示例7: getUser

 public function getUser()
 {
     if ($this->user != null) {
         return $this->user;
     }
     $guid = Yii::$app->request->getQuery('uguid');
     $this->user = User::findOne(['guid' => $guid]);
     if ($this->user == null) {
         throw new HttpException(404, Yii::t('UserModule.behaviors_ProfileControllerBehavior', 'User not found!'));
     }
     $this->checkAccess();
     return $this->user;
 }
开发者ID:VasileGabriel,项目名称:humhub,代码行数:13,代码来源:ProfileController.php

示例8: getUserByAuthClient

 /**
  * Returns the user object which is linked against given authClient
  * 
  * @param ClientInterface $authClient the authClient
  * @return User the user model or null if not found
  */
 public static function getUserByAuthClient(ClientInterface $authClient)
 {
     $attributes = $authClient->getUserAttributes();
     if ($authClient instanceof interfaces\PrimaryClient) {
         /**
          * @var interfaces\PrimaryClient $authClient
          */
         return User::findOne([$authClient->getUserTableIdAttribute() => $attributes['id'], 'auth_mode' => $authClient->getId()]);
     }
     $auth = Auth::find()->where(['source' => $authClient->getId(), 'source_id' => $attributes['id']])->one();
     if ($auth !== null) {
         return $auth->user;
     }
 }
开发者ID:kreativmind,项目名称:humhub,代码行数:20,代码来源:AuthClientHelpers.php

示例9: recover

 /**
  * Sends this user a new password by E-Mail
  *
  */
 public function recover()
 {
     $user = User::findOne(array('email' => $this->email));
     // Switch to users language - if specified
     if ($user->language !== "") {
         Yii::$app->language = $user->language;
     }
     $token = \humhub\libs\UUID::v4();
     Yii::$app->getModule('user')->settings->contentContainer($user)->set('passwordRecoveryToken', $token . '.' . time());
     $mail = Yii::$app->mailer->compose(['html' => '@humhub/modules/user/views/mails/RecoverPassword', 'text' => '@humhub/modules/user/views/mails/plaintext/RecoverPassword'], ['user' => $user, 'linkPasswordReset' => Url::to(["/user/password-recovery/reset", 'token' => $token, 'guid' => $user->guid], true)]);
     $mail->setFrom([Yii::$app->settings->get('mailer.systemEmailAddress') => Yii::$app->settings->get('mailer.systemEmailName')]);
     $mail->setTo($user->email);
     $mail->setSubject(Yii::t('UserModule.forms_AccountRecoverPasswordForm', 'Password Recovery'));
     $mail->send();
     return true;
 }
开发者ID:VasileGabriel,项目名称:humhub,代码行数:20,代码来源:AccountRecoverPassword.php

示例10: checkEmails

 /**
  * Checks a comma separated list of e-mails which should invited.
  * E-Mails needs to be valid and not already registered.
  *
  * @param string $attribute
  * @param array $params
  */
 public function checkEmails($attribute, $params)
 {
     if ($this->{$attribute} != "") {
         foreach ($this->getEmails() as $email) {
             $validator = new \yii\validators\EmailValidator();
             if (!$validator->validate($email)) {
                 $this->addError($attribute, Yii::t('UserModule.invite', '{email} is not valid!', array("{email}" => $email)));
                 continue;
             }
             if (User::findOne(['email' => $email]) != null) {
                 $this->addError($attribute, Yii::t('UserModule.invite', '{email} is already registered!', array("{email}" => $email)));
                 continue;
             }
         }
     }
 }
开发者ID:VasileGabriel,项目名称:humhub,代码行数:23,代码来源:Invite.php

示例11: recover

 /**
  * Sends this user a new password by E-Mail
  *
  */
 public function recover()
 {
     $user = User::findOne(array('email' => $this->email));
     // Switch to users language - if specified
     if ($user->language !== "") {
         Yii::$app->language = $user->language;
     }
     $token = \humhub\libs\UUID::v4();
     $user->setSetting('passwordRecoveryToken', $token . '.' . time(), 'user');
     $mail = Yii::$app->mailer->compose(['html' => '@humhub/modules/user/views/mails/RecoverPassword'], ['user' => $user, 'linkPasswordReset' => Url::to(["/user/auth/reset-password", 'token' => $token, 'guid' => $user->guid], true)]);
     $mail->setFrom([\humhub\models\Setting::Get('systemEmailAddress', 'mailing') => \humhub\models\Setting::Get('systemEmailName', 'mailing')]);
     $mail->setTo($user->email);
     $mail->setSubject(Yii::t('UserModule.forms_AccountRecoverPasswordForm', 'Password Recovery'));
     $mail->send();
     return true;
 }
开发者ID:SimonBaeumer,项目名称:humhub,代码行数:20,代码来源:AccountRecoverPassword.php

示例12: actionReset

 /**
  * Resets users password based on given token
  */
 public function actionReset()
 {
     $user = User::findOne(array('guid' => Yii::$app->request->get('guid')));
     if ($user === null || !$this->checkPasswordResetToken($user, Yii::$app->request->get('token'))) {
         throw new HttpException('500', 'It looks like you clicked on an invalid password reset link. Please try again.');
     }
     $model = new Password();
     $model->scenario = 'registration';
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         Yii::$app->getModule('user')->settings->contentContainer($user)->delete('passwordRecoveryToken');
         $model->user_id = $user->id;
         $model->setPassword($model->newPassword);
         $model->save();
         return $this->render('reset_success');
     }
     return $this->render('reset', array('model' => $model));
 }
开发者ID:kreativmind,项目名称:humhub,代码行数:20,代码来源:PasswordRecoveryController.php

示例13: checkRecipient

 /**
  * Form Validator which checks the recipient field
  *
  * @param type $attribute
  * @param type $params
  */
 public function checkRecipient($attribute, $params)
 {
     // Check if email field is not empty
     if ($this->{$attribute} != "") {
         $recipients = explode(",", $this->{$attribute});
         foreach ($recipients as $userGuid) {
             $userGuid = preg_replace("/[^A-Za-z0-9\\-]/", '', $userGuid);
             // Try load user
             $user = User::findOne(['guid' => $userGuid]);
             if ($user != null) {
                 if ($user->id == Yii::$app->user->id) {
                     $this->addError($attribute, Yii::t('MailModule.forms_InviteRecipientForm', "You cannot send a email to yourself!"));
                 } else {
                     $this->recipients[] = $user;
                 }
             }
         }
     }
 }
开发者ID:kinderp,项目名称:humhub-modules-services,代码行数:25,代码来源:InviteRecipient.php

示例14: afterSave

 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     if ($this->scenario == 'edit') {
         \humhub\modules\user\models\GroupAdmin::deleteAll(['group_id' => $this->id]);
         $adminUsers = array();
         foreach (explode(",", $this->adminGuids) as $adminGuid) {
             // Ensure guids valid characters
             $adminGuid = preg_replace("/[^A-Za-z0-9\\-]/", '', $adminGuid);
             // Try load user
             $user = \humhub\modules\user\models\User::findOne(['guid' => $adminGuid]);
             if ($user != null) {
                 $groupAdmin = new GroupAdmin();
                 $groupAdmin->user_id = $user->id;
                 $groupAdmin->group_id = $this->id;
                 $groupAdmin->save();
             }
         }
     }
     parent::afterSave($insert, $changedAttributes);
 }
开发者ID:weison-tech,项目名称:humhub,代码行数:23,代码来源:Group.php

示例15: afterSave

 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     foreach (explode(",", $this->assignedUserGuids) as $userGuid) {
         $f = false;
         foreach ($this->assignedUsers as $user) {
             if ($user->guid == trim($userGuid)) {
                 $f = true;
             }
         }
         if ($f == false) {
             $this->assignUser(User::findOne(['guid' => trim($userGuid)]));
         }
     }
     foreach ($this->assignedUsers as $user) {
         if (strpos($this->assignedUserGuids, $user->guid) === false) {
             $this->unassignUser($user);
         }
     }
 }
开发者ID:pkdevboxy,项目名称:humhub-modules-tasks,代码行数:20,代码来源:Task.php


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