Allowed single user to be logged in at multiple sessions
This commit is contained in:
parent
66745e26d5
commit
d4dce8e460
@ -110,8 +110,7 @@ class Home
|
|||||||
$password = $args['password'];
|
$password = $args['password'];
|
||||||
|
|
||||||
$user = $this->access->showAll($table, [
|
$user = $this->access->showAll($table, [
|
||||||
['username', '=', $username],
|
['username', '=', $username]
|
||||||
['status', '!=', 1]
|
|
||||||
]);
|
]);
|
||||||
if ($user == false) {
|
if ($user == false) {
|
||||||
$info = "Invalid username/password";
|
$info = "Invalid username/password";
|
||||||
@ -119,9 +118,14 @@ class Home
|
|||||||
$hash = Hash::compare($password, $user['salt'], $user['password']);
|
$hash = Hash::compare($password, $user['salt'], $user['password']);
|
||||||
|
|
||||||
if ($hash == true) {
|
if ($hash == true) {
|
||||||
|
if ($user['max_user'] <= 0) {
|
||||||
|
$info = "Max user reached!";
|
||||||
|
} else {
|
||||||
if ($this->access->update($table, ['status' => 1], $user['id']) != true) {
|
if ($this->access->update($table, ['status' => 1], $user['id']) != true) {
|
||||||
$info = "There's an error. Please try again.";
|
$info = "There's an error. Please try again.";
|
||||||
} else {
|
} else {
|
||||||
|
$max_user = $user['max_user'] - 1;
|
||||||
|
if ($this->access->update($table, ['max_user' => $max_user], $user['id']) == true) {
|
||||||
Session::put('userid', $user['id']);
|
Session::put('userid', $user['id']);
|
||||||
Session::put('username', $user['username']);
|
Session::put('username', $user['username']);
|
||||||
Session::put('full_name', $user['full_name']);
|
Session::put('full_name', $user['full_name']);
|
||||||
@ -131,6 +135,8 @@ class Home
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Session::flash('info', $info);
|
Session::flash('info', $info);
|
||||||
Redirect::to('/');
|
Redirect::to('/');
|
||||||
}
|
}
|
||||||
@ -138,9 +144,21 @@ class Home
|
|||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
$table = 'user';
|
$table = 'user';
|
||||||
$user = Session::get('userid');
|
$userid = Session::get('userid');
|
||||||
|
|
||||||
if ($this->access->update($table, ['status' => 0], $user) != true) {
|
$user = $this->access->showAll($table, [
|
||||||
|
['id', '=', $userid]
|
||||||
|
]);
|
||||||
|
$max_user = $user['max_user'] + 1;
|
||||||
|
|
||||||
|
if ($this->access->update(
|
||||||
|
$table,
|
||||||
|
[
|
||||||
|
'status' => 0,
|
||||||
|
'max_user' => $max_user
|
||||||
|
],
|
||||||
|
$userid
|
||||||
|
) != true) {
|
||||||
throw new \Exception("Bad request", 400);
|
throw new \Exception("Bad request", 400);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user