Advertisement
Guest User

auth.php

a guest
Dec 15th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. <?php
  2.  
  3. defined('BASEPATH') OR exit('No direct script access allowed');
  4.  
  5. class Auth extends Admin_Controller
  6. {
  7.  
  8. public function __construct()
  9. {
  10. parent::__construct();
  11.  
  12. $this->load->model('model_auth');
  13. }
  14.  
  15. /*
  16. Check if the login form is submitted, and validates the user credential
  17. If not submitted it redirects to the login page
  18. */
  19. public function login()
  20. {
  21.  
  22. $this->logged_in();
  23.  
  24. $this->form_validation->set_rules('email', 'Email', 'required');
  25. $this->form_validation->set_rules('password', 'Password', 'required');
  26.  
  27. if ($this->form_validation->run() == TRUE) {
  28. // true case
  29. $email_exists = $this->model_auth->check_email($this->input->post('email'));
  30.  
  31. if($email_exists == TRUE) {
  32. $login = $this->model_auth->login($this->input->post('email'), $this->input->post('password'));
  33.  
  34. if($login) {
  35.  
  36. $logged_in_sess = array(
  37. 'id' => $login['id'],
  38. 'username' => $login['username'],
  39. 'email' => $login['email'],
  40. 'logged_in' => TRUE
  41. );
  42.  
  43. $this->session->set_userdata($logged_in_sess);
  44. redirect('dashboard', 'refresh');
  45. }
  46. else {
  47. $this->data['errors'] = 'Incorrect username/password combination';
  48. $this->load->view('login', $this->data);
  49. }
  50. }
  51. else {
  52. $this->data['errors'] = 'Email does not exists';
  53.  
  54. $this->load->view('login', $this->data);
  55. }
  56. }
  57. else {
  58. // false case
  59. $this->load->view('login');
  60. }
  61. }
  62.  
  63. /*
  64. clears the session and redirects to login page
  65. */
  66. public function logout()
  67. {
  68. $this->session->sess_destroy();
  69. redirect('auth/login', 'refresh');
  70. }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement