mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Образован trait AccountFinder для поиска пользователя по его нику\мылу
Модель EmailActivation теперь умеет автоматически создавать своих правильных потомков по соответствующему типу Добавлена форма восстановления пароля и её обработчик (без контроллера)
This commit is contained in:
27
api/traits/AccountFinder.php
Normal file
27
api/traits/AccountFinder.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?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) {
|
||||
$this->account = Account::findOne([$this->getLoginAttribute() => $this->getLogin()]);
|
||||
}
|
||||
|
||||
return $this->account;
|
||||
}
|
||||
|
||||
public function getLoginAttribute() {
|
||||
return strpos($this->getLogin(), '@') ? 'email' : 'username';
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user