Hmmm.
Det gjorde mig lidt klogere at se lidt små film om dette ACL på youtube.
Men problemet er blot at jeg har rigtig svært ved at forstå hvordan jeg implementere det i mit CI projekt.
Jeg har skrevet et mindre authentication script selv ud fra en tutorial.
- <?php
-
- class User extends Admin_Controller {
-
- public function __construct(){
- parent::__construct();
- }
-
- public function login(){
- //Sæt view til screen ved logget ind
- $dashboard = 'dashboard';
-
- //Er brugeren logget ind, send brugeren videre
- $this->user_m->loggedin() == FALSE || redirect($dashboard);
-
- //Gem validerings regler
- $rules = $this->user_m->rules;
-
- //Sæt validerings regler ind i lib
- $this->form_validation->set_rules($rules);
-
- //Går validering igennem
- if ($this->form_validation->run() == TRUE) {
- // Check om bruger findes i databasen via model
- if ($this->user_m->login() == TRUE) {
- //Send brugeren til logget ind screen
- redirect($dashboard);
- }
- else {
- //Findes brugeren ikke så klargør besked
- $this->session->set_flashdata('error', $this->lang->line('login_error'));
- //Send brugeren til login med besked om fejl
- redirect('user/login', 'refresh');
- }
- }
-
- //Sæt data til viewt
- $this->data['subview'] = 'login/login_form'; //Loader login form view.
- $this->data['login_title'] = $this->lang->line('login_title');
- $this->data['login_username'] = $this->lang->line('login_username');
- $this->data['login_password'] = $this->lang->line('login_password');
- $this->data['login_remember_me'] = $this->lang->line('login_remember_me');
- $this->data['login_button'] = $this->lang->line('login_button');
- $this->data['forgot_password_title'] = $this->lang->line('forgot_password_title');
- $this->data['login_footer_contact'] = $this->lang->line('login_footer_contact');
- $this->data['login_footer_email'] = $this->lang->line('login_footer_email');
- $this->data['login_footer_text'] = $this->lang->line('login_footer_text');
-
- //Load view med data
- $this->load->view('login/login_view', $this->data);
- }
-
- public function logout(){
- //Kald method i model logout og nedlæg session
- $this->user_m->logout();
-
- //Send brugeren til login screen
- redirect('user/login');
- }
-
-
- public function forgot_password(){
-
- //Gem validerings regler
- $rules = $this->user_m->rules_forgot;
-
- //Sæt validerings regler ind i lib
- $this->form_validation->set_rules($rules);
-
- //Går validering igennem?
- if($this->form_validation->run() == TRUE){
- //Find bruger i db
-
- //Lav ny adgangskode
-
- //Send kode til brugerens email
- }
-
-
- //Sæt data til viewet
- $this->data['subview'] = 'login/login_forgot_password'; //Loader glemt adgangskode view.
- $this->data['login_title'] = $this->lang->line('forgot_password_title');
- $this->data['forgot_password_text'] = $this->lang->line('forgot_password_text');
- $this->data['forgot_password_label'] = $this->lang->line('forgot_password_label');
- $this->data['forgot_password_button'] = $this->lang->line('forgot_password_button');
- $this->data['forgot_password_title'] = $this->lang->line('forgot_password_title');
- $this->data['login_footer_contact'] = $this->lang->line('login_footer_contact');
- $this->data['login_footer_email'] = $this->lang->line('login_footer_email');
- $this->data['login_footer_text'] = $this->lang->line('login_footer_text');
-
- //Load view med data
- $this->load->view('login/login_view', $this->data);
- }
- }
- <?php
- class MY_Model extends CI_Model {
-
- protected $_table_name = '';
- protected $_primary_key = 'id';
- protected $_primary_filter = 'intval';
- protected $_order_by = '';
- public $rules = array();
- protected $_timestamps = FALSE;
-
- function __construct() {
- parent::__construct();
- }
-
- public function get($id = NULL, $single = FALSE){
-
- if ($id != NULL) {
- $filter = $this->_primary_filter;
- $id = $filter($id);
- $this->db->where($this->_primary_key, $id);
- $method = 'row';
- }
- elseif($single == TRUE) {
- $method = 'row';
- }
- else {
- $method = 'result';
- }
-
- if (!count($this->db->ar_orderby)) {
- $this->db->order_by($this->_order_by);
- }
- return $this->db->get($this->_table_name)->$method();
- }
-
- public function get_by($where, $single = FALSE){
- $this->db->where($where);
- return $this->get(NULL, $single);
- }
-
- public function save($data, $id = NULL){
-
- // Set timestamps
- if ($this->_timestamps == TRUE) {
- $now = date('Y-m-d H:i:s');
- $id || $data['created'] = $now;
- $data['modified'] = $now;
- }
-
- // Insert
- if ($id === NULL) {
- !isset($data[$this->_primary_key]) || $data[$this->_primary_key] = NULL;
- $this->db->set($data);
- $this->db->insert($this->_table_name);
- $id = $this->db->insert_id();
- }
- // Update
- else {
- $filter = $this->_primary_filter;
- $id = $filter($id);
- $this->db->set($data);
- $this->db->where($this->_primary_key, $id);
- $this->db->update($this->_table_name);
- }
-
- return $id;
- }
-
- public function delete($id){
- $filter = $this->_primary_filter;
- $id = $filter($id);
-
- if (!$id) {
- return FALSE;
- }
- $this->db->where($this->_primary_key, $id);
- $this->db->limit(1);
- $this->db->delete($this->_table_name);
- }
- }
- <?php
- class User_M extends MY_Model {
-
- protected $_table_name = 'users';
- protected $_order_by = 'name';
-
- public $rules = array(
- 'username' => array(
- 'field' => 'username',
- 'label' => 'Brugernavn',
- 'rules' => 'trim|required|xss_clean'
- ),
- 'password' => array(
- 'field' => 'password',
- 'label' => 'Adgangskode',
- 'rules' => 'trim|required'
- )
- );
-
- public $rules_forgot = array(
- 'email' => array(
- 'field' => 'email',
- 'label' => 'Email',
- 'rules' => 'trim|required|valid_email|xss_clean'
- )
- );
-
- function __construct(){
- parent::__construct();
- }
-
- public function login(){
- $user = $this->get_by(array(
- 'username' => $this->input->post('username'),
- 'password' => $this->hash($this->input->post('password')),
- ), TRUE);
-
- if(count($user)){
- //Log ind user
- $data = array(
- 'name' => $user->name,
- 'email' => $user->email,
- 'id' => $user->id,
- 'loggedin' => TRUE
- );
- $this->session->set_userdata($data);
- }
- }
-
- public function logout(){
- $this->session->sess_destroy();
- }
-
- public function loggedin(){
- return (bool) $this->session->userdata('loggedin');
- }
-
- public function hash($string){
- return hash('sha512', $string . config_item('encryption_key'));
- }
- }
Jeg er helt lost på hvordan jeg skal tilføje dette ACL, som et eller andet sted giver en lille mening i mit hoved