Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php defined('BASEPATH') OR exit('No direct script access allowed');
- class User extends CI_Controller {
- public function __construct() {
- parent::__construct();
- $this->load->library('ion_auth');
- $this->form_validation->set_error_delimiters($this->config->item('error_start_delimiter', 'ion_auth'), $this->config->item('error_end_delimiter', 'ion_auth'));
- $this->lang->load('auth');
- }
- public function index() {
- if (!$this->ion_auth->logged_in() || !$this->ion_auth->is_admin()) {
- // redirect them to the login page
- redirect('user/login', 'refresh');
- }
- }
- public function login() {
- //validate form input
- $this->form_validation->set_rules('identity', 'Identity', 'required');
- $this->form_validation->set_rules('password', 'Password', 'required');
- if ($this->form_validation->run() == TRUE) {
- // passed validation
- $identity = $this->input->post('email');
- $password = $this->input->post('password');
- $remember = (bool) $this->input->post('remember');
- if ($this->ion_auth->login($identity, $password, $remember)) {
- //if the login is successful
- //redirect them back to the dashboard
- $this->session->set_flashdata('message', $this->ion_auth->messages());
- redirect('admin/Dashboard', 'refresh');
- }
- else
- {
- // if the login was un-successful
- // redirect them back to the login page
- $this->session->set_flashdata('message', $this->ion_auth->errors());
- redirect('user/login', 'refresh');
- }
- }
- else
- {
- // the user is not logging in so display the login page
- // set the flash data error message if there is one
- $this->load->view('user/login');
- }
- }
- public function logout() {
- $this->data['title'] = "Logout";
- // log the user out
- $logout = $this->ion_auth->logout();
- // redirect them to the login page
- $this->session->set_flashdata('message', $this->ion_auth->messages());
- redirect('user/login', 'refresh');
- }
- }//end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement