I am trying to create a login with a staff code or email.
My code is:
public function admin()
{
if (is_staff_logged_in()) {
redirect(admin_url());
}
$this->form_validation->set_rules('password', _l('admin_auth_login_password'), 'required');
$this->form_validation->set_rules('email' OR 'staff_code', _l('admin_auth_login_email_or_staff_code'), 'trim|required');
if (show_recaptcha()) {
$this->form_validation->set_rules('g-recaptcha-response', 'Captcha', 'callback_recaptcha');
}
if ($this->input->post()) {
if ($this->form_validation->run() !== false) {
$email = $this->input->post('email');
$staff_code = $this->input->post('staff_code');
$password = $this->input->post('password', false);
$remember = $this->input->post('remember');
$data = $this->Authentication_model->login($email or $staff_code, $password, $remember, true);
if (is_array($data) && isset($data['memberinactive'])) {
set_alert('danger', _l('admin_auth_inactive_account'));
redirect(admin_url('authentication'));
} elseif (is_array($data) && isset($data['two_factor_auth'])) {
$this->session->set_userdata('_two_factor_auth_established', true);
if ($data['user']->two_factor_auth_enabled == 1) {
$this->Authentication_model->set_two_factor_auth_code($data['user']->staffid);
$sent = send_mail_template('staff_two_factor_auth_key', $data['user']);
if (!$sent) {
set_alert('danger', _l('two_factor_auth_failed_to_send_code'));
redirect(admin_url('authentication'));
} else {
$this->session->set_userdata('_two_factor_auth_staff_email', $email);
set_alert('success', _l('two_factor_auth_code_sent_successfully', $email));
redirect(admin_url('authentication/two_factor'));
}
} else {
set_alert('success', _l('enter_two_factor_auth_code_from_mobile'));
redirect(admin_url('authentication/two_factor/app'));
}
} elseif ($data == false) {
set_alert('danger', _l('admin_auth_invalid_email_or_password'));
redirect(admin_url('authentication'));
}
$this->load->model('announcements_model');
$this->announcements_model->set_announcements_as_read_except_last_one(get_staff_user_id(), true);
// is logged in
maybe_redirect_to_previous_url();
hooks()->do_action('after_staff_login');
redirect(admin_url());
}
}
$data['title'] = _l('admin_auth_login_heading');
$this->load->view('authentication/login_admin', $data);
}
Logging in with an email is successful, but logging in with a staff code is not working. Please help me!
The full attached PHP code.
My code is:
public function admin()
{
if (is_staff_logged_in()) {
redirect(admin_url());
}
$this->form_validation->set_rules('password', _l('admin_auth_login_password'), 'required');
$this->form_validation->set_rules('email' OR 'staff_code', _l('admin_auth_login_email_or_staff_code'), 'trim|required');
if (show_recaptcha()) {
$this->form_validation->set_rules('g-recaptcha-response', 'Captcha', 'callback_recaptcha');
}
if ($this->input->post()) {
if ($this->form_validation->run() !== false) {
$email = $this->input->post('email');
$staff_code = $this->input->post('staff_code');
$password = $this->input->post('password', false);
$remember = $this->input->post('remember');
$data = $this->Authentication_model->login($email or $staff_code, $password, $remember, true);
if (is_array($data) && isset($data['memberinactive'])) {
set_alert('danger', _l('admin_auth_inactive_account'));
redirect(admin_url('authentication'));
} elseif (is_array($data) && isset($data['two_factor_auth'])) {
$this->session->set_userdata('_two_factor_auth_established', true);
if ($data['user']->two_factor_auth_enabled == 1) {
$this->Authentication_model->set_two_factor_auth_code($data['user']->staffid);
$sent = send_mail_template('staff_two_factor_auth_key', $data['user']);
if (!$sent) {
set_alert('danger', _l('two_factor_auth_failed_to_send_code'));
redirect(admin_url('authentication'));
} else {
$this->session->set_userdata('_two_factor_auth_staff_email', $email);
set_alert('success', _l('two_factor_auth_code_sent_successfully', $email));
redirect(admin_url('authentication/two_factor'));
}
} else {
set_alert('success', _l('enter_two_factor_auth_code_from_mobile'));
redirect(admin_url('authentication/two_factor/app'));
}
} elseif ($data == false) {
set_alert('danger', _l('admin_auth_invalid_email_or_password'));
redirect(admin_url('authentication'));
}
$this->load->model('announcements_model');
$this->announcements_model->set_announcements_as_read_except_last_one(get_staff_user_id(), true);
// is logged in
maybe_redirect_to_previous_url();
hooks()->do_action('after_staff_login');
redirect(admin_url());
}
}
$data['title'] = _l('admin_auth_login_heading');
$this->load->view('authentication/login_admin', $data);
}
Logging in with an email is successful, but logging in with a staff code is not working. Please help me!
The full attached PHP code.