diff --git a/lib/Auth/Basic.php b/lib/Auth/Basic.php index 9c4ffa616..df63eb334 100644 --- a/lib/Auth/Basic.php +++ b/lib/Auth/Basic.php @@ -75,7 +75,16 @@ function init(){ $this->info=$this->recall('info',false); } - /** Create an array model and specify it for authentication as a quick way to get authentication working */ + + /** + * Configure this Auth controller with a generic Model based on static + * collection of user/password combinations. Use this method if you + * only want one or few accounts to access the system. + * + * @param mixed $user Either string username or associative array with data + * @param mixed $pass Password if username is string + * @return $this + */ function allow($user,$pass=null){ // creates fictional model to allow specified user and password // TODO: test this @@ -89,7 +98,17 @@ function allow($user,$pass=null){ $this->setModel($m); return $this; } - /** Specify user model */ + /** + * Associate model with authentication class. Username / password + * check will be performed against the model in the following steps: + * Model will attempt to load record where login_field matches + * specified. Password is then loaded and verified using configured + * encryption method. + * + * @param [type] $model [description] + * @param string $login_field [description] + * @param string $password_field [description] + */ function setModel($model,$login_field='email',$password_field='password'){ parent::setModel($model); $this->login_field=$login_field; @@ -138,8 +157,11 @@ function setModel($model,$login_field='email',$password_field='password'){ return $this->model; } - /** Adds a hook to specified model which will encrypt password before save. Do not call - * on api->auth->model, because that model already has the hook */ + /** + * Adds a hook to specified model which will encrypt password before save. + * This method will be applied on $this->model, so you should not call + * it manually. You can call it on a fresh model, however. + */ function addEncryptionHook($model){ // If model is saved, encrypt password $t=$this; @@ -167,8 +189,10 @@ function get($property=null,$default=null){ function getAll(){ return $this->info; } - /** Specify page or array of pages which will exclude authentication. Add your registration page here - * or page containing terms and conditions */ + /** + * Specify page or array of pages which will exclude authentication. Add your registration page here + * or page containing terms and conditions + */ function allowPage($page){ if(is_array($page)){ foreach($page as $p)$this->allowPage($p); @@ -180,12 +204,31 @@ function allowPage($page){ function getAllowedPages(){ return $this->allowed_pages; } + /** + * Verifies if the specified page is allowed to be accessed without + * authentication. + * + * @param [type] $page [description] + * @return boolean [description] + */ function isPageAllowed($page){ if($this->hook('isPageAllowed',array($page))===true)return true; return in_array($page,$this->allowed_pages) || in_array(str_replace('_','/',$page),$this->allowed_pages); } - /** Specifies how password will be encrypted when stored. Some values are "sha256/salt", "md5", "rot13". If you - * don't call this, passwords will be stored in plain-text */ + + /** + * Specifies how password will be encrypted when stored. It's recommended + * that you do not specify encryption method, in which case a built-in + * password_hash() will be used, which is defined by PHP. + * + * Some other values are "sha256/salt", "md5", "rot13". Note that + * if your application is already using 'md5' or 'sha1', you can + * remove the argument entirely and your user passwords will keep + * working and wil automatically be "upgraded" to password_hash + * when used. + * + * If you are having trouble with authentication, use auth->debug() + */ function usePasswordEncryption($method='php'){ $this->password_encryption=$method; return $this; @@ -214,12 +257,14 @@ function encryptPassword($password,$salt=null){ default: throw $this->exception('No such encryption method')->addMoreInfo('encryption',$this->password_encryption); } } - /** Call this function to perform a check for logged in user. This will also display a login-form + /** + * Call this function to perform a check for logged in user. This will also display a login-form * and will verify user's credential. If you want to handle log-in form on your own, use * auth->isLoggedIn() to check and redirect user to a login page. * * check() returns true if user have just logged in and will return "null" for requests when user - * continues to use his session. Use that to perform some calculation on log-in */ + * continues to use his session. Use that to perform some calculation on log-in + */ function check(){ if($this->isPageAllowed($this->api->page))return null; // no authentication is required @@ -264,14 +309,14 @@ function addInfo($key,$val=null){ $this->info[$key]=$val; return $this; } - /** Returns if user is authenticated or not. For more info on user see auth->model */ + /** + * This function determines - if user is already logged in or not. It does it by + * looking at $this->info, which was loaded during init() from session. + */ function isLoggedIn(){ - /* - * This function determines - if user is already logged in or not. It does it by - * looking at $this->info, which was loaded during init() from session. - */ return $this->model->loaded(); } + /** * This function verifies credibility of supplied authenication data. * It will search based on user and verify the password. It's also @@ -421,7 +466,9 @@ function getURL(){ $this->forget('url');$this->forget('args'); return $url; } - /** Rederect to page user tried to access before authentication was requested */ + /** + * Rederect to page user tried to access before authentication was requested + */ function loginRedirect(){ $this->debug("to Index"); $this->api->redirect($this->getURL()); @@ -435,7 +482,9 @@ function loggedIn($user=null,$pass=null){ //$username,$password,$memorize=false) $this->hook('loggedIn',array($user,$pass)); $this->api->redirect($this->getURL()); } - /** Store model in session data so that it can be retrieved faster */ + /** + * Store model in session data so that it can be retrieved faster + */ function memorizeModel(){ if(!$this->model->loaded())throw $this->exception('Authentication failure','AccessDenied'); @@ -455,13 +504,17 @@ function memorizeModel(){ $this->hook('login'); } - /** Manually Log in as specified users. Will not perform password check or redirect */ + /** + * Manually Log in as specified users. Will not perform password check or redirect + */ function loginByID($id){ $this->model->load($id); $this->memorizeModel(); return $this; } - /** Manually Log in with specified condition */ + /** + * Manually Log in with specified condition + */ function loginBy($field,$value){ $this->model->tryLoadBy($field,$value); $this->memorizeModel(); diff --git a/lib/Model.php b/lib/Model.php index e5d0b0302..f3e02d15a 100644 --- a/lib/Model.php +++ b/lib/Model.php @@ -764,7 +764,9 @@ public function deleteAll() return $this; } - /** Unloads then loads current record back. Use this if you have added new fields */ + /** + * Unloads then loads current record back. Use this if you have added new fields + */ public function reload() { return $this->load($this->id); diff --git a/lib/Paginator/Basic.php b/lib/Paginator/Basic.php index aaa06686b..39dd99b78 100644 --- a/lib/Paginator/Basic.php +++ b/lib/Paginator/Basic.php @@ -30,7 +30,11 @@ class Paginator_Basic extends CompleteLister { function init(){ parent::init(); - if(!$this->skip_var)$this->skip_var=$this->name.'_skip'; + + if (!$this->skip_var) { + $this->skip_var = $this->name . '_skip'; + } + $this->skip_var = $this->_shorten($this->skip_var); } /** Set number of items displayed per page */ @@ -106,9 +110,6 @@ function recursiveRender(){ $this->cur_page=floor($this->skip / $this->ipp) +1; $this->total_pages = ceil($this->found_rows / $this->ipp); - // no need for paginator if there is only one page - if($this->total_pages<=1)return $this->destroy(); - if($this->cur_page>$this->total_pages || ($this->cur_page==1 && $this->skip!=0)){ $this->cur_page=1; if($this->memorize){ @@ -125,22 +126,10 @@ function recursiveRender(){ } } + // no need for paginator if there is only one page + if($this->total_pages<=1)return $this->destroy(); - // generate source for Paginator Lister (pages, links, labels etc.) - $data=array(); - - - /* if($this->cur_page>1){ - - $data[]=array( - 'href'=>$this->api->url($this->base_page,array($this->skip_var=>$pn=($p-1)*$this->ipp)), - 'pn'=>$pn, - 'cur'=>$p==$this->cur_page?$this->template->get('cur'):'', - 'label'=>'«' - ); - - $this->add('View',null,'prev') ->setElement('a') ->setAttr('href',$this->api->url($this->base_page,$u=array($this->skip_var=> @@ -149,7 +138,7 @@ function recursiveRender(){ ->setAttr('data-skip',$pn) ->set('<') ; - }else $first=null; + } if($this->cur_page<$this->total_pages){ $this->add('View',null,'next') @@ -198,14 +187,19 @@ function recursiveRender(){ } } - */ + // generate source for Paginator Lister (pages, links, labels etc.) + $data=array(); + //setting cur as array seems not working in atk4.3. String is working + $tplcur = $this->template->get('cur'); + $tplcur = (isset($tplcur[0])) ? $tplcur[0] : ''; - foreach(range(max(1,$this->cur_page-$this->range), min($this->total_pages, $this->cur_page+$this->range)) as $p){ - $data[]=array( + foreach(range(max(1,$this->cur_page-$this->range), min($this->total_pages, $this->cur_page+$this->range)) as $p) + { + $data[]=array( 'href'=>$this->api->url($this->base_page,array($this->skip_var=>$pn=($p-1)*$this->ipp)), 'pn'=>$pn, - 'cur'=>$p==$this->cur_page?$this->template->get('cur'):'', + 'cur'=>$p==$this->cur_page?$tplcur:'', 'label'=>$p ); } diff --git a/lib/View/CRUD.php b/lib/View/CRUD.php index 85fe75b62..ec59bfde3 100644 --- a/lib/View/CRUD.php +++ b/lib/View/CRUD.php @@ -78,7 +78,7 @@ class View_CRUD extends View * * $this->add('CRUD', array('allow_add'=>false')); // to disable */ - protected $allow_add=true; + public $allow_add=true; /** * Grid will contain "EDIT" button for each row allowing usir to edit @@ -86,7 +86,7 @@ class View_CRUD extends View * * $this->add('CRUD', array('allow_edit'=>false')); // to disable */ - protected $allow_edit=true; + public $allow_edit=true; /** * Grid will contain a "DELETE" button for each row. If you don't want @@ -94,7 +94,7 @@ class View_CRUD extends View * * $this->add('CRUD', array('allow_del'=>false')); // to disable */ - protected $allow_del=true; + public $allow_del=true; /** * For ->setModel('User'), your add button would contain "Add User". If @@ -269,6 +269,8 @@ public function setModel($model, $fields = null, $grid_fields = null) if ($this->configureAdd($fields)) { return $model; } + } elseif (isset($this->add_button)) { + $this->add_button->destroy(); } if ($this->allow_edit) {