Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. <?php if(!defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Login extends CI_Controller
  4. {
  5. /**
  6. * This is default constructor of the class
  7. */
  8. public function __construct()
  9. {
  10. parent::__construct();
  11. $this->load->model('login_model');
  12. }
  13.  
  14. /**
  15. * Index Page for this controller.
  16. */
  17. public function index()
  18. {
  19. $this->isLoggedIn();
  20. }
  21.  
  22. /**
  23. * This function used to check the user is logged in or not
  24. */
  25. function isLoggedIn()
  26. {
  27. $isLoggedIn = $this->session->userdata('isLoggedIn');
  28.  
  29. if(!isset($isLoggedIn) || $isLoggedIn != TRUE)
  30. {
  31. $data['tahunajaran'] = $this->login_model->lihat_tahunajaran();
  32. $this->load->view('login', $data);
  33. }
  34. else
  35. {
  36. redirect('/dashboard');
  37. }
  38. }
  39.  
  40.  
  41. /**
  42. * This function used to logged in user
  43. */
  44. public function loginMe()
  45. {
  46. $this->load->library('form_validation');
  47.  
  48. $this->form_validation->set_rules('username', 'Username', 'required|max_length[128]|');
  49. $this->form_validation->set_rules('password', 'Password', 'required|max_length[32]|');
  50.  
  51. if($this->form_validation->run() == FALSE)
  52. {
  53. $this->index();
  54. }
  55. else
  56. {
  57. $username = $this->input->post('username');
  58. $password = $this->input->post('password');
  59. $thnajaran = $this->input->post('thnajaran');
  60. $tipe = $this->input->post('tipe');
  61. if($tipe != "Admin"){
  62. $result = $this->login_model->loginMe($username, $password);
  63.  
  64. }else{
  65. $result = $this->login_model->loginAdmin($username, $password);
  66. }
  67.  
  68.  
  69. if(count($result) > 0)
  70. {
  71. foreach ($result as $res)
  72. {
  73. if($tipe != "Admin"){
  74. $sessionArray = array('userId'=>$res->userId,
  75. 'idmatpel'=>$res->id_matpel,
  76. 'role'=>$res->roleId,
  77. 'roleText'=>$res->role,
  78. 'thnajaran'=>$thnajaran,
  79. 'name'=>$res->name,
  80. 'isLoggedIn' => TRUE
  81. );
  82. }else{
  83. $sessionArray = array('userId'=>$res->userId,
  84. 'role'=>$res->roleId,
  85. 'roleText'=>$res->role,
  86. 'thnajaran'=>$thnajaran,
  87. 'name'=>$res->name,
  88. 'isLoggedIn' => TRUE
  89. );
  90. }
  91.  
  92. $this->session->set_userdata($sessionArray);
  93.  
  94. redirect('/dashboard');
  95. }
  96. }
  97. else
  98. {
  99. $this->session->set_flashdata('error', 'Username or password mismatch');
  100.  
  101. redirect('/login');
  102. }
  103. }
  104. }
  105. }
  106.  
  107. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement