File tree Expand file tree Collapse file tree 3 files changed +37
-4
lines changed
Expand file tree Collapse file tree 3 files changed +37
-4
lines changed Original file line number Diff line number Diff line change 44
55 use base \util \UUID ;
66 use yii \behaviors \AttributeBehavior ;
7+ use yii \behaviors \BlameableBehavior ;
78 use yii \behaviors \TimestampBehavior ;
89
910 class ActiveRecord extends \yii \db \ActiveRecord
Original file line number Diff line number Diff line change 55use Yii ;
66use yii \base \NotSupportedException ;
77use yii \behaviors \TimestampBehavior ;
8- use yii \db \ActiveRecord ;
8+ use base \db \ActiveRecord ;
99use yii \web \IdentityInterface ;
1010
1111/**
@@ -49,7 +49,7 @@ public static function findIdentity($id)
4949 */
5050 public static function findIdentityByAccessToken ($ token , $ type = null )
5151 {
52- throw new NotSupportedException ( ' "findIdentityByAccessToken" is not implemented. ' );
52+ return static :: findOne ([ ' access_token ' => $ token , ' status ' => self :: STATUS_ACTIVE ] );
5353 }
5454
5555 /**
@@ -187,4 +187,36 @@ public function removePasswordResetToken()
187187 {
188188 $ this ->password_reset_token = null ;
189189 }
190+
191+ /**
192+ * Generates new access token
193+ */
194+ public function generateAccessToken ()
195+ {
196+ $ this ->access_token = Yii::$ app ->security ->generateRandomString (32 ) . '_ ' . time ();
197+ }
198+
199+ /**
200+ * Removes access token
201+ */
202+ public function removeAccessToken ()
203+ {
204+ $ this ->access_token = null ;
205+ }
206+
207+ /**
208+ * Generates new refresh token
209+ */
210+ public function generateRefreshToken ()
211+ {
212+ $ this ->refresh_token = Yii::$ app ->security ->generateRandomString (32 ) . '_ ' . time ();
213+ }
214+
215+ /**
216+ * Removes access token
217+ */
218+ public function removeRefreshToken ()
219+ {
220+ $ this ->refresh_token = null ;
221+ }
190222}
Original file line number Diff line number Diff line change @@ -16,8 +16,8 @@ public function up()
1616 'id ' => $ this ->string (36 )->notNull (),
1717 'username ' => $ this ->string ()->notNull ()->unique (),
1818 'auth_key ' => $ this ->string (32 )->notNull (),
19- 'access_token ' => $ this ->string (32 )->notNull (),
20- 'refresh_token ' => $ this ->string (32 )->notNull (),
19+ 'access_token ' => $ this ->string (46 )->notNull (),
20+ 'refresh_token ' => $ this ->string (46 )->notNull (),
2121 'password_hash ' => $ this ->string ()->notNull (),
2222 'password_reset_token ' => $ this ->string ()->unique (),
2323 'email ' => $ this ->string ()->notNull ()->unique (),
You can’t perform that action at this time.
0 commit comments