You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

171 lines
6.5 KiB

<?php
namespace App\Controllers;
use CodeIgniter\Controller;
use App\Models\Mauth;
class Auth extends Controller
{
public function index()
{
helper(['form']);
echo view('pages/loginv');
}
public function login()
{
$session = session();
$model = new Mauth();
$username = $this->request->getVar('username');
//$password = $this->request->getVar('password');
$data = $model->cekuser($username)->getRowArray();
// var_dump($data);
//exit();
if ($data) {
$ses_data = [
'nip' => $data['NIP9'],
'nipp' => $data['NIP18'],
'nama' => $data['NAMA'],
'kppadm' => $data['KPPADM'],
'jabatan' => $data['NAMA_JABATAN'],
'kantor' => $data['NAMA_KANTOR'],
'seksi' => $data['NAMA_UNIT_ES3'],
'tpkantor' => $data['TP_KANTOR'],
'kwladm' => $data['KD_KANWIL'],
'isLogin' => true
];
$session->set($ses_data);
if (session('tpkantor') == 'KPDJP') {
return redirect()->to(base_url('Home'));
} else if (session('tpkantor') == 'Kanwil') {
return redirect()->to(base_url('Kanwil'));
} else {
return redirect()->to(base_url('seksiar'));
}
} else {
//print_r('user tidak ada');
//exit;
$session->setFlashdata('msg', 'User Tidak ada');
return redirect()->to('auth');
}
}
function ldap_auth()
{
$username = $this->request->getVar('username');
$password = $this->request->getVar('password');
$session = session();
if ($password == "") return redirect()->to(base_url('auth'));
else {
$model = new Mauth();
$ldaprdn = 'INTRANET' . "\\" . $username;
$adServer = "ldap://10.254.28.141";
$ldap = ldap_connect($adServer);
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
$bind = @ldap_bind($ldap, $ldaprdn, $password);
if ($bind) {
$filter = "(&(objectCategory=person)(objectClass=user)(cn={$username}*) )";
$ldap_base_dn = "OU=Pegawai DJP,DC=intranet,DC=pajak,DC=go,DC=id";
$result = ldap_search($ldap, $ldap_base_dn, $filter);
$info = ldap_get_entries($ldap, $result);
for ($i = 0; $i < $info["count"]; $i++) {
if ($info['count'] > 1) break;
$_SESSION['usr'] = $username;
$_SESSION['nama'] = $info[$i]["displayname"][0];
$_SESSION['nip'] = $info[$i]["employeenumber"][0];
}
@ldap_close($ldap);
$data = $model->cekuser($username)->getRowArray();
$ses_data = [
'nip' => $data['NIP9'],
'nipp' => $data['NIP18'],
'nama' => $data['NAMA'],
'kppadm' => $data['KPPADM'],
'jabatan' => $data['NAMA_JABATAN'],
'kantor' => $data['NAMA_KANTOR'],
'seksi' => $data['NAMA_UNIT_ES3'],
'tpkantor' => $data['TP_KANTOR'],
'kwladm' => $data['KD_KANWIL'],
'isLogin' => true
];
$session->set($ses_data);
if (session('tpkantor') == 'KPDJP') {
return redirect()->to(base_url('Home'));
} else if (session('tpkantor') == 'Kanwil') {
return redirect()->to(base_url('Kanwil'));
} else {
return redirect()->to(base_url('seksiar'));
}
} else {
$ldaprdn = 'INTRANET' . "\\" . $username;
$adServer = "ldap://10.254.28.142";
$ldap = ldap_connect($adServer);
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
$bind = @ldap_bind($ldap, $ldaprdn, $password);
if ($bind) {
$filter = "(&(objectCategory=person)(objectClass=user)(cn={$username}*) )";
$ldap_base_dn = "OU=Pegawai DJP,DC=intranet,DC=pajak,DC=go,DC=id";
$result = ldap_search($ldap, $ldap_base_dn, $filter);
$info = ldap_get_entries($ldap, $result);
for ($i = 0; $i < $info["count"]; $i++) {
if ($info['count'] > 1) break;
$_SESSION['usr'] = $username;
$_SESSION['nama'] = $info[$i]["displayname"][0];
$_SESSION['nip'] = $info[$i]["employeenumber"][0];
}
@ldap_close($ldap);
$data = $model->cekuser($username)->getRowArray();
$ses_data = [
'nip' => $data['NIP9'],
'nipp' => $data['NIP18'],
'nama' => $data['NAMA'],
'kppadm' => $data['KPPADM'],
'jabatan' => $data['NAMA_JABATAN'],
'kantor' => $data['NAMA_KANTOR'],
'seksi' => $data['NAMA_UNIT_ES3'],
'tpkantor' => $data['TP_KANTOR'],
'kwladm' => $data['KD_KANWIL'],
'isLogin' => true
];
$session->set($ses_data);
if (session('tpkantor') == 'KPDJP') {
return redirect()->to(base_url('Home'));
} else if (session('tpkantor') == 'Kanwil') {
return redirect()->to(base_url('Kanwil'));
} else {
return redirect()->to(base_url('seksiar'));
}
// return true;
} else {
return redirect()->to(base_url('auth'));
}
}
}
}
public function logout()
{
$session = session();
$session->destroy();
return redirect()->to(base_url('auth'));
}
public function underconst()
{
echo view('errors/html/unconstruct');
}
}