...
This commit is contained in:
parent
1db373a03d
commit
9bcbd3e194
118 changed files with 1116 additions and 155 deletions
|
|
@ -1,92 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Core\Auth;
|
||||
use App\Models\User;
|
||||
|
||||
class AuthController
|
||||
{
|
||||
public function showLoginForm(): void
|
||||
{
|
||||
view('auth.login');
|
||||
}
|
||||
|
||||
public function login(): void
|
||||
{
|
||||
validate([
|
||||
'email' => 'required|email',
|
||||
'password' => 'required',
|
||||
]);
|
||||
|
||||
$email = (string) input('email');
|
||||
$password = (string) input('password');
|
||||
|
||||
if (!Auth::attempt($email, $password)) {
|
||||
$_SESSION['_errors']['email'][] = 'Anmeldedaten sind ungültig.';
|
||||
$_SESSION['_old'] = $_POST;
|
||||
redirect('/login');
|
||||
}
|
||||
|
||||
redirect('/');
|
||||
}
|
||||
|
||||
public function logout(): void
|
||||
{
|
||||
Auth::logout();
|
||||
redirect('/');
|
||||
}
|
||||
|
||||
public function showRegisterForm(): void
|
||||
{
|
||||
view('auth.register');
|
||||
}
|
||||
|
||||
public function register(): void
|
||||
{
|
||||
validate([
|
||||
'name' => 'required|min:3',
|
||||
'email' => 'required|email',
|
||||
'mobile' => 'required',
|
||||
'password' => 'required|min:8',
|
||||
]);
|
||||
|
||||
$name = (string) input('name');
|
||||
|
||||
// Einfacher Spam-Schutz: mehr als drei Großbuchstaben im Namen ablehnen.
|
||||
if (preg_match_all('/[A-Z]/', $name) > 3) {
|
||||
redirect('/');
|
||||
}
|
||||
|
||||
$password = (string) input('password');
|
||||
$confirmation = (string) input('password_confirmation');
|
||||
|
||||
if ($password !== $confirmation) {
|
||||
$_SESSION['_errors']['password'][] = 'Die Passwörter stimmen nicht überein.';
|
||||
$_SESSION['_old'] = $_POST;
|
||||
redirect('/register');
|
||||
}
|
||||
|
||||
if (User::byEmail((string) input('email')) !== null) {
|
||||
$_SESSION['_errors']['email'][] = 'Diese E-Mail-Adresse ist bereits vergeben.';
|
||||
$_SESSION['_old'] = $_POST;
|
||||
redirect('/register');
|
||||
}
|
||||
|
||||
$user = User::create([
|
||||
'name' => $name,
|
||||
'email' => (string) input('email'),
|
||||
'mobile' => (string) input('mobile'),
|
||||
'role' => 'GUEST',
|
||||
'password' => password_hash($password, PASSWORD_BCRYPT),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
redirect('/');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue