Skip to content

Commit

Permalink
Implements login action
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammadreza-73 committed Apr 29, 2023
1 parent bff8dd5 commit 2ebeb93
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
14 changes: 10 additions & 4 deletions app/Core/Authenticatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ public function attemp(string $email, string $password)
$user = $this->db()->query("SELECT * FROM `users` WHERE `email` = :email", [
'email' => $email,
])->find();

if ($user) {
if (password_verify($password, $user->password)) {
$this->login([
'email' => $email,
// $this->login($user);
Session::put('user', [
'email' => $user->email,
]);

// Prevent Session Hijacking
session_regenerate_id(true);

return true;
}
Expand All @@ -27,7 +31,9 @@ public function login(array|object $user)
{
$user = is_object($user) ? $user : (object) $user;

Session::flash('email', $user->email);
Session::put('user', [
'email' => $user->email,
]);

// Prevent Session Hijacking
session_regenerate_id(true);
Expand Down
7 changes: 3 additions & 4 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ public function verify()
}

if ($this->attemp($inputs['email'], $inputs['password'])) {
return redirect('/admin'); // Bug: to many redirects

} else {
return redirect('/login', 'error', 'Invalid email or password.');
return redirect('/admin');
}

return redirect('/login', 'error', 'Invalid email or password.');
}

public function signup()
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public function index()

public function dashboard()
{
echo 'admin dashboard';
return view('dashboard');
}
}
12 changes: 12 additions & 0 deletions resources/Views/dashboard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard</title>
</head>
<body>
<h1>Welcome to Dashboard</h1>
</body>
</html>

0 comments on commit 2ebeb93

Please sign in to comment.