Skip to content

Commit 5718c38

Browse files
committed
Modified migration and model for User Entity
1 parent c83ede8 commit 5718c38

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

common/components/base/db/ActiveRecord.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
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

common/models/User.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Yii;
66
use yii\base\NotSupportedException;
77
use yii\behaviors\TimestampBehavior;
8-
use yii\db\ActiveRecord;
8+
use base\db\ActiveRecord;
99
use 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
}

console/migrations/m130524_201442_init.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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(),

0 commit comments

Comments
 (0)