Blame view

app-wx/models/UserIdentity.php 2.37 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;
use app\wx\models\User as UserModel;
62d73041   xu   app-wx
6

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

    /**
32926e46   xu   app-wx(v0.1.0 bui...
16
     * Finds an identity by the given ID.
62d73041   xu   app-wx
17
18
     *
     * @param string|int $id the ID to be looked for
32926e46   xu   app-wx(v0.1.0 bui...
19
     * @return IdentityInterface|null the identity object that matches the given ID.
62d73041   xu   app-wx
20
     */
62d73041   xu   app-wx
21
22
23
    public static function findIdentity($id)
    {
        return static::findOne($id);
32926e46   xu   app-wx(v0.1.0 bui...
24
25
26
27
    }

    /**
     * Finds an identity by the given token.
62d73041   xu   app-wx
28
29
30
     *
     * @param string $token the token to be looked for
     * @return IdentityInterface|null the identity object that matches the given token.
32926e46   xu   app-wx(v0.1.0 bui...
31
     */
62d73041   xu   app-wx
32
33
34
    public static function findIdentityByAccessToken($token, $type = null)
    {
        return static::findOne(['access_token' => $token]);
32926e46   xu   app-wx(v0.1.0 bui...
35
36
37
38
    }

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

    /**
32926e46   xu   app-wx(v0.1.0 bui...
46
     * @inheritdoc
62d73041   xu   app-wx
47
48
49
50
51
52
53
     */
    public function getAuthKey()
    {
        return  '';
    }

    /**
32926e46   xu   app-wx(v0.1.0 bui...
54
     * @inheritdoc
62d73041   xu   app-wx
55
56
57
     */
    public function validateAuthKey($authKey)
    {
32926e46   xu   app-wx(v0.1.0 bui...
58
        return true;
62d73041   xu   app-wx
59
60
61
    }

    /**
32926e46   xu   app-wx(v0.1.0 bui...
62
     * Validates password
62d73041   xu   app-wx
63
64
65
66
67
68
69
     *
     * @param string $password password to validate
     * @return bool if password provided is valid for current user
     */
    public function validatePassword($password)
    {
        return true ;//Yii::$app->security->validatePassword($password, $this->password_hash);
32926e46   xu   app-wx(v0.1.0 bui...
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
    }

    /**
     * Generates password hash from password and sets it to the model
     *
     * @param string $password
     */
    public function setPassword($password)
    {
        $this->password_hash = Yii::$app->security->generatePasswordHash($password);
    }

    /**
     * Generates new password reset token
     */
    public function generatePasswordResetToken()
    {
        $this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time();
    }

    /**
     * @return mixed|null
     */
    protected static function getIdFromSession()
    {
        if (null === self::$id){
            $user = Yii::$app->getUser();
            $session = Yii::$app->getSession();
            $id = $session->getHasSessionId() || $session->getIsActive() ? $session->get($user->idParam) : null;
62d73041   xu   app-wx
99
100
101
102
103
            self::$id = $id;
        }

        return self::$id;
    }
32926e46   xu   app-wx(v0.1.0 bui...
104
}
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