Skip to content

Commit

Permalink
Merge pull request #2 from irfaardy/scrutinizer-patch-1
Browse files Browse the repository at this point in the history
Scrutinizer Auto-Fixes
  • Loading branch information
irfaardy authored Jul 24, 2020
2 parents 2de3f72 + b7c8395 commit fee75c1
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions libraries/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ function __construct() {
$this->CI = & get_instance();
}
/**
* Cek username dan password, jika password yang diinputkan sama dengan di database sama maka login sukses.
*
* @param string $username
* @param string $password
* @return boolean
*/
* Cek username dan password, jika password yang diinputkan sama dengan di database sama maka login sukses.
*
* @param string $username
* @param string $password
* @return boolean
*/
public function verify($username, $password) {
$get = $this->CI->user->getBy(['username' => $username]);
if (empty($get)) {
Expand All @@ -27,9 +27,9 @@ public function verify($username, $password) {

if (password_verify($password, $get->password)) {
$user_datas = array(
'user_id' => $get->id,
'logged_in' => TRUE,
'login_token' => sha1($get->id.time().mt_rand(1000, 9999))
'user_id' => $get->id,
'logged_in' => TRUE,
'login_token' => sha1($get->id.time().mt_rand(1000, 9999))
);
$this->CI->session->sess_regenerate();
$this->CI->session->set_userdata($user_datas);
Expand All @@ -40,10 +40,10 @@ public function verify($username, $password) {
}
}
/**
* Cek sudah login apa belum.
*
* @return boolean
*/
* Cek sudah login apa belum.
*
* @return boolean
*/
public function check() {
if ($this->CI->session->logged_in) {
return true;
Expand All @@ -53,10 +53,10 @@ public function check() {
}

/**
* Cek hak akses.
*
* @return mixed
*/
* Cek hak akses.
*
* @return mixed
*/
public function hakAkses($hakAksesId) {
if ($this->user()->level != $hakAksesId) {
$this->CI->session->set_flashdata('warning', 'Anda tidak dapat mengakses halaman ini.');
Expand All @@ -65,10 +65,10 @@ public function hakAkses($hakAksesId) {
}

/**
* Ambil data user sesuai dengan id yang login.
*
* @return mixed
*/
* Ambil data user sesuai dengan id yang login.
*
* @return mixed
*/
public function user() {
if ($this->check()) {
$get = $this->CI->user->getBy(['id' => $this->CI->session->user_id]);
Expand All @@ -79,10 +79,10 @@ public function user() {
}

/**
* Keluar dari sesi.
*
* @return void
*/
* Keluar dari sesi.
*
* @return void
*/
public function logout() {
if (empty($this->CI->input->get('token'))) {
return redirect($_SERVER['HTTP_REFERER']);
Expand All @@ -101,9 +101,9 @@ private function destroy() {
return redirect(base_url('login'));
}
/**
* Mencegah guest untuk mengakses halaman
* @return void
*/
* Mencegah guest untuk mengakses halaman
* @return void
*/
public function protect($hakAksesId = null) {
if (!$this->check()) {
$this->destroy();
Expand Down

0 comments on commit fee75c1

Please sign in to comment.