Blame view

app-wx/models/UserIdentity.php 1.55 KB
62d73041   xu   app-wx
1
2
<?php namespace app\wx\models;

32926e46   xu   app-wx(v0.1.0 bui...
3
use yii;
afd2f743   xu   app-ht(v0.0.1 bui...
4
5
use yii\web\IdentityInterface;

62d73041   xu   app-wx
6
/**
32926e46   xu   app-wx(v0.1.0 bui...
7
 * Class UserIdentity
afd2f743   xu   app-ht(v0.0.1 bui...
8
9
10
11
12
13
 * @package app\wx\models
 */
class UserIdentity implements IdentityInterface
{
    /**
     * @var null
62d73041   xu   app-wx
14
15
     */
    static $id = null;
32926e46   xu   app-wx(v0.1.0 bui...
16

62d73041   xu   app-wx
17
18
    /**
     * @param int|string $id
32926e46   xu   app-wx(v0.1.0 bui...
19
     * @return  IdentityInterface
62d73041   xu   app-wx
20
     */
62d73041   xu   app-wx
21
22
23
    public static function findIdentity($id)
    {
        self::getIdFromSession();
32926e46   xu   app-wx(v0.1.0 bui...
24
25
26
27
        return new UserIdentity();
    }

    /**
62d73041   xu   app-wx
28
29
30
     * @param mixed $token
     * @param null $type
     * @return  IdentityInterface
32926e46   xu   app-wx(v0.1.0 bui...
31
     */
62d73041   xu   app-wx
32
33
34
    public static function findIdentityByAccessToken($token, $type = null)
    {
        return self::getIdFromSession();
32926e46   xu   app-wx(v0.1.0 bui...
35
36
37
38
        return new UserIdentity();
    }

    /**
62d73041   xu   app-wx
39
40
41
     * @return  int|string $id
     */
    public function getId()
32926e46   xu   app-wx(v0.1.0 bui...
42
    {
62d73041   xu   app-wx
43
44
45
        return self::getIdFromSession();
    }

32926e46   xu   app-wx(v0.1.0 bui...
46
    /**
62d73041   xu   app-wx
47
48
49
50
51
52
53
     *不启动自动登录,AuthKey 是用来设定到cookie的字符串
     *
     */
    public function getAuthKey()
    {
        return "";
    }
32926e46   xu   app-wx(v0.1.0 bui...
54

62d73041   xu   app-wx
55
56
57
    /**
     * 不启动自动登录,这里默认返回true
     * @param string $authKey
32926e46   xu   app-wx(v0.1.0 bui...
58
     */
62d73041   xu   app-wx
59
60
61
    public function validateAuthKey($authKey)
    {
        return true;
32926e46   xu   app-wx(v0.1.0 bui...
62
    }
62d73041   xu   app-wx
63
64
65
66
67
68
69

    /**
     * @return mixed|null
     */
    protected static function getIdFromSession()
    {
        if (null === self::$id){
32926e46   xu   app-wx(v0.1.0 bui...
70
71
72
73
74
75
76
77
78
            $user = \Yii::$app->getUser();
            $session = Yii::$app->getSession();
            $id = $session->getHasSessionId() || $session->getIsActive() ? $session->get($user->idParam) : null;
            self::$id = $id;
        }

        return self::$id;
    }
}
62d73041   xu   app-wx

32926e46   xu   app-wx(v0.1.0 bui...

62d73041   xu   app-wx

afd2f743   xu   app-ht(v0.0.1 bui...

1de3211f   xu   app-wx(v0.1.0 bui...

afd2f743   xu   app-ht(v0.0.1 bui...

1de3211f   xu   app-wx(v0.1.0 bui...

afd2f743   xu   app-ht(v0.0.1 bui...

1de3211f   xu   app-wx(v0.1.0 bui...

afd2f743   xu   app-ht(v0.0.1 bui...

1de3211f   xu   app-wx(v0.1.0 bui...

afd2f743   xu   app-ht(v0.0.1 bui...

afd2f743   xu   app-ht(v0.0.1 bui...

1de3211f   xu   app-wx(v0.1.0 bui...

afd2f743   xu   app-ht(v0.0.1 bui...

1de3211f   xu   app-wx(v0.1.0 bui...

afd2f743   xu   app-ht(v0.0.1 bui...

1de3211f   xu   app-wx(v0.1.0 bui...

afd2f743   xu   app-ht(v0.0.1 bui...

1de3211f   xu   app-wx(v0.1.0 bui...

afd2f743   xu   app-ht(v0.0.1 bui...

afd2f743   xu   app-ht(v0.0.1 bui...

1de3211f   xu   app-wx(v0.1.0 bui...

afd2f743   xu   app-ht(v0.0.1 bui...

62d73041   xu   app-wx