mirror of
https://github.com/elyby/accounts.git
synced 2024-12-27 07:30:18 +05:30
bdc96d82c1
Добавлен механизм сохранения сессий и refresh_token
36 lines
720 B
PHP
36 lines
720 B
PHP
<?php
|
|
namespace api\traits;
|
|
|
|
use common\models\Account;
|
|
|
|
trait AccountFinder {
|
|
|
|
private $account;
|
|
|
|
public abstract function getLogin();
|
|
|
|
/**
|
|
* @return Account|null
|
|
*/
|
|
public function getAccount() {
|
|
if ($this->account === null) {
|
|
$className = $this->getAccountClassName();
|
|
$this->account = $className::findOne([$this->getLoginAttribute() => $this->getLogin()]);
|
|
}
|
|
|
|
return $this->account;
|
|
}
|
|
|
|
public function getLoginAttribute() {
|
|
return strpos($this->getLogin(), '@') ? 'email' : 'username';
|
|
}
|
|
|
|
/**
|
|
* @return Account|string
|
|
*/
|
|
protected function getAccountClassName() {
|
|
return Account::class;
|
|
}
|
|
|
|
}
|