Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. public function login_auth(){
  2. $this->form_validation->set_rules('user_username','User Name','required|trim');
  3. $this->form_validation->set_rules('user_password','User Password','required|trim|trim');
  4. if($this->form_validation->run()==false){
  5. $this->login_panel();
  6. }
  7. else{
  8. $this->load->model('Authentication_model');
  9. $input_data = array(
  10. 'user_username' => $this->input->post('user_username'),
  11. 'user_password' => sha1($this->input->post('user_password' );
  12. $login_data = $this->Authentication_model->get_data_login('ac_users',$input_data,1)->row_array();
  13. if(empty($login_data)){
  14. $input_username = array(
  15. 'user_username' => $this->input->post('user_username')
  16. );
  17. $login_username = $this->Authentication_model->get_data_login('ac_users',$input_username,1)->row_array();
  18. if(sizeof($login_username)>0){
  19. $this->update_login_attempts($login_username);
  20. $notification = array(
  21. 'sign' => 'alert alert-danger',
  22. 'msg' => 'Your input is wrong.'
  23. );
  24. }
  25. else if($login_username['max_login_attempt']>3){
  26. $this->update_login_attempts($login_username);
  27. $notification = array(
  28. 'sign' => 'alert alert-danger',
  29. 'msg' => 'Login attempts excedded.'
  30. );
  31. $captcha = array('captcha_show' => 'true');
  32. $this->create_session($captcha);
  33. }
  34. $this->error($notification);
  35. redirect('authentication/login_panel');
  36. }
  37. else if(isset($login_data) && sizeof($login_data)>0){
  38. if($login_data['user_suspend']){
  39. $notification = array(
  40. 'sign' => 'alert alert-danger',
  41. 'msg' => 'Your Account Is Blocked.'
  42. );
  43. $this->error($notification);
  44. redirect('authentication/login_panel');
  45. }
  46. if($login_data['user_branch_id'])
  47. $branch_name = 'Main';
  48. else if($login_data['user_branch_id']==0)
  49. $branch_name = 'All';
  50. $loginData = array(
  51. 'logged_in' => true,
  52. 'user_name' => $login_data['user_first_name'].$login_data['user_last_name'],
  53. 'user_id' => $login_data['user_id'],
  54. 'branch_id' => $login_data['user_branch_id'],
  55. 'user_group' => $login_data['user_group'],
  56. 'branch_name' => ucfirst($branch_name)
  57. );
  58. $where = array(
  59. 'user_id' => $login_data['user_id']
  60. );
  61. $update_data = array('user_date_last_login'=>date('Y-m-d g:i:s'));
  62. $this->Authentication_model->update_data('ac_users',$update_data,$where);
  63. $this->create_session($loginData);
  64. $notification = array(
  65. 'sign' => 'alert alert-success',
  66. 'msg' => 'You are logged in successfully'
  67. );
  68. $this->error($notification);
  69. redirect('master/index');
  70. }
  71. else{
  72. $notification = array(
  73. 'sign' => 'alert alert-danger',
  74. 'msg' => 'Your input is wrong.'
  75. );
  76. $this->error($notification);
  77. redirect('authentication/login_panel');
  78. }
  79. }
  80. }
  81.  
  82. class Authentication_model extends CI_Model {
  83.  
  84. public function insert_data($tbl='',$data=''){
  85. return $this->db->insert($tbl,$data);
  86. }
  87. public function get_data($tbl='',$where=''){
  88. if(!empty($where)){
  89. $this->db->where($where);
  90. }
  91. return $this->db->get($tbl);
  92. }
  93. public function get_data_limit($tbl='',$where='',$limit='',$offset=''){
  94. if(!empty($where)){
  95. $this->db->limit($limit,$offset);
  96. $this->db->where($where);
  97. }
  98. return $this->db->get($tbl);
  99. }
  100. public function get_data_login($tbl='',$where='',$limit=''){
  101. if(!empty($where)){
  102. $this->db->limit($limit);
  103. $this->db->where($where);
  104. }
  105. return $this->db->get($tbl);
  106. }
  107. public function count_all_data($tbl='',$where=''){
  108. if(!empty($where)){
  109. $this->db->where($where);
  110. }
  111. return $this->db->count_all_results($tbl);
  112. }
  113. public function update_data($tbl='',$update_data='',$where=''){
  114. if(!empty($where)){
  115. $this->db->where($where);
  116. }
  117. return $this->db->update($tbl,$update_data);
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement