35 lines
817 B
PHP
35 lines
817 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers;
|
||
|
|
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
|
||
|
|
class SessionsController extends Controller
|
||
|
|
{
|
||
|
|
|
||
|
|
function __construct() {
|
||
|
|
$this->middleware('guest', ['except' => 'destroy']); // Filter: Only guests = not logged in users are allowed. Everybody else is redirected away.
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public function create() {
|
||
|
|
return view('sessions.create');
|
||
|
|
}
|
||
|
|
public function store() {
|
||
|
|
// Attempt to authenticate the user
|
||
|
|
|
||
|
|
if (!auth()->attempt(request(['name','password']))) {
|
||
|
|
return back()->withErrors(['message'=>'Bitte Logindaten prüfen und nochmal versuchen.']);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
// And redirect to home page
|
||
|
|
return redirect()->home();
|
||
|
|
|
||
|
|
}
|
||
|
|
public function destroy() {
|
||
|
|
auth()->logout();
|
||
|
|
return redirect()->home();
|
||
|
|
}
|
||
|
|
}
|