tippspiel/pfosten/app/Http/Controllers/SessionsController.php

35 lines
817 B
PHP
Raw Normal View History

2017-06-20 08:43:36 +02:00
<?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();
}
}