Advertisement
Bucurion

User controller

Dec 29th, 2015
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2.  
  3. class User extends CI_Controller {
  4.  
  5. public function __construct() {
  6. parent::__construct();
  7. $this->load->library('ion_auth');
  8. $this->form_validation->set_error_delimiters($this->config->item('error_start_delimiter', 'ion_auth'), $this->config->item('error_end_delimiter', 'ion_auth'));
  9.  
  10. $this->lang->load('auth');
  11. }
  12.  
  13. public function index() {
  14.  
  15. if (!$this->ion_auth->logged_in() || !$this->ion_auth->is_admin()) {
  16. // redirect them to the login page
  17. redirect('user/login', 'refresh');
  18. }
  19.  
  20. }
  21.  
  22.  
  23. public function login() {
  24.  
  25.  
  26. //validate form input
  27. $this->form_validation->set_rules('identity', 'Identity', 'required');
  28. $this->form_validation->set_rules('password', 'Password', 'required');
  29.  
  30. if ($this->form_validation->run() == TRUE) {
  31. // passed validation
  32. $identity = $this->input->post('email');
  33. $password = $this->input->post('password');
  34. $remember = (bool) $this->input->post('remember');
  35.  
  36. if ($this->ion_auth->login($identity, $password, $remember)) {
  37.  
  38. //if the login is successful
  39. //redirect them back to the dashboard
  40. $this->session->set_flashdata('message', $this->ion_auth->messages());
  41. redirect('admin/Dashboard', 'refresh');
  42. }
  43.  
  44. else
  45. {
  46. // if the login was un-successful
  47. // redirect them back to the login page
  48. $this->session->set_flashdata('message', $this->ion_auth->errors());
  49. redirect('user/login', 'refresh');
  50. }
  51. }
  52. else
  53. {
  54. // the user is not logging in so display the login page
  55. // set the flash data error message if there is one
  56. $this->load->view('user/login');
  57. }
  58. }
  59.  
  60.  
  61.  
  62. public function logout() {
  63.  
  64. $this->data['title'] = "Logout";
  65.  
  66. // log the user out
  67. $logout = $this->ion_auth->logout();
  68.  
  69. // redirect them to the login page
  70. $this->session->set_flashdata('message', $this->ion_auth->messages());
  71. redirect('user/login', 'refresh');
  72.  
  73.  
  74. }
  75.  
  76.  
  77.  
  78.  
  79. }//end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement