Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function submit($post_username = NULL, $post_password = NULL)
- {
- $output_error = 'TRUE';
- $output_title = 'Not processed';
- $output_message = 'The request was unprocessed!';
- if ($this->users_model->is_logged_in($this->session->userdata('xtr')) === FALSE)
- {
- $data = array();
- $x = 0;
- if ($this->input->post()) { $data = $this->input->post(); } else { $x++; }
- if ($this->input->get()) { $data = $this->input->get(); } else { $x++; }
- if ($x == 2)
- {
- if ($this->functions_model->null_check($post_username) === FALSE) { $data['username'] = $post_username; }
- if ($this->functions_model->null_check($post_password) === FALSE) { $data['password'] = $post_password; }
- }
- if (count($data) > 0)
- {
- $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|strtolower');
- $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
- if ($this->form_validation->run())
- {
- $x = 0;
- $post_username = $data['username'];
- $post_password = $data['password'];
- date_default_timezone_set('GMT');
- $current_gmt_time = time();
- $user_data = $this->users_model->get_user_data('', $post_username);
- if ($user_data !== NULL)
- {
- if ($user_data->lock_date !== '0000-00-00 00:00:00')
- {
- $output_title = 'Account Locked';
- $output_message = 'Your account is currently locked due to too many failed login attempts. Please wait the allotted time and you will be able to login again!';
- $x++;
- }
- else
- {
- $this->users_model->unlock_user($user_data->user_id);
- $this->submit($post_username, $post_password);
- return false;
- }
- if ($x == 0)
- {
- if ($user_data->user_status_id == '1')
- {
- $output_title = 'Account not verified';
- $output_message = 'Sorry you must verify your account before logging in!';
- $x++;
- }
- if ($user_data->user_status_id == '3')
- {
- $output_title = 'Account Suspended';
- $output_message = 'Your account has been suspended!';
- $x++;
- }
- if ($user_data->user_status_id == '4')
- {
- $output_title = 'Account Banned';
- $output_message = 'Your account has been banned!';
- $x++;
- }
- if ($user_data->user_status_id == '5')
- {
- $output_title = 'Account Deleted';
- $output_message = 'Your account has been deleted!';
- $x++;
- }
- if ($x == 0)
- {
- $regenerated_post_password = $this->functions_model->regenerate_password_hash($post_password, $user_data->password_hash);
- $failed_logins = $this->session->userdata('failed_logins');
- if ($regenerated_post_password == $user_data->password)
- {
- $profile_data = $this->users_model->get_profile_data($user_data->user_id);
- $this->session->set_userdata('xtr', $user_data->user_id);
- $this->session->unset_userdata('failed_logins');
- $output_error = 'FALSE';
- $output_title = 'Login Success';
- $output_message = 'Successful login! Sending you to the dashboard';
- }
- else
- {
- if (is_numeric($failed_logins))
- {
- if ($failed_logins == ((int)$this->config->item('failed_login_limit') - 1))
- {
- $wait_time = $this->config->item('wait_time');
- $wait_time = $current_gmt_time + $wait_time;
- $lock_out_date = gmdate('Y-m-d H:i:s', $wait_time);
- $this->users_model->lock_out_user($user_data->user_id, $lock_out_date);
- $this->functions_model->send_email('maximum_failed_login_attempts_exceeded', $user_data->email_address, $user_data);
- $output_title = 'Account Locked';
- $output_message = 'Your account is currently locked, we apologize for the inconvienence. You must wait 15 minutes befor eyou can login again! An email was sent to the owner of this account! Forgotten your username or password? <a href="forgotusername">Forgot Username</a> or <a href="forgotpassword">Forgot Password</a>';
- }
- else
- {
- $failed_logins++;
- $this->session->set_userdata('failed_logins', $failed_logins);
- $output_title = 'Incorrect Credentials';
- $output_message = 'Incorrect username and password combination!';
- }
- }
- else
- {
- $this->session->set_userdata('failed_logins', '1');
- $output_title = 'Incorrect Credentials';
- $output_message = 'Incorrect username and password combination!';
- }
- $time_of_attempt = gmdate('Y-m-d H:i:s');
- $this->users_model->increase_login_attempt($this->input->ip_address(), $post_username, $time_of_attempt);
- }
- }
- }
- }
- else
- {
- $output_title = 'User not found';
- $output_message = 'User was not found in the database!';
- }
- }
- else
- {
- $output_title = 'Form not submitted';
- $output_message = validation_errors();
- }
- }
- else
- {
- $output_title = 'No data';
- $output_message = 'There is no data to work with!';
- }
- }
- else
- {
- $output_title = 'Session Available';
- $output_message = 'You are already logged in!';
- }
- echo json_encode(array('error' => $output_error, 'title' => $output_title, 'message' => $output_message));
- }
- }
Add Comment
Please, Sign In to add comment