本文整理汇总了PHP中common\models\User::findIdentity方法的典型用法代码示例。如果您正苦于以下问题:PHP User::findIdentity方法的具体用法?PHP User::findIdentity怎么用?PHP User::findIdentity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\User
的用法示例。
在下文中一共展示了User::findIdentity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionIndex
/**
* Lists all ApiLogs models.
* @return mixed
*/
public function actionIndex()
{
$user = User::findIdentity(Yii::$app->user->id);
$user->level == 1 ? $searchModel = new ApiLogsSearch() : ($searchModel = new UserApiLogsSearch());
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
}
示例2: signup
/**
* Signs user up.
*
* @return true|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate()) {
$user = new User();
$user->phone = $this->phone;
$user->email = $this->email;
$randLength = mt_rand(6, 9);
$this->password = Yii::$app->security->generateRandomString($randLength);
$user->setPassword($this->password);
$user->generateAuthKey();
if ($user->save()) {
$profile = new Profile();
$profile->user_id = $user->id;
$profile->name = $this->name;
//если в куках есть id аффилиата, сохраняем его
$affiliateId = (int) Yii::$app->request->cookies['affiliate'];
if ($affiliateId > 0 && User::findIdentity($affiliateId)) {
$profile->user_affiliate_id = $affiliateId;
}
$profile->save();
return $this->sendRegistrationEmail();
}
}
return null;
}
示例3: findPasswords
public function findPasswords($attribute, $params)
{
$user = User::findIdentity(Yii::$app->user->id);
if (!$user->validatePassword($this->currentPassword)) {
$this->addError($attribute, 'Old password is incorrect');
}
}
示例4: rules
public function rules()
{
return [[['password', 'email', 'title'], 'required', 'on' => self::SCENARIO_NEW], [['email', 'title'], 'required', 'on' => self::SCENARIO_EDIT], ['password', 'string', 'min' => Yii::$app->params['passLength']], ['password_repeat', 'compare', 'compareAttribute' => 'password', 'message' => Yii::t('app', "Passwords don't match")], [['ssid'], 'default', 'value' => helper::getSsid()], [['ssid', 'shop_id'], 'integer'], [['title'], 'string', 'max' => 100], [['description'], 'string', 'max' => 250], 'emailPattern' => ['email', 'email'], 'emailLength' => ['email', 'string', 'max' => 255], 'emailUniqueEdit' => ['email', function ($attribute) {
if (User::findByEmail($this->email)) {
$this->addError($attribute, $this->email . Yii::t('app', 'Email already exist'));
}
}, 'when' => function () {
$user = User::findByEmail($this->email);
if (!empty((array) $user)) {
return Yii::$app->user->id != $user->id;
// do not check for current user (my email)
}
}, 'on' => self::SCENARIO_EDIT], 'emailUniqueNew' => ['email', function ($attribute, $params) {
$user = User::findByEmail($this->{$attribute});
if (!empty((array) $user)) {
$this->addError($attribute, Yii::t('app', 'Email already exist'));
}
}, 'on' => self::SCENARIO_NEW], 'emailTrim' => ['email', 'trim'], 'oldPassCheck' => ['password_old', function ($attribute) {
$user = User::findIdentity($this->id);
if (!empty((array) $user)) {
if ($user->validatePassword($this->password_old)) {
$this->addError($attribute, Yii::t('app', 'Password Do not match'));
}
}
}, 'on' => self::SCENARIO_EDIT]];
}
示例5: searchTreeView
public function searchTreeView($params)
{
$user = User::findIdentity(Yii::$app->user->id);
$query = User::find();
$query->where('status != ' . User::STATUS_DELETED);
// $query->andwhere('id != '.Yii::$app->user->id);
$query->andwhere('referrer IS NULL OR referrer = "' . $user->code . '" ');
// if($params == null){
// $query->andwhere(['referrer'=>$user->code]);
//
// }
$dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC, 'first_name' => SORT_ASC]]]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
$query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['state' => $this->state, 'sex' => $this->sex, 'zip' => $this->zip, 'code' => $this->code, 'referrer' => $this->referrer, 'graduate_high_school' => $this->graduate_high_school]);
if ($this->status != null) {
$query->andFilterWhere(['status' => $this->status]);
}
$query->andFilterWhere(['like', 'first_name', $this->first_name])->orFilterWhere(['like', 'last_name', $this->first_name]);
$query->andFilterWhere(['like', 'email', $this->email]);
$query->andFilterWhere(['like', 'city', $this->city]);
$query->andFilterWhere(['like', 'mobile', $this->mobile]);
return $dataProvider;
}
示例6: actionIndex
public function actionIndex($id)
{
$user = User::findIdentity($id);
$comments = Comment::getRecentComments();
$sidebarCategories = Category::getSidebarCategories();
$tags = Tag::getTagList();
return $this->render('index', ['user' => $user, 'comments' => $comments, 'sidebarCategories' => $sidebarCategories, 'tags' => $tags]);
}
示例7: resetPassword
public function resetPassword()
{
$this->_user = User::findIdentity(Yii::$app->user->id);
if (!Yii::$app->getSecurity()->validatePassword($this->password, $this->_user->password_hash)) {
throw new InvalidParamException(Yii::t('User', 'source_password_error'));
}
$this->_user->setPassword($this->new_password);
return $this->_user->save(false);
}
示例8: save_signature
public function save_signature()
{
$user = User::findIdentity(Yii::$app->user->id);
$user->signature = Functions::clear_text($this->signature);
if ($user->save()) {
return Html::decode($user->signature);
}
return false;
}
示例9: __construct
/**
* Creates a form model given a token.
*
* @param string $token
* @param array $config name-value pairs that will be used to initialize the object properties
* @throws \yii\base\InvalidParamException if token is empty or not valid
*/
public function __construct($id, $config = [])
{
$this->_user = User::findIdentity($id);
if (!$this->_user) {
throw new InvalidParamException('Unable to find user!');
}
$this->id = $this->_user->id;
$this->username = $this->_user->username;
parent::__construct($config);
}
示例10: statusVerified
/**
* Check status verified
* @param [type] $user_id [description]
* @return [type] [description]
*/
function statusVerified($user_id)
{
$profile = static::findOne(['user_id' => $user_id, 'created_by' => $user_id]);
$user = User::findIdentity($user_id);
if ($profile->email != $user->email) {
$email = $profile->email . ' <span class="label label-warning">Not Verified</span>';
} elseif ($profile->email === $user->email) {
$email = $profile->email . ' <span class="label label-success">Verified</span>';
}
return $email;
}
示例11: save_age_date
public function save_age_date()
{
$user = User::findIdentity(Yii::$app->user->id);
if ($user->age_date != $this->age_date) {
$user->age_date = $this->age_date;
if ($user->save()) {
return Functions::get_is_age_from_date($this->age_date);
}
}
return false;
}
示例12: actionInputPenduduk
public function actionInputPenduduk()
{
// get user from class User by id
$getUser = User::findIdentity(Yii::$app->user->id);
// check user level, if level equals 1 then user is an admin, he can through frontend or backend, if else user is a user, he only can through frontend
if ($getUser->level == 1) {
return $this->render('input_penduduk');
} else {
return $this->redirect(['../../frontend/web/', 'id' => Yii::$app->user->id]);
}
}
示例13: execute
/**
* Проверка доступа к ресурсу.
*
* @param int $userId Идентификатор пользователя.
* @param \yii\rbac\Item $item Роль.
* @param array $params Параметры для проверки доступа.
* @return bool
*/
public function execute($userId, $item, $params)
{
// Если не указан обязательный параметр action.
if (!isset($params['action']) || !in_array($params['action'], $this->actions)) {
return false;
}
// Пользователь не может редактировать и удалять сам себя.
if (in_array($params['action'], [self::ACTION_EDIT_USER, self::ACTION_DELETE_USER]) && $userId == $params['userId']) {
return false;
}
// Админам, кроме редактирования, удаления самомго себя разрешаются все действия.
$user = User::findIdentity($userId);
if ($user->isAdmin()) {
return true;
}
// Менеджерам запрещено выполнять какие-либо действия на пользователями.
if ($user->isManager()) {
return false;
}
// Если добавление пользователя.
if ($params['action'] == self::ACTION_ADD_USER) {
return true;
} else {
// Если не указан идентификатор пользователя, над которым выполняется действие.
if (!isset($params['userId'])) {
return false;
}
$actionUser = User::findIdentity($params['userId']);
// Если пользователь, на которым выполняется действие из другой компании, запрещаем что-либо делать.
if ($actionUser->getCompanyId() != $user->getCompanyId()) {
return false;
}
// Если пользователь, над которым выполняется действие администратор, запрещаем действие.
if ($actionUser->isAdmin()) {
return false;
}
// Если действие редактирование или удаление и если пользователь оовнер или пользователь, который выполняет
// действие босс и пользователь, над которым выполняется тоже босс, разрешаем выполнение.
$isChangeUserAction = in_array($params['action'], [self::ACTION_EDIT_USER, self::ACTION_DELETE_USER]);
if ($isChangeUserAction && ($user->isOwner() || $user->isBoss() && ($actionUser->isBoss() || $actionUser->isManager()))) {
return true;
}
// Просматривать можно и овнерам и боссам.
if (self::ACTION_VIEW_USER == $params['action']) {
return true;
}
return false;
}
}
示例14: actionIndex
/**
* Displays homepage.
*
* @return mixed
*/
public function actionIndex()
{
if (Yii::$app->user->isGuest) {
return $this->render('index');
} else {
$user = User::findIdentity(Yii::$app->user->id);
//var_dump($user);die;
$type = $user['type'];
if ($type == 'Tutor' || $type == 'tutor') {
return $this->redirect('index.php?r=file/index');
} else {
return $this->render('studentHome');
}
}
}
示例15: successAuthclientCallback
/**
* TODO: допилить, разделить
* @param \yii\authclient\BaseClient $client
* @return bool
*/
public function successAuthclientCallback($client)
{
$attributes = $client->getUserAttributes();
//TODO: добавить обновление данных
if (!Yii::$app->getUser()->isGuest) {
$userAuthClient = \common\models\UserAuthclient::findOne(["user_id" => Yii::$app->user->getId(), "provider" => $client->getId(), "provider_identifier" => $attributes["id"]]);
if (!$userAuthClient) {
$userAuthClient = new \common\models\UserAuthclient(["user_id" => Yii::$app->user->getId(), "provider" => $client->getId(), "provider_identifier" => $attributes["id"], "provider_data" => serialize($attributes)]);
$userAuthClient->save();
}
} else {
$userAuthClient = \common\models\UserAuthclient::findOne(["provider" => $client->getId(), "provider_identifier" => $attributes["id"]]);
if ($userAuthClient) {
$user = \common\models\User::findIdentity($userAuthClient->getUserId());
if ($user) {
return Yii::$app->user->login($user, 0);
}
}
}
}