From 1499b2cd405bad772489e0942d262289782c4454 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 7 Feb 2015 22:50:47 +0100 Subject: [PATCH] Login and some routes fixed. --- app/Http/Controllers/Auth/AuthController.php | 54 +++++----- app/Http/routes.php | 12 ++- app/Services/Registrar.php | 65 +++++------ config/auth.php | 1 + resources/views/auth/login.blade.php | 108 +++++++++---------- resources/views/auth/register.blade.php | 39 +++---- resources/views/layouts/guest.blade.php | 10 +- 7 files changed, 142 insertions(+), 147 deletions(-) diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php index e5c6f11823..e175b6a819 100644 --- a/app/Http/Controllers/Auth/AuthController.php +++ b/app/Http/Controllers/Auth/AuthController.php @@ -5,34 +5,38 @@ use Illuminate\Contracts\Auth\Guard; use Illuminate\Contracts\Auth\Registrar; use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; -class AuthController extends Controller { +class AuthController extends Controller +{ - /* - |-------------------------------------------------------------------------- - | Registration & Login Controller - |-------------------------------------------------------------------------- - | - | This controller handles the registration of new users, as well as the - | authentication of existing users. By default, this controller uses - | a simple trait to add these behaviors. Why don't you explore it? - | - */ + /* + |-------------------------------------------------------------------------- + | Registration & Login Controller + |-------------------------------------------------------------------------- + | + | This controller handles the registration of new users, as well as the + | authentication of existing users. By default, this controller uses + | a simple trait to add these behaviors. Why don't you explore it? + | + */ - use AuthenticatesAndRegistersUsers; + use AuthenticatesAndRegistersUsers; - /** - * Create a new authentication controller instance. - * - * @param \Illuminate\Contracts\Auth\Guard $auth - * @param \Illuminate\Contracts\Auth\Registrar $registrar - * @return void - */ - public function __construct(Guard $auth, Registrar $registrar) - { - $this->auth = $auth; - $this->registrar = $registrar; + public $redirectTo = '/'; - $this->middleware('guest', ['except' => 'getLogout']); - } + /** + * Create a new authentication controller instance. + * + * @param \Illuminate\Contracts\Auth\Guard $auth + * @param \Illuminate\Contracts\Auth\Registrar $registrar + * + * @return void + */ + public function __construct(Guard $auth, Registrar $registrar) + { + $this->auth = $auth; + $this->registrar = $registrar; + + $this->middleware('guest', ['except' => 'getLogout']); + } } diff --git a/app/Http/routes.php b/app/Http/routes.php index fd403496e5..e6f4c05abb 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -136,13 +136,19 @@ Route::group( //Route::any('/transactions/unrelate/{tj}', ['uses' => 'TransactionController@unrelate', 'as' => 'transactions.unrelate']); /** - * User Controller - * TODO move to AuthController + * Auth\Auth Controller */ - Route::get('/logout', ['uses' => 'UserController@logout', 'as' => 'logout']); + Route::get('/logout', ['uses' => 'Auth\AuthController@getLogout', 'as' => 'logout']); + } ); + +/** + * Auth\AuthController + */ +Route::get('/register', ['uses' => 'Auth\AuthController@getRegister', 'as' => 'register']); + Route::controllers( [ 'auth' => 'Auth\AuthController', diff --git a/app/Services/Registrar.php b/app/Services/Registrar.php index 434b46e4db..771bf26134 100644 --- a/app/Services/Registrar.php +++ b/app/Services/Registrar.php @@ -1,39 +1,44 @@ 'required|max:255', - 'email' => 'required|email|max:255|unique:users', - 'password' => 'required|confirmed|min:6', - ]); - } + /** + * Create a new user instance after a valid registration. + * + * @param array $data + * + * @return User + */ + public function create(array $data) + { + return User::create( + [ + 'email' => $data['email'], + 'password' => bcrypt($data['password']), + ] + ); + } - /** - * Create a new user instance after a valid registration. - * - * @param array $data - * @return User - */ - public function create(array $data) - { - return User::create([ - 'name' => $data['name'], - 'email' => $data['email'], - 'password' => bcrypt($data['password']), - ]); - } + /** + * Get a validator for an incoming registration request. + * + * @param array $data + * + * @return \Illuminate\Contracts\Validation\Validator + */ + public function validator(array $data) + { + return Validator::make( + $data, [ + 'email' => 'required|email|max:255|unique:users', + 'password' => 'required|confirmed|min:6', + ] + ); + } } diff --git a/config/auth.php b/config/auth.php index e4eb512d63..feff197837 100644 --- a/config/auth.php +++ b/config/auth.php @@ -63,5 +63,6 @@ return [ 'table' => 'password_resets', 'expire' => 60, ], + 'allow_register' => true ]; diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 344cdbd79f..4587758c7e 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -1,63 +1,51 @@ -@extends('app') - +@extends('layouts.guest') @section('content') -
-
-
-
-
Login
-
- @if (count($errors) > 0) -
- Whoops! There were some problems with your input.

-
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
-
- @endif -
- - -
- -
- -
-
- -
- -
- -
-
- -
-
-
- -
-
-
- -
-
- - - Forgot Your Password? -
-
-
-
-
-
-
+@if($errors->has('email')) +
+
+ +
-@endsection +@endif + + +
+
+ +
+
+@stop diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index 452c1a7ff3..aa0e671f97 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -1,12 +1,14 @@ -@extends('app') +@extends('layouts.guest') @section('content') -
-
-
-
Register
+
+