| 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 |
namespace UserAccessManager\Controller\Frontend; |
| 16 |
|
| 17 |
use UserAccessManager\Controller\BaseControllerTrait; |
| 18 |
use UserAccessManager\Wrapper\Wordpress; |
| 19 |
|
| 20 |
/** |
| 21 |
* Trait LoginControllerTrait |
| 22 |
* |
| 23 |
* @package UserAccessManager\Controller |
| 24 |
*/ |
| 25 |
trait LoginControllerTrait |
| 26 |
{ |
| 27 |
use BaseControllerTrait; |
| 28 |
|
| 29 |
/** |
| 30 |
* @return Wordpress |
| 31 |
*/ |
| 32 |
abstract protected function getWordpress(); |
| 33 |
|
| 34 |
/** |
| 35 |
* Returns the user login name. |
| 36 |
* |
| 37 |
* @return string |
| 38 |
*/ |
| 39 |
public function getUserLogin() |
| 40 |
{ |
| 41 |
$userLogin = $this->getRequestParameter('log'); |
| 42 |
return $this->getWordpress()->escHtml(stripslashes($userLogin)); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Returns true if the user is logged in. |
| 47 |
* |
| 48 |
* @return bool |
| 49 |
*/ |
| 50 |
public function isUserLoggedIn() |
| 51 |
{ |
| 52 |
return $this->getWordpress()->isUserLoggedIn(); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Returns the user name of the current user |
| 57 |
* |
| 58 |
* @return string |
| 59 |
*/ |
| 60 |
public function getCurrentUserName() |
| 61 |
{ |
| 62 |
return $this->getWordpress()->getCurrentUser()->display_name; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Returns the login url. |
| 67 |
* |
| 68 |
* @return string |
| 69 |
*/ |
| 70 |
public function getLoginUrl() |
| 71 |
{ |
| 72 |
return $this->getWordpress()->wpLoginUrl($this->getRequestUrl()); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Returns the logout url. |
| 77 |
* |
| 78 |
* @return string |
| 79 |
*/ |
| 80 |
public function getLogoutUrl() |
| 81 |
{ |
| 82 |
return $this->getWordpress()->wpLogoutUrl($this->getRequestUrl()); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
/** |
| 87 |
* Returns the registration url. |
| 88 |
* |
| 89 |
* @return string |
| 90 |
*/ |
| 91 |
public function getRegistrationUrl() |
| 92 |
{ |
| 93 |
return $this->getWordpress()->wpRegistrationUrl(); |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Returns the lost password url. |
| 98 |
* |
| 99 |
* @return string |
| 100 |
*/ |
| 101 |
public function getLostPasswordUrl() |
| 102 |
{ |
| 103 |
return $this->getWordpress()->wpLostPasswordUrl($this->getRequestUrl()); |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* Checks if we allowed show the login form. |
| 108 |
* |
| 109 |
* @return bool |
| 110 |
*/ |
| 111 |
public function showLoginForm() |
| 112 |
{ |
| 113 |
return $this->getWordpress()->isSingle() === true || $this->getWordpress()->isPage() === true; |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Returns the login redirect url. |
| 118 |
* |
| 119 |
* @return mixed |
| 120 |
*/ |
| 121 |
public function getRedirectLoginUrl() |
| 122 |
{ |
| 123 |
$loginUrl = $this->getWordpress()->getBlogInfo('wpurl') |
| 124 |
.'/wp-login.php?redirect_to='.urlencode($_SERVER['REQUEST_URI']); |
| 125 |
return $this->getWordpress()->applyFilters('uam_login_url', $loginUrl); |
| 126 |
} |
| 127 |
} |
| 128 |
|