32 parent::__construct();
36 $this->_noAccessMsg=
new FlashMessage(
"You are not authorized to access the page <b>{url}</b> !",
"Forbidden access",
"error",
"warning circle");
37 $this->_loginCaption=
"Log in";
76 if(!is_array($urlParts)){
77 $urlParts=explode(
".", $urlParts);
82 $message=$this->
fMessage($fMessage->parseContent([
"url"=>implode(
"/",$urlParts)]));
110 if(isset($_POST[
"ck-remember"])){
127 abstract protected function _connect();
132 abstract protected function onConnect($connected);
145 $fMessage=
new FlashMessage(
"Invalid creditentials!",
"Connection problem",
"warning",
"warning circle");
155 $fAttemptsNumberMessage=
new FlashMessage(
"<i class='ui warning icon'></i> You still have {_attemptsCount} attempts to log in.",null,
"bottom attached warning",
"");
159 $fAttemptsNumberMessage->parseContent([
"_attemptsCount"=>$nb,
"_timer"=>
"<span id='timer'></span>"]);
160 $attemptsMessage=$this->
fMessage($fAttemptsNumberMessage,
"timeout-message");
161 $fMessage->addType(
"attached");
163 $message=$this->
fMessage($fMessage,
"bad-login").$attemptsMessage;
170 if(is_numeric($timeout)){
171 $this->jquery->exec(
"$('._login').addClass('disabled');",
true);
172 $plus=
" You can try again {_timer}";
173 $this->jquery->exec(
"var startTimer=function(duration, display) {var timer = duration, minutes, seconds; 174 var interval=setInterval(function () { 175 minutes = parseInt(timer / 60, 10);seconds = parseInt(timer % 60, 10); 176 minutes = minutes < 10 ? '0' + minutes : minutes; 177 seconds = seconds < 10 ? '0' + seconds : seconds; 178 display.html('in ' +minutes + ':' + seconds); 179 if (--timer < 0) {clearInterval(interval);$('#timeout-message').hide();$('#bad-login').removeClass('attached');$('._login').removeClass('disabled');} 183 $this->jquery->exec(
"startTimer({$timeToLeft},$('#timer'));",
true);
184 $this->jquery->compile($this->view);
186 return new FlashMessage(
"<i class='ui warning icon'></i> You have no more attempt of connection !".$plus,null,
"bottom attached error",
"");
199 $mainTemplate=$files->getBaseTemplate();
200 if(isset($mainTemplate)){
201 $vars[
"_viewname"]=$viewName;
202 $vars[
"_base"]=$mainTemplate;
203 $this->
loadView($files->getViewBaseTemplate(),$vars);
215 $fMessage=
new FlashMessage(
"You have been properly disconnected!",
"Logout",
"success",
"checkmark");
217 $message=$this->
fMessage($fMessage);
222 $fMessage=
new FlashMessage(
"You have been disconnected from the application!",
"Logout",
"",
"sign out");
224 $message=$this->
fMessage($fMessage);
226 $this->jquery->execOn(
"click",
"._close",
"window.open(window.location,'_self').close();");
227 $this->jquery->renderView($this->
_getFiles()->getViewDisconnected(),[
"_title"=>
"Session ended",
"_message"=>$message]);
259 public function message($type,$header,$body,$icon=
"info",$id=null){
260 return $this->
loadView($this->
_getFiles()->getViewMessage(),get_defined_vars(),
true);
303 echo
"{\"valid\":".UString::getBooleanStr($this->
_isValidUser()).
"}";
332 if(!isset($this->authFiles)){
367 $this->_noAccessMsg->setValues($content,$title,$type,$icon);
377 return "Remember me";
static isPost()
Returns true if the request is sent by the POST method.
_displayInfoAsString()
Override to define if info is displayed as string if set to true, use _infoUser var in views to displ...
_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> !...
attemptsNumber()
To override Returns the maximum number of allowed login attempts.
attemptsTimeout()
To override Returns the time before trying to connect again Effective only if attemptsNumber return a...
toCookie($connected)
Returns the value from connected user to save it in the cookie for auto connection.
fMessage(FlashMessage $fMessage, $id=null)
static delete($key)
Deletes the key in Session.
_setLoginCaption($_loginCaption)
static exists($key)
Returns true if the key exists in Session.
static setTmp($key, $value, $duration)
static asJSON()
Sets the response content-type to application/json.
badLoginMessage(FlashMessage $fMessage)
To override for modifying the bad login message.
noAccessMessage(FlashMessage $fMessage)
Override for modifying the noAccess message.
rememberMe($connected)
Saves the connected user identifier in a cookie.
connect()
Override to implement the complete connection procedure.
_isValidUser()
return boolean true if activeUser is valid
terminateMessage(FlashMessage $fMessage)
To override for modifying the logout message.
getFiles()
To override for changing view files.
_getBaseRoute()
To override Return the base route for this Auth controller.
loadView($viewName, $pData=NULL, $asString=false)
Loads the view $viewName possibly passing the variables $pdata.
static set($name, $value, $duration=60 *60 *24, $path="/")
Sends a cookie.
static terminate()
Terminates the active session.
onBadCreditentials()
To override for defining a new action when creditentials are invalid.
disconnectedMessage(FlashMessage $fMessage)
To override for modifying the disconnect message.
attemptsNumberMessage(FlashMessage $fMessage, $attempsCount)
Override for modifying attempts message You can use {_timer} and {_attemptsCount} variables in messag...
static set($key, $value)
Adds or sets a value to the Session at position $key.
_autoConnect()
Auto connect the user.
static get($name, $default=null)
Returns the Cookie with the name $name.
terminate()
Logout action Terminate the session and display a logout message.
_connect()
Processes the data posted by the login form Have to return the connected user instance.
getCookieUser()
Returns the cookie for auto connection.
authLoadView($viewName, $vars=[])
_getActiveUser()
To override for getting active user, default : USession::get("activeUser")
fromCookie($cookie)
Loads the user from database using the cookie value.
static get($key, $default=NULL)
Returns the value stored at the key position in session.
static delete($name, $path="/")
Removes the cookie with the name $name.
info()
Action displaying the logged user information if _displayInfoAsString returns true, use _infoUser var in views to display user info.
_checkConnectionTimeout()
message($type, $header, $body, $icon="info", $id=null)
_getUserSessionKey()
To override for defining user session key, default : "activeUser".
forgetConnection()
Deletes the cookie for auto connection and returns to index.
noAccess($urlParts)
Action called when the user does not have access rights to a requested resource.
badLogin()
Default Action for invalid creditentials.
static getClassSimpleName($classnameWithNamespace)
static getTmp($key, $default=null)