58 'nameSpace'=>$this->cfg->sessionNameSpace
60 $this->table =
db::get(
'table', $this->cfg->table);
69 if (!$cryptic = $this->
session->cryptic) {
72 $cryptic = $cook->get(
true);
80 $this->
hook(
'autoLogin'.($fromSession ?
'Session' : null));
81 $this->
session->cryptic = $cryptic;
82 }
else if (isset($cook))
94 return $this->table->find(array_merge(array(
95 $this->table->getRawName().
'.'.$this->cfg->getInArray(
'fields',
'cryptic')=>$cryptic
96 ), $this->cfg->where));
109 if ($this->
isLogged() && $this->user)
133 protected function saveLogin($cookieStayConnected =
false) {
134 $crypticKey = $this->cfg->getInArray(
'fields',
'cryptic');
135 $cryptic = $this->
cryptPass(uniqid(),
'Cryptic');
136 $this->user->set($crypticKey, $cryptic);
149 $tableName = $this->table->getRawName();
150 $loginField = $this->cfg->getInArray(
'fields',
'login');
151 $passField = $this->cfg->getInArray(
'fields',
'pass');
154 $tableName.
'.'.$loginField=>$login,
155 $tableName.
'.'.$passField=>$this->cryptPass($pass),
167 public function login($prm = null, $page = null, $redirectIfLogged =
true) {
168 $loginField = $this->cfg->getInArray(
'fields',
'login');
169 $passField = $this->cfg->getInArray(
'fields',
'pass');
176 $prm =
$form->getValues(
true);
181 && array_key_exists($loginField, $prm)
182 && array_key_exists($passField, $prm)) {
183 $this->user = $this->table->find(array_merge(
185 $this->getWhereLogin($prm[$loginField], $prm[$passField])
189 $this->
saveLogin(array_key_exists(
'stayConnected', $prm) && $prm[
'stayConnected']);
190 $this->
hook(
'login');
192 $form->addCustomError($loginField, $this->cfg->errorMsg);
193 if ($this->logged && $redirectIfLogged) {
194 if (is_null($page)) {
195 if ($this->
session->pageFrom) {
196 $page = $this->
session->pageFrom;
197 unset($this->
session->pageFrom);
215 $this->
session->cryptic = $cryptic;
216 $this->logged =
true;
217 if ($cookieStayConnected)
225 $cook =
factory::get(
'http_cookie', $this->cfg->cookie);
226 $cook->set($this->user->get($this->cfg->getInArray(
'fields',
'cryptic')));
238 $crypt = $this->cfg->get(
'crypt'.$plus);
239 if ($crypt && function_exists($crypt))
246 $this->
session->del(
'cryptic');
247 $this->logged =
false;
249 $cook =
factory::get(
'http_cookie', $this->cfg->cookie);
252 $this->
hook(
'logout');
253 return $this->logged ==
false;
257 $this->roles[$role] =
true;
265 return array_key_exists($role, $this->roles);
269 if (is_null($role)) {
270 $this->roles = array();
273 unset($this->roles[$rol]);
277 public function check(array $url = null, $redirect =
true) {
281 if ($this->
isContained($url, $this->cfg->noSecurity))
284 $hasRight = $this->cfg->default;
292 if (!empty($this->cfg->rightRoles)) {
294 foreach($this->
hasRole() as $r=>$t) {
295 $tmp = $this->cfg->getInArray(
'rightRoles', $r);
296 if (is_array($tmp)) {
306 if (!$hasRight && $redirect) {
308 if ($request != $this->
getPage(
'forbidden') && $request != $this->
getPage(
'login')) {
311 $this->
hook(
'redirectError');
321 $this->
form = $this->table->getRow()->getForm(array(
322 $this->cfg->getInArray(
'fields',
'login'),
323 $this->cfg->getInArray(
'fields',
'pass')
324 ), array_merge($this->cfg->formOptions, $prm, array(
327 $this->
form->
get($this->cfg->getInArray(
'fields',
'login'))->getValid()->delRule(
'dbUnique');
328 if ($this->cfg->stayConnected) {
329 $this->
form->
add(
'checkbox', array(
330 'name'=>
'stayConnected',
333 'valid'=>array(
'required'=>
false),
static htmlOut($val, $key=false)
login($prm=null, $page=null, $redirectIfLogged=true)
saveLogin($cookieStayConnected=false)
isContained(array $url, array $checks)
getWhereLogin($login, $pass)
static setFlash($name, $val=null)
saveCookieStayConnected()
getLoginForm(array $prm=array())
static getInstance(array $cfg=array())
static removeLangOutUrl($request)
check(array $url=null, $redirect=true)
getPage($type='login', $uri=false)
logFromCryptic($cryptic, $cookieStayConnected=false)
static get($type, $table, array $prm=array())
getUserFromCryptic($cryptic)
cryptPass($str, $plus='Password')
static get($className, array $cfg=array())
setUser(db_row $user, $saveLogin=true, $cookieStayConnected=false)