diff --git a/App/Controllers/Home.php b/App/Controllers/Home.php index 9440b77..c6e76ce 100644 --- a/App/Controllers/Home.php +++ b/App/Controllers/Home.php @@ -24,7 +24,7 @@ class Home $posts->index(); } - public function login() + public function login($args = []) { if (Session::exists('userid')) { Session::flash('info', 'Anda telah masuk.'); @@ -35,6 +35,45 @@ class Home 'token' => Token::generate() ]); } + + // Login + if ($args) { + $username = $args['username']; + $password = $args['password']; + + $user = $this->model->showAll([ + ['username', '=', $username] + ]); + + if ($user == false) { + $info = "Username/password salah."; + } else { + $hash = Hash::compare($password, $user['salt'], $user['password']); + + if ($hash == true) { + if ($user['max_user'] <= 0) { + $info = "Telah mencapai maksimal user yang diizinkan. Silahkan logout pada perangkat lain terlebih dahulu."; + } else { + if ($this->model->update(['status' => 1], $user['id']) != true) { + $info = "Terjadi kesalahan. Silahkan coba lagi dalam beberapa saat."; + } else { + $max_user = $user['max_user'] - 1; + if ($this->model->update(['max_user' => $max_user], $user['id']) == true) { + Session::put('userid', $user['id']); + Session::put('username', $user['username']); + Session::put('full_name', $user['full_name']); + Session::put('privilage', $user['privilage']); + + $info = "Berhasil masuk"; + } + } + } + } + } + Session::flash('info', $info); + Redirect::to('/'); + die(); + } } public function logout() { @@ -106,45 +145,6 @@ class Home die(); } - public function put($args = []) - { - $username = $args['username']; - $password = $args['password']; - - $user = $this->model->showAll([ - ['username', '=', $username] - ]); - - if ($user == false) { - $info = "Username/password salah."; - } else { - $hash = Hash::compare($password, $user['salt'], $user['password']); - - if ($hash == true) { - if ($user['max_user'] <= 0) { - $info = "Telah mencapai maksimal user yang diizinkan. Silahkan logout pada perangkat lain terlebih dahulu."; - } else { - if ($this->model->update(['status' => 1], $user['id']) != true) { - $info = "Terjadi kesalahan. Silahkan coba lagi dalam beberapa saat."; - } else { - $max_user = $user['max_user'] - 1; - if ($this->model->update(['max_user' => $max_user], $user['id']) == true) { - Session::put('userid', $user['id']); - Session::put('username', $user['username']); - Session::put('full_name', $user['full_name']); - Session::put('privilage', $user['privilage']); - - $info = "Berhasil masuk"; - } - } - } - } - } - Session::flash('info', $info); - Redirect::to('/'); - die(); - } - public function delete() { if (Session::exists('userid') == false) { diff --git a/Core/Router.php b/Core/Router.php index f1802ae..633af89 100644 --- a/Core/Router.php +++ b/Core/Router.php @@ -68,7 +68,9 @@ class Router // Check the token if (Token::check($var['_token'])) { // Get the method - $action = $var['_method']; + if (isset($var['_method'])) { + $action = $var['_method']; + } } else { // Token invalid throw new \Exception("Token invalid", 498);