| 1 |
<?php |
| 2 |
/** |
| 3 |
* LoginControllerTrait.php |
| 4 |
* |
| 5 |
* The LoginControllerTrait trait file. |
| 6 |
* |
| 7 |
* PHP versions 5 |
| 8 |
* |
| 9 |
* @author Alexander Schneider <alexanderschneider85@gmail.com> |
| 10 |
* @copyright 2008-2017 Alexander Schneider |
| 11 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 |
| 12 |
* @version SVN: $id$ |
| 13 |
* @link http://wordpress.org/extend/plugins/user-access-manager/ |
| 14 |
*/ |
| 15 |
|
| 16 |
declare(strict_types=1); |
| 17 |
|
| 18 |
namespace UserAccessManager\Controller\Frontend; |
| 19 |
|
| 20 |
use UserAccessManager\Wrapper\Wordpress; |
| 21 |
|
| 22 |
/** |
| 23 |
* Trait LoginControllerTrait |
| 24 |
* |
| 25 |
* @package UserAccessManager\Controller |
| 26 |
*/ |
| 27 |
trait LoginControllerTrait |
| 28 |
{ |
| 29 |
/** |
| 30 |
* @return Wordpress |
| 31 |
*/ |
| 32 |
abstract protected function getWordpress(): Wordpress; |
| 33 |
|
| 34 |
/** |
| 35 |
* @return string |
| 36 |
*/ |
| 37 |
abstract public function getRequestUrl(): string; |
| 38 |
|
| 39 |
/** |
| 40 |
* @param string $name |
| 41 |
* @param mixed $default |
| 42 |
* @return mixed |
| 43 |
*/ |
| 44 |
abstract public function getRequestParameter(string $name, $default = null); |
| 45 |
|
| 46 |
/** |
| 47 |
* Returns the user login name. |
| 48 |
* @return string |
| 49 |
*/ |
| 50 |
public function getUserLogin(): string |
| 51 |
{ |
| 52 |
$userLogin = $this->getRequestParameter('log'); |
| 53 |
return $this->getWordpress()->escHtml(stripslashes((string) $userLogin)); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Returns true if the user is logged in. |
| 58 |
* @return bool |
| 59 |
*/ |
| 60 |
public function isUserLoggedIn(): bool |
| 61 |
{ |
| 62 |
return $this->getWordpress()->isUserLoggedIn(); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Returns the user name of the current user |
| 67 |
* @return string |
| 68 |
*/ |
| 69 |
public function getCurrentUserName(): string |
| 70 |
{ |
| 71 |
return $this->getWordpress()->getCurrentUser()->display_name; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Returns the login url. |
| 76 |
* @return string |
| 77 |
*/ |
| 78 |
public function getLoginUrl(): string |
| 79 |
{ |
| 80 |
return $this->getWordpress()->wpLoginUrl($this->getRequestUrl()); |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Returns the logout url. |
| 85 |
* @return string |
| 86 |
*/ |
| 87 |
public function getLogoutUrl(): string |
| 88 |
{ |
| 89 |
return $this->getWordpress()->wpLogoutUrl($this->getRequestUrl()); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
/** |
| 94 |
* Returns the registration url. |
| 95 |
* @return string |
| 96 |
*/ |
| 97 |
public function getRegistrationUrl(): string |
| 98 |
{ |
| 99 |
return $this->getWordpress()->wpRegistrationUrl(); |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Returns the lost password url. |
| 104 |
* @return string |
| 105 |
*/ |
| 106 |
public function getLostPasswordUrl(): string |
| 107 |
{ |
| 108 |
return $this->getWordpress()->wpLostPasswordUrl($this->getRequestUrl()); |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Checks if we allowed show the login form. |
| 113 |
* @return bool |
| 114 |
*/ |
| 115 |
public function showLoginForm(): bool |
| 116 |
{ |
| 117 |
return $this->getWordpress()->isSingle() === true || $this->getWordpress()->isPage() === true; |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Returns the login redirect url. |
| 122 |
* @return mixed |
| 123 |
*/ |
| 124 |
public function getRedirectLoginUrl() |
| 125 |
{ |
| 126 |
$loginUrl = $this->getWordpress()->getBlogInfo('wpurl') |
| 127 |
.'/wp-login.php?redirect_to='.urlencode($_SERVER['REQUEST_URI']); |
| 128 |
return $this->getWordpress()->applyFilters('uam_login_url', $loginUrl); |
| 129 |
} |
| 130 |
} |
| 131 |
|