Blame view

app-api/models/ClientUser.php 1.24 KB
cfe42223   曹明   提交初始代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php

namespace app\api\models;

use common\models\ClientUser as BaseClientUser;
use OAuth2\Storage\UserCredentialsInterface;

/**
 * Class ClientUser
 * @package app\api\models
 */
class ClientUser extends BaseClientUser implements UserCredentialsInterface
{
    public function init()
    {
        parent::init();
    }

    /**
     * Implemented for Oauth2 Interface
     */
    public function checkUserCredentials($openId, $password)
    {
        $user = static::findByOpenId($openId);
        if (empty($user)) {
            return false;
        }
        return $user->validateAuthKey($password);
    }

    /**
     * Implemented for Oauth2 Interface
     */
    public function getUserDetails($openId)
    {
        $clientUser = static::findByOpenId($openId);
        return ['user_id' => $clientUser->getId()];
    }

    /** @inheritdoc */
    public static function findIdentityByAccessToken($token, $type = null)
    {
        $q = static::find();
        $q->select("client_user.*")
            ->from("oauth_access_tokens")
            ->leftJoin("client_user", 'client_user.id = oauth_access_tokens.user_id')
            ->where(['oauth_access_tokens.access_token'=>$token]);

        $identity = $q->one();

        return $identity;
    }
}