| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace UserAccessManager\Controller\Frontend\Authentication; |
| 6 |
|
| 7 |
use UserAccessManager\Wrapper\Wordpress; |
| 8 |
|
| 9 |
trait LoginControllerTrait |
| 10 |
{ |
| 11 |
abstract protected function getWordpress(): Wordpress; |
| 12 |
abstract public function getRequestUrl(): string; |
| 13 |
abstract public function getRequestParameter(string $name, mixed $default = null): mixed; |
| 14 |
|
| 15 |
public function getUserLogin(): string |
| 16 |
{ |
| 17 |
$userLogin = $this->getRequestParameter('log'); |
| 18 |
return $this->getWordpress()->escHtml(stripslashes((string) $userLogin)); |
| 19 |
} |
| 20 |
|
| 21 |
public function isUserLoggedIn(): bool |
| 22 |
{ |
| 23 |
return $this->getWordpress()->isUserLoggedIn(); |
| 24 |
} |
| 25 |
|
| 26 |
public function getCurrentUserName(): string |
| 27 |
{ |
| 28 |
return $this->getWordpress()->getCurrentUser()->display_name; |
| 29 |
} |
| 30 |
|
| 31 |
public function getLoginUrl(): string |
| 32 |
{ |
| 33 |
return $this->getWordpress()->wpLoginUrl($this->getRequestUrl()); |
| 34 |
} |
| 35 |
|
| 36 |
public function getLogoutUrl(): string |
| 37 |
{ |
| 38 |
return $this->getWordpress()->wpLogoutUrl($this->getRequestUrl()); |
| 39 |
} |
| 40 |
|
| 41 |
public function getRegistrationUrl(): string |
| 42 |
{ |
| 43 |
return $this->getWordpress()->wpRegistrationUrl(); |
| 44 |
} |
| 45 |
|
| 46 |
public function getLostPasswordUrl(): string |
| 47 |
{ |
| 48 |
return $this->getWordpress()->wpLostPasswordUrl($this->getRequestUrl()); |
| 49 |
} |
| 50 |
|
| 51 |
public function showLoginForm(): bool |
| 52 |
{ |
| 53 |
return $this->getWordpress()->isSingle() === true || $this->getWordpress()->isPage() === true; |
| 54 |
} |
| 55 |
|
| 56 |
public function getRedirectLoginUrl(): mixed |
| 57 |
{ |
| 58 |
$loginUrl = $this->getWordpress()->getBlogInfo('wpurl') |
| 59 |
.'/wp-login.php?redirect_to='.urlencode($_SERVER['REQUEST_URI']); |
| 60 |
return $this->getWordpress()->applyFilters('uam_login_url', $loginUrl); |
| 61 |
} |
| 62 |
} |
| 63 |
|