Working on default app structure. Login views.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php namespace App\Http\Controllers;
|
||||
|
||||
use App\User;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
|
||||
use App\Http\Requests\LoginRequest;
|
||||
@@ -45,11 +46,15 @@ class AuthController extends Controller {
|
||||
*/
|
||||
public function postRegister(RegisterRequest $request)
|
||||
{
|
||||
// Registration form is valid, create user...
|
||||
$user = User::forceCreate([
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'password' => bcrypt($request->password),
|
||||
]);
|
||||
|
||||
$this->auth->login($user);
|
||||
|
||||
return redirect('/');
|
||||
return redirect('/dashboard');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,12 +77,14 @@ class AuthController extends Controller {
|
||||
{
|
||||
if ($this->auth->attempt($request->only('email', 'password')))
|
||||
{
|
||||
return redirect('/');
|
||||
return redirect('/dashboard');
|
||||
}
|
||||
|
||||
return redirect('/auth/login')->withErrors([
|
||||
'email' => 'These credentials do not match our records.',
|
||||
]);
|
||||
return redirect('/auth/login')
|
||||
->withInput($request->only('email'))
|
||||
->withErrors([
|
||||
'email' => 'These credentials do not match our records.',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
25
app/Http/Controllers/DashboardController.php
Normal file
25
app/Http/Controllers/DashboardController.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php namespace App\Http\Controllers;
|
||||
|
||||
class DashboardController extends Controller {
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard to the user.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('dashboard');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,20 @@
|
||||
<?php namespace App\Http\Controllers;
|
||||
|
||||
use App\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Contracts\Auth\PasswordBroker;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class PasswordController extends Controller {
|
||||
|
||||
/**
|
||||
* The Guard implementation.
|
||||
*
|
||||
* @var Guard
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* The password broker implementation.
|
||||
*
|
||||
@@ -19,8 +28,9 @@ class PasswordController extends Controller {
|
||||
* @param PasswordBroker $passwords
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(PasswordBroker $passwords)
|
||||
public function __construct(Guard $auth, PasswordBroker $passwords)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->passwords = $passwords;
|
||||
|
||||
$this->middleware('guest');
|
||||
@@ -33,7 +43,7 @@ class PasswordController extends Controller {
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return view('password.email');
|
||||
return view('auth.password');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,6 +54,8 @@ class PasswordController extends Controller {
|
||||
*/
|
||||
public function postEmail(Request $request)
|
||||
{
|
||||
$this->validate($request, ['email' => 'required']);
|
||||
|
||||
switch ($response = $this->passwords->sendResetLink($request->only('email')))
|
||||
{
|
||||
case PasswordBroker::INVALID_USER:
|
||||
@@ -67,7 +79,7 @@ class PasswordController extends Controller {
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
|
||||
return view('password.reset')->with('token', $token);
|
||||
return view('auth.reset')->with('token', $token);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,11 +106,26 @@ class PasswordController extends Controller {
|
||||
case PasswordBroker::INVALID_PASSWORD:
|
||||
case PasswordBroker::INVALID_TOKEN:
|
||||
case PasswordBroker::INVALID_USER:
|
||||
return redirect()->back()->withErrors(['email' => trans($response)]);
|
||||
return redirect()->back()
|
||||
->withInput($request->only('email'))
|
||||
->withErrors(['email' => trans($response)]);
|
||||
|
||||
case PasswordBroker::PASSWORD_RESET:
|
||||
return redirect()->to('/');
|
||||
return $this->loginAndRedirect($request->email);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Login the user with the given e-mail address and redirect home.
|
||||
*
|
||||
* @param string $email
|
||||
* @return Response
|
||||
*/
|
||||
protected function loginAndRedirect($email)
|
||||
{
|
||||
$this->auth->login(User::where('email', $email)->firstOrFail());
|
||||
|
||||
return redirect('/dashboard');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php namespace App\Http\Controllers;
|
||||
|
||||
class HomeController extends Controller {
|
||||
class WelcomeController extends Controller {
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -11,13 +11,13 @@ class HomeController extends Controller {
|
||||
| based routes. That's great! Here is an example controller method to
|
||||
| get you started. To route to this controller, just add the route:
|
||||
|
|
||||
| $router->get('/', 'HomeController@showWelcome');
|
||||
| $router->get('/', 'WelcomeController@index');
|
||||
|
|
||||
*/
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('hello');
|
||||
return view('welcome');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,8 @@ class RegisterRequest extends Request {
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'email' => 'required|email|unique:users',
|
||||
'name' => 'required|max:255',
|
||||
'email' => 'required|max:255|email|unique:users',
|
||||
'password' => 'required|confirmed|min:8',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
|
|
||||
*/
|
||||
|
||||
$router->get('/', 'HomeController@index');
|
||||
$router->get('/', 'WelcomeController@index');
|
||||
|
||||
$router->get('/dashboard', 'DashboardController@index');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user