Guest User

Untitled

a guest
Jul 18th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. <?php if (! defined('BASEPATH')) exit('No direct script access');
  2.  
  3. class Auth extends Controller {
  4.  
  5. function __construct() {
  6. parent::Controller();
  7. }
  8.  
  9. function index() {
  10. redirect('auth/login');
  11. }
  12.  
  13. function login()
  14. {
  15. if (!$this->auth_lib->is_logged_in()) {
  16. redirect('');
  17. } else {
  18. $this->load->library('validation');
  19.  
  20. // Lets set some rules for our login form
  21. $rules['username'] = "trim|required|callback_check_login";
  22. $rules['password'] = "trim|required";
  23. $this->validation->set_rules($rules);
  24.  
  25. // Now lets set the fields for those rules
  26. $fields['username'] = "Username";
  27. $fields['password'] = "Password";
  28. $this->validation->set_fields($fields);
  29.  
  30. $this->validation->set_error_delimiters('<p class="errors"><b>', '</b></p>');
  31.  
  32. if (!$this->validation->run()) {
  33. $this->load->view('auth/login');
  34. } else {
  35. redirect('');
  36. }
  37. }
  38. }
  39.  
  40. function check_login()
  41. {
  42. $username = $this->input->post('username');
  43. $password = $this->input->post('password');
  44.  
  45. if ($this->auth_lib->login($username, $password)) {
  46. $ref = $this->session->userdata('referrer');
  47. redirect($ref);
  48. } else {
  49. $this->validation->set_message('check_login', 'Your username or password was wrong');
  50. return FALSE;
  51. }
  52. }
  53.  
  54. function logout()
  55. {
  56. $this->auth_lib->logout();
  57. redirect('');
  58. }
  59.  
  60. }
Add Comment
Please, Sign In to add comment