1 | <?php |
||
33 | class Token extends ActiveRecord |
||
34 | { |
||
35 | use ModuleAwareTrait; |
||
36 | use ContainerAwareTrait; |
||
37 | |||
38 | const TYPE_CONFIRMATION = 0; |
||
39 | const TYPE_RECOVERY = 1; |
||
40 | const TYPE_CONFIRM_NEW_EMAIL = 2; |
||
41 | const TYPE_CONFIRM_OLD_EMAIL = 3; |
||
42 | |||
43 | protected $routes = [ |
||
44 | self::TYPE_CONFIRMATION => '/user/registration/confirm', |
||
45 | self::TYPE_RECOVERY => '/user/recovery/reset', |
||
46 | self::TYPE_CONFIRM_NEW_EMAIL => '/user/settings/confirm', |
||
47 | self::TYPE_CONFIRM_OLD_EMAIL => '/user/settings/confirm', |
||
48 | ]; |
||
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | 4 | public function beforeSave($insert) |
|
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | 5 | public static function tableName() |
|
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | 2 | public static function primaryKey() |
|
79 | |||
80 | /** |
||
81 | * @return \yii\db\ActiveQuery |
||
82 | */ |
||
83 | 2 | public function getUser() |
|
87 | |||
88 | /** |
||
89 | * @return string |
||
90 | */ |
||
91 | 4 | public function getUrl() |
|
95 | |||
96 | /** |
||
97 | * @return bool Whether token has expired |
||
98 | */ |
||
99 | 3 | public function getIsExpired() |
|
100 | { |
||
101 | 3 | if ($this->type == static::TYPE_RECOVERY) { |
|
102 | 1 | $expirationTime = $this->getModule()->tokenRecoveryLifespan; |
|
103 | 2 | } elseif ($this->type >= static::TYPE_CONFIRMATION && $this->type <= static::TYPE_CONFIRM_OLD_EMAIL) { |
|
104 | 2 | $expirationTime = $this->getModule()->tokenConfirmationLifespan; |
|
105 | } else { |
||
106 | throw new RuntimeException(); |
||
107 | } |
||
108 | |||
109 | 3 | return ($this->created_at + $expirationTime) < time(); |
|
110 | } |
||
111 | |||
112 | /** |
||
113 | * @return TokenQuery |
||
114 | */ |
||
115 | 4 | public static function find() |
|
119 | } |
||
120 |