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'];
|
||||
|
||||
$user = $this->access->showAll($table, [
|
||||
['username', '=', $username],
|
||||
['status', '!=', 1]
|
||||
['username', '=', $username]
|
||||
]);
|
||||
if ($user == false) {
|
||||
$info = "Invalid username/password";
|
||||
@ -119,9 +118,14 @@ class Home
|
||||
$hash = Hash::compare($password, $user['salt'], $user['password']);
|
||||
|
||||
if ($hash == true) {
|
||||
if ($user['max_user'] <= 0) {
|
||||
$info = "Max user reached!";
|
||||
} else {
|
||||
if ($this->access->update($table, ['status' => 1], $user['id']) != true) {
|
||||
$info = "There's an error. Please try again.";
|
||||
} 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('username', $user['username']);
|
||||
Session::put('full_name', $user['full_name']);
|
||||
@ -131,6 +135,8 @@ class Home
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Session::flash('info', $info);
|
||||
Redirect::to('/');
|
||||
}
|
||||
@ -138,9 +144,21 @@ class Home
|
||||
public function delete()
|
||||
{
|
||||
$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);
|
||||
}
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user