Added login controller
This commit is contained in:
parent
d7645c5837
commit
10d4792842
47
app/Http/Controllers/Auth/LoginController.php
Normal file
47
app/Http/Controllers/Auth/LoginController.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
|
||||
public function authenticate(Request $request)
|
||||
{
|
||||
$credentials = $request->validate([
|
||||
'email' => ['required', 'email'],
|
||||
'password' => ['required'],
|
||||
]);
|
||||
|
||||
if (Auth::attempt($credentials)) {
|
||||
$request->session()->regenerate();
|
||||
return redirect()->route('admin.home');
|
||||
}
|
||||
|
||||
return back()->withErrors([
|
||||
'email' => 'The provided credentials do not match our records.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
if (Auth::check()) {
|
||||
Auth::logout();
|
||||
}
|
||||
|
||||
return redirect()->route('admin.auth.login');
|
||||
}
|
||||
|
||||
public function login(): View
|
||||
{
|
||||
return view('auth.login');
|
||||
}
|
||||
|
||||
}
|
16
resources/views/auth/login.blade.php
Normal file
16
resources/views/auth/login.blade.php
Normal file
@ -0,0 +1,16 @@
|
||||
@extends('layout.app')
|
||||
@section('title', 'Login')
|
||||
|
||||
@section('main')
|
||||
<form class="form" method="POST" action="">
|
||||
@csrf
|
||||
<label for="email">E-mail</label>
|
||||
<input id="email" type="text" name="email" value="{{ old('email') }}" placeholder="Podaj swój e-mail">
|
||||
@error('email')
|
||||
<span class="error">{{ $message }}</span>
|
||||
@enderror
|
||||
<label for="email">Hasło</label>
|
||||
<input id="email" type="password" name="password" placeholder="Podaj swoje hasło">
|
||||
<input type="submit" value="Zaloguj">
|
||||
</form>
|
||||
@endsection
|
20
resources/views/layout/app.blade.php
Normal file
20
resources/views/layout/app.blade.php
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title>KamilCraft API - @yield('title')</title>
|
||||
|
||||
<!-- Fonts -->
|
||||
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap" rel="stylesheet">
|
||||
|
||||
<!-- Styles -->
|
||||
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
|
||||
</head>
|
||||
<body class="antialiased">
|
||||
<main id="main">
|
||||
@yield('main')
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user