Added login controller

This commit is contained in:
Kamil Niemczycki 2022-02-14 22:46:48 +01:00
parent d7645c5837
commit 10d4792842
3 changed files with 83 additions and 0 deletions

View 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');
}
}

View 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

View 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>