Changed login method from put to post
This commit is contained in:
parent
94d4a76ec6
commit
04ac2155db
@ -24,7 +24,7 @@ class Home
|
|||||||
$posts->index();
|
$posts->index();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function login()
|
public function login($args = [])
|
||||||
{
|
{
|
||||||
if (Session::exists('userid')) {
|
if (Session::exists('userid')) {
|
||||||
Session::flash('info', 'Anda telah masuk.');
|
Session::flash('info', 'Anda telah masuk.');
|
||||||
@ -35,6 +35,45 @@ class Home
|
|||||||
'token' => Token::generate()
|
'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() {
|
public function logout() {
|
||||||
@ -106,45 +145,6 @@ class Home
|
|||||||
die();
|
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()
|
public function delete()
|
||||||
{
|
{
|
||||||
if (Session::exists('userid') == false) {
|
if (Session::exists('userid') == false) {
|
||||||
|
@ -68,7 +68,9 @@ class Router
|
|||||||
// Check the token
|
// Check the token
|
||||||
if (Token::check($var['_token'])) {
|
if (Token::check($var['_token'])) {
|
||||||
// Get the method
|
// Get the method
|
||||||
|
if (isset($var['_method'])) {
|
||||||
$action = $var['_method'];
|
$action = $var['_method'];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Token invalid
|
// Token invalid
|
||||||
throw new \Exception("Token invalid", 498);
|
throw new \Exception("Token invalid", 498);
|
||||||
|
Loading…
Reference in New Issue
Block a user