15use Ajax\service\Javascript;
18use Ajax\semantic\html\collections\form\HtmlForm;
19use Ajax\php\ubiquity\JsUtils;
44 parent::__construct ();
49 $this->_noAccessMsg =
new FlashMessage (
'You are not authorized to access the page <b>{url}</b> !',
'Forbidden access',
'error',
'warning circle' );
50 $this->_loginCaption =
'Log in';
51 $this->_controllerInstance = $instance;
52 if (isset ( $instance )){
55 if($this->
useAjax() && !URequest::isAjax()) {
62 $nb = USession::getTmp ( $this->_attemptsSessionKey, $nbAttempsMax );
91 if (! \is_array ( $urlParts )) {
92 $urlParts = \explode (
'.', $urlParts );
94 USession::set (
'urlParts', $urlParts );
97 $message = $this->
fMessage ( $fMessage->parseContent ( [
'url' => \implode (
'/', $urlParts ) ] ) );
99 if (URequest::isAjax ()) {
100 $this->jquery->get ( $this->
_getBaseRoute () .
'/info/f',
'#_userInfo', [
'historize' =>
false,
'jqueryDone' =>
'replaceWith',
'hasLoader' =>
false,
'attr' =>
'' ] );
101 $this->jquery->compile ( $this->view );
113 #[\Ubiquity\attributes\items\router\Post]
115 if (URequest::isPost ()) {
116 if ($connected = $this->
_connect ()) {
117 if (isset ( $_POST [
'ck-remember'] )) {
120 if (USession::exists ( $this->_attemptsSessionKey )) {
121 USession::delete ( $this->_attemptsSessionKey );
123 if($this->
has2FA($connected)){
133 $this->_invalid=
true;
146 #[\Ubiquity\attributes\items\router\NoRoute]
148 $fMessage =
new FlashMessage (
'Invalid creditentials!',
'Connection problem',
'warning',
'warning circle' );
150 $attemptsMessage =
'';
152 $nb = USession::getTmp ( $this->_attemptsSessionKey, $nbAttempsMax );
158 $fAttemptsNumberMessage = $this->
noAttempts ();
160 $fAttemptsNumberMessage =
new FlashMessage (
'<i class="ui warning icon"></i> You still have {_attemptsCount} attempts to log in.',
null,
'bottom attached warning',
'' );
162 USession::setTmp ( $this->_attemptsSessionKey, $nb, $this->
attemptsTimeout () );
164 $fAttemptsNumberMessage->parseContent ( [
'_attemptsCount' => $nb,
'_timer' =>
'<span id="timer"></span>' ] );
165 $attemptsMessage = $this->
fMessage ( $fAttemptsNumberMessage,
'timeout-message' );
166 $fMessage->addType (
"attached" );
168 $message = $this->
fMessage ( $fMessage,
'bad-login' ) . $attemptsMessage;
177 USession::terminate ();
178 $fMessage =
new FlashMessage (
'You have been properly disconnected!',
'Logout',
'success',
'checkmark' );
180 $message = $this->
fMessage ( $fMessage );
185 $fMessage =
new FlashMessage (
'You have been disconnected from the application!',
'Logout',
'',
'sign out' );
187 $message = $this->
fMessage ( $fMessage );
188 $this->jquery->getOnClick (
'._signin', $this->
getBaseUrl (), $this->
_getBodySelector (), [
'stopPropagation' =>
false,
'preventDefault' =>
false ] );
189 $this->jquery->execOn (
'click',
'._close',
"window.open(window.location,'_self').close();" );
190 return $this->jquery->renderView ( $this->
_getFiles ()->getViewDisconnected (), [
"_title" =>
'Session ended',
'_message' => $message ],
true );
201 public function info($force =
null) {
202 if (isset ( $force )) {
203 $displayInfoAsString = $force ===
true;
211 UResponse::asJSON ();
224 public function _setNoAccessMsg($content, $title = NULL, $type = NULL, $icon =
null) {
225 $this->_noAccessMsg->setValues ( $content, $title, $type, $icon );
241 if (isset ( $cookie )) {
243 if (isset ( $user )) {
263 if (! UResponse::isJSON ()) {
267 $this->jquery->execAtLast (
"if($('#_userInfo').length){\$('#_userInfo').replaceWith(" . \preg_replace (
"/$\R?^/m",
"", Javascript::prep_element ( $this->
info () ) ) .
");}" );
268 if ($this->_compileJS) {
269 echo $this->jquery->compile ();
275 if (!URequest::isAjax()) {
276 $this->
loadView(
'@activeTheme/main/vFooter.html');
292 if (!URequest::isAjax()) {
293 $this->
loadView(
'@activeTheme/main/vHeader.html');
301 public function _forward($url, $initialize =
null, $finalize =
null) {
302 if (! isset ( $initialize )) {
303 $initialize = (! isset ( $this->_controllerInstance ) || URequest::isAjax ());
305 if (! isset ( $finalize )) {
306 $finalize = $initialize;
311 public function _addAjaxBehavior(JsUtils
$jquery=
null,$ajaxParameters=[
'hasLoader'=>
'$(this).children(".button")',
'historize'=>
false,
'listenerOn'=>
'body']){
313 $jquery->getHref(
'.ajax[data-target]',
'', $ajaxParameters);
318 $frm=$this->jquery->semantic()->htmlForm($id);
321 $frm->setValidationParams([
'inline'=>
true,
'on'=>
'blur']);
Base class for controllers.
static getController()
Returns the active controller name.
static forward(string $url, bool $initialize=true, bool $finalize=true)
Forwards to url.
static injectDependencies($controller)
Injects the dependencies from the di config key in a controller.
static getActionParams()
Returns the active parameters.
static getAction()
Returns tha active action.
fMessage(FlashMessage $fMessage, $id=null)
loadView(string $viewName, $pData=NULL, bool $asString=false)
addAccountCreationViewData(array &$vData, $forMessage=false)
authLoadView($viewName, $vars=[])
_autoConnect()
Auto connect the user.
forgetConnection()
Deletes the cookie for auto connection and returns to index.
info($force=null)
Action displaying the logged user information if _displayInfoAsString returns true,...
_addAjaxBehavior(JsUtils $jquery=null, $ajaxParameters=['hasLoader'=> '$(this).children(".button")', 'historize'=>false, 'listenerOn'=> 'body'])
connect()
Override to implement the complete connection procedure.
initialize()
{Method called before each action Can be override in derived class.}
__construct($instance=null)
finalize()
{Method called after each action Can be override in derived class.}
noAccess($urlParts)
Action called when the user does not have access rights to a requested resource.
terminate()
Logout action Terminate the session and display a logout message.
_forward($url, $initialize=null, $finalize=null)
_setLoginCaption($_loginCaption)
isValid($action)
{Returns True if access to the controller is allowed To be override in sub classes....
_setNoAccessMsg($content, $title=NULL, $type=NULL, $icon=null)
Sets the default noAccess message Default : "You are not authorized to access the page <b>{url}</b> !...
badLogin()
Default Action for invalid creditentials.
Trait AuthControllerOverrideTrait.
_connect()
Processes the data posted by the login form Have to return the connected user instance.
rememberMe($connected)
Saves the connected user identifier in a cookie.
getCookieUser()
Returns the cookie for auto connection.
onBadCreditentials()
To override for defining a new action when creditentials are invalid.
_isValidUser($action=null)
Checks if user is valid for the action.
fromCookie($cookie)
Loads the user from database using the cookie value.
Ubiquity\controllers\auth$AuthControllerVariablesTrait This class is part of Ubiquity.
disconnectedMessage(FlashMessage $fMessage)
To override for modifying the disconnect message.
attemptsNumber()
To override Returns int the maximum number of allowed login attempts.
noAccessMessage(FlashMessage $fMessage)
Override for modifying the noAccess message.
_displayInfoAsString()
Override to define if user info is displayed as string.
attemptsNumberMessage(FlashMessage $fMessage, $attempsCount)
Override for modifying attempts message You can use {_timer} and {_attemptsCount} variables in messag...
terminateMessage(FlashMessage $fMessage)
To override for modifying the logout message.
badLoginMessage(FlashMessage $fMessage)
To override for modifying the bad login message.
has2FA($accountValue=null)
To override Returns true for a two factor authentification for this account.
Trait AuthAccountCreationTrait.
Ubiquity\controllers\auth\traits$AuthAccountRecoveryTrait This class is part of Ubiquity.
Http Cookies utilities Ubiquity\utils\http$UCookie This class is part of Ubiquity.
Http Request utilities, wrapper for accessing to $_GET, $_POST and php://input.
Http Session utilities This class is part of Ubiquity.