Попытка реализовать отдельный компонент для oAuth авторизации в свой же API. Не тестировал, не проверял работу, просто пушнул, чтобы потом продолжить в дргуом месте.

This commit is contained in:
ErickSkrauch
2016-08-04 01:07:21 +03:00
parent 71d9511d8e
commit 26b37c2f6b
13 changed files with 241 additions and 8 deletions

View File

@@ -25,7 +25,8 @@ use yii\db\ActiveRecord;
* @property integer $password_changed_at
*
* Геттеры-сеттеры:
* @property string $password пароль пользователя (только для записи)
* @property string $password пароль пользователя (только для записи)
* @property string $profileLink ссылка на профиль на Ely без поддержки static url (только для записи)
*
* Отношения:
* @property EmailActivation[] $emailActivations
@@ -144,7 +145,7 @@ class Account extends ActiveRecord {
*
* @return bool
*/
public function canAutoApprove(OauthClient $client, array $scopes = []) {
public function canAutoApprove(OauthClient $client, array $scopes = []) : bool {
if ($client->is_trusted) {
return true;
}
@@ -165,10 +166,14 @@ class Account extends ActiveRecord {
* Выполняет проверку, принадлежит ли этому нику аккаунт у Mojang
* @return bool
*/
public function hasMojangUsernameCollision() {
public function hasMojangUsernameCollision() : bool {
return MojangUsername::find()
->andWhere(['username' => $this->username])
->exists();
}
public function getProfileLink() : string {
return 'http://ely.by/u' . $this->id;
}
}

View File

@@ -2,7 +2,6 @@
namespace common\models;
use common\components\redis\Set;
use Yii;
use yii\db\ActiveRecord;
/**
@@ -13,6 +12,8 @@ use yii\db\ActiveRecord;
* @property integer $expire_time
*
* @property Set $scopes
*
* @property OauthSession $session
*/
class OauthAccessToken extends ActiveRecord {
@@ -38,4 +39,8 @@ class OauthAccessToken extends ActiveRecord {
return true;
}
public function isExpired() {
return time() > $this->expire_time;
}
}