Skip to content
This repository has been archived by the owner on Sep 28, 2023. It is now read-only.

Commit

Permalink
Add login with rememberToken
Browse files Browse the repository at this point in the history
  • Loading branch information
kkamara committed Aug 20, 2023
1 parent e9d6b29 commit 350fe60
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
28 changes: 27 additions & 1 deletion app/Http/Controllers/Admin/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
Expand All @@ -20,6 +22,30 @@ public function index(Request $request)
*/
public function create(Request $request)
{
return route('adminHome');
$validator = Validator::make($request->all(), [
'username' => 'required|max:30|exists:users,email',
'password' => 'required|max:30',
]);
if ($validator->fails()) {
return redirect()->back()
->withInput()
->withErrors($validator);
}
$rememberToken = false;
if ($request->has('rememberToken')) {
$rememberToken = true;
}
$username = htmlspecialchars($request->get('username'));
$password = $request->get('password');
$auth = Auth::attempt([
'email' => $username,
'password' => $password,
], $rememberToken);
if (!$auth) {
return redirect()->back()
->withInput()
->withErrors(['username' => 'Invalid email & password combination']);
}
return redirect()->route('adminHome');
}
}
4 changes: 3 additions & 1 deletion resources/views/admin/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class="position-relative overflow-hidden radial-gradient min-vh-100 d-flex align
class="form-control @if(isset($errors) && $errors->count() && strlen($errors->first('username'))) is-invalid @endif"
id="inputUsername"
aria-describedby="emailHelp"
value="{{ old('username') }}"
/>
@if(isset($errors) && $errors->count() && strlen($errors->first('username')))
<div id="validationUsernameFeedback">
Expand All @@ -57,6 +58,7 @@ class="form-label"
name="password"
class="form-control @if(isset($errors) && $errors->count() && strlen($errors->first('password'))) is-invalid @endif"
id="inputPassword"
value="{{ old('password') }}"
/>
@if(isset($errors) && $errors->count() && strlen($errors->first('password')))
<div id="validationPasswordFeedback">
Expand All @@ -69,7 +71,7 @@ class="form-control @if(isset($errors) && $errors->count() && strlen($errors->fi
<input
class="form-check-input primary"
type="checkbox"
value=""
value="true"
id="rememberToken"
name="rememberToken"
/>
Expand Down

0 comments on commit 350fe60

Please sign in to comment.