Hello,
For my second post i will give you my login interface that use SESSION auth. It's maybe not the better code you ever seen ^^.
If someone want upgrade the code, post here your updates :).
I'm so sorry but i don't generate a registration page.
ALL MODIFICATIONS ARE IN DOWNLOAD FILES AT THE BOTTOM. i'll not present the global code. Just some important modifications.
Well, to start that tuto you have to generate 2 new views :
- login.php
- recover.php
Next, you have to change your default route in : appplication/config/routes.php to redirect in login interface (only if you want a codeigniter admin).
$route['default_controller'] = "admin"; $route['admin/(:any)'] = 'admin/index'; $route['recover'] = 'admin/recover';
here you say at codeigniter to start in admin controller (he will ask you to login before access to home controller).
well, now you have to import the SQL file at your sql database. It will generate a users table with one row :
login : admin@admin
password : admin
if u want change your email address, you could easely with mysql remote. (update compte email ...).
well now you just have to go in your baseurl lie : http://localhost/myfolderapp/
If you have change your default controller to my admin controller, you will enter at login interface.
But know we have to blocked the admin GC access. It's really easy because the login function use $_SESSION.
You have to add that specials line at your home controller (administration GC controller) in the construct magick function :
if (!isset($_SESSION['username']) ) { redirect('my-login-route-or-let-it-blank'); }
in the .zip file, you will have an example with a grocery function to admin users :
public function __construct(){ parent::__construct(); $this->load->database(); $this->load->helper('url'); $this->load->model('home_model'); $this->load->library('grocery_CRUD'); if (!isset($_SESSION['username']) ) { redirect(''); }else{ $this->template->set('title', 'Tableau de bord'); $this->template->set('nom', $_SESSION["nom"]); } } public function comptes() { $me = $this ->db ->where('email_address', $_SESSION['username']) ->limit(1) ->get('users'); $crud = new grocery_CRUD(); $crud->set_table('users'); $crud->set_subject('Comptes'); $this->template->set('title', 'Gestion des comptes'); $crud->field_type('password', 'password'); $crud->where('id >=',$me->row()->id); $crud->callback_before_insert(array($this,'encrypt_password_callback')); $crud->callback_before_update(array($this,'encrypt_password_callback')); $crud->callback_edit_field('password',array($this,'decrypt_password_callback')); $output = $crud->render(); $this->template->load('layouts/admin', 'admin/actu',$output); }
i hope that my work will help some gorcery users.
It's maybe not a good practice but it works. I create this admin 4 months ago at my first grocery app. I know that it is not the better solution. That's why if someone want help this topic and somes new GC users, he could post here an other solution.
bb ;)