Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function login_auth(){
- $this->form_validation->set_rules('user_username','User Name','required|trim');
- $this->form_validation->set_rules('user_password','User Password','required|trim|trim');
- if($this->form_validation->run()==false){
- $this->login_panel();
- }
- else{
- $this->load->model('Authentication_model');
- $input_data = array(
- 'user_username' => $this->input->post('user_username'),
- 'user_password' => sha1($this->input->post('user_password' );
- $login_data = $this->Authentication_model->get_data_login('ac_users',$input_data,1)->row_array();
- if(empty($login_data)){
- $input_username = array(
- 'user_username' => $this->input->post('user_username')
- );
- $login_username = $this->Authentication_model->get_data_login('ac_users',$input_username,1)->row_array();
- if(sizeof($login_username)>0){
- $this->update_login_attempts($login_username);
- $notification = array(
- 'sign' => 'alert alert-danger',
- 'msg' => 'Your input is wrong.'
- );
- }
- else if($login_username['max_login_attempt']>3){
- $this->update_login_attempts($login_username);
- $notification = array(
- 'sign' => 'alert alert-danger',
- 'msg' => 'Login attempts excedded.'
- );
- $captcha = array('captcha_show' => 'true');
- $this->create_session($captcha);
- }
- $this->error($notification);
- redirect('authentication/login_panel');
- }
- else if(isset($login_data) && sizeof($login_data)>0){
- if($login_data['user_suspend']){
- $notification = array(
- 'sign' => 'alert alert-danger',
- 'msg' => 'Your Account Is Blocked.'
- );
- $this->error($notification);
- redirect('authentication/login_panel');
- }
- if($login_data['user_branch_id'])
- $branch_name = 'Main';
- else if($login_data['user_branch_id']==0)
- $branch_name = 'All';
- $loginData = array(
- 'logged_in' => true,
- 'user_name' => $login_data['user_first_name'].$login_data['user_last_name'],
- 'user_id' => $login_data['user_id'],
- 'branch_id' => $login_data['user_branch_id'],
- 'user_group' => $login_data['user_group'],
- 'branch_name' => ucfirst($branch_name)
- );
- $where = array(
- 'user_id' => $login_data['user_id']
- );
- $update_data = array('user_date_last_login'=>date('Y-m-d g:i:s'));
- $this->Authentication_model->update_data('ac_users',$update_data,$where);
- $this->create_session($loginData);
- $notification = array(
- 'sign' => 'alert alert-success',
- 'msg' => 'You are logged in successfully'
- );
- $this->error($notification);
- redirect('master/index');
- }
- else{
- $notification = array(
- 'sign' => 'alert alert-danger',
- 'msg' => 'Your input is wrong.'
- );
- $this->error($notification);
- redirect('authentication/login_panel');
- }
- }
- }
- class Authentication_model extends CI_Model {
- public function insert_data($tbl='',$data=''){
- return $this->db->insert($tbl,$data);
- }
- public function get_data($tbl='',$where=''){
- if(!empty($where)){
- $this->db->where($where);
- }
- return $this->db->get($tbl);
- }
- public function get_data_limit($tbl='',$where='',$limit='',$offset=''){
- if(!empty($where)){
- $this->db->limit($limit,$offset);
- $this->db->where($where);
- }
- return $this->db->get($tbl);
- }
- public function get_data_login($tbl='',$where='',$limit=''){
- if(!empty($where)){
- $this->db->limit($limit);
- $this->db->where($where);
- }
- return $this->db->get($tbl);
- }
- public function count_all_data($tbl='',$where=''){
- if(!empty($where)){
- $this->db->where($where);
- }
- return $this->db->count_all_results($tbl);
- }
- public function update_data($tbl='',$update_data='',$where=''){
- if(!empty($where)){
- $this->db->where($where);
- }
- return $this->db->update($tbl,$update_data);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement