Advertisement
Guest User

validate_login

a guest
Jun 26th, 2022
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. public function validate_login($from = "")
  2. {
  3. if ($this->crud_model->check_recaptcha() == false && get_frontend_settings('recaptcha_status') == true) {
  4. $this->session->set_flashdata('error_message', get_phrase('recaptcha_verification_failed'));
  5. redirect(site_url('home/login'), 'refresh');
  6. }
  7.  
  8. $email = $this->input->post('email');
  9. $password = $this->input->post('password');
  10. $credential = array('email' => $email, 'password' => sha1($password), 'status' => 1);
  11.  
  12. // Checking login credential for admin
  13. $query = $this->db->get_where('users', $credential);
  14.  
  15. if ($query->num_rows() > 0) {
  16. $row = $query->row();
  17. $this->session->set_userdata('user_id', $row->id);
  18. $this->session->set_userdata('role_id', $row->role_id);
  19. $this->session->set_userdata('role', get_user_role('user_role', $row->id));
  20. $this->session->set_userdata('name', $row->first_name . ' ' . $row->last_name);
  21. $this->session->set_userdata('is_instructor', $row->is_instructor);
  22. $this->session->set_flashdata('flash_message', get_phrase('welcome') . ' ' . $row->first_name . ' ' . $row->last_name);
  23. if ($row->role_id == 1) {
  24. if ($this->input->post('rememberme')){
  25. set_cookie("email",$email, 2 * 60);
  26. set_cookie("password",$password, 2 * 60);
  27. $this->session->set_userdata('admin_login', '1');
  28. redirect(site_url('admin/dashboard'), 'refresh');
  29. }else {
  30. $this->session->set_userdata('admin_login', '1');
  31. redirect(site_url('admin/dashboard'), 'refresh');
  32. }
  33. } else if ($row->role_id == 2) {
  34. if ($this->input->post('rememberme')){
  35. set_cookie("email",$email, 2 * 60);
  36. set_cookie("password",$password, 2 * 60);
  37. $this->session->set_userdata('user_login', '1');
  38.  
  39. if($this->session->userdata('url_history')){
  40. redirect($this->session->userdata('url_history'), 'refresh');
  41. }
  42. redirect(site_url('home'), 'refresh');
  43. }else{
  44. $this->session->set_userdata('user_login', '1');
  45.  
  46. if($this->session->userdata('url_history')){
  47. redirect($this->session->userdata('url_history'), 'refresh');
  48. }
  49. redirect(site_url('home'), 'refresh');
  50. }
  51. }
  52. } else {
  53. $this->session->set_flashdata('error_message', get_phrase('invalid_login_credentials'));
  54. redirect(site_url('home/login'), 'refresh');
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement