Page MenuHomeDevCentral

D449.id1089.diff
No OneTemporary

D449.id1089.diff

diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php
--- a/app/Http/Controllers/Auth/AuthController.php
+++ b/app/Http/Controllers/Auth/AuthController.php
@@ -10,6 +10,7 @@
use AuthGrove\Services\Registrar;
use AuthGrove\Models\User;
+use Config;
use Route;
class AuthController extends Controller implements RegistrarContract
@@ -51,28 +52,59 @@
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
+ ///
+ /// Routes
+ ///
+
+ /**
+ * Gets the URL prefix for the authentication routes.
+ *
+ * @return string
+ */
+ protected static function getRoutePrefix () {
+ return Config::get('auth.route');
+ }
+
+ /**
+ * Gets a specific authentication route
+ *
+ * @param $action The authentication action (e.g. login)
+ * @return string The route URL (e.g. /auth/loin)
+ */
+ public static function getRoute ($action) {
+ $prefix = static::getRoutePrefix();
+
+ if ((string)$action === '') {
+ return $prefix;
+ }
+
+ return $prefix . '/' . $action;
+ }
+
/**
* Registers auth routes.
*/
public static function registerRoutes () {
+ $auth = static::getRoutePrefix();
+
// Login
- Route::get('/auth', ['as' => 'auth.login', 'uses' => 'Auth\AuthController@showLoginForm']);
- Route::get('/auth/login', ['as' => 'auth.login', 'uses' => 'Auth\AuthController@showLoginForm']);
- Route::post('/auth/login', ['as' => 'auth.login', 'uses' => 'Auth\AuthController@login']);
+ Route::get($auth, ['as' => 'auth.login', 'uses' => 'Auth\AuthController@showLoginForm']);
+ Route::get($auth . '/login', ['as' => 'auth.login', 'uses' => 'Auth\AuthController@showLoginForm']);
+ Route::post($auth . '/login', ['as' => 'auth.login', 'uses' => 'Auth\AuthController@login']);
// Logout
- Route::get('/auth/logout', ['as' => 'auth.logout', 'uses' => 'Auth\AuthController@logout']);
+ Route::get($auth . '/logout', ['as' => 'auth.logout', 'uses' => 'Auth\AuthController@logout']);
// Registration
- Route::get('/auth/register', ['as' => 'auth.register', 'uses' => 'Auth\AuthController@showRegistrationForm']);
- Route::post('/auth/register', ['as' => 'auth.register', 'uses' => 'Auth\AuthController@register']);
+ Route::get($auth . '/register', ['as' => 'auth.register', 'uses' => 'Auth\AuthController@showRegistrationForm']);
+ Route::post($auth . '/register', ['as' => 'auth.register', 'uses' => 'Auth\AuthController@register']);
// Recover account
- Route::get('/auth/recover', ['as' => 'auth.password.reset', 'uses' => 'Auth\PasswordController@getRecover']);
- Route::post('/auth/recover', ['as' => 'auth.password.reset', 'uses' => 'Auth\PasswordController@postRecover']);
+ Route::get($auth . '/recover', ['as' => 'auth.password.reset', 'uses' => 'Auth\PasswordController@getRecover']);
+ Route::post($auth . '/recover', ['as' => 'auth.password.reset', 'uses' => 'Auth\PasswordController@postRecover']);
// Reset password (with a token received by mail)
- Route::get('/auth/reset/{token?}', ['as' => 'auth.password.reset', 'uses' => 'Auth\PasswordController@getReset']);
- Route::post('/auth/reset', ['as' => 'auth.password.reset', 'uses' => 'Auth\PasswordController@reset']);
+ Route::get($auth . '/reset/{token?}', ['as' => 'auth.password.reset', 'uses' => 'Auth\PasswordController@getReset']);
+ Route::post($auth . '/reset', ['as' => 'auth.password.reset', 'uses' => 'Auth\PasswordController@reset']);
}
}
diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php
--- a/app/Providers/AppServiceProvider.php
+++ b/app/Providers/AppServiceProvider.php
@@ -2,6 +2,10 @@
use Illuminate\Support\ServiceProvider;
+use AuthGrove\Http\Controllers\Auth\AuthController;
+
+use Blade;
+
class AppServiceProvider extends ServiceProvider {
/**
@@ -9,9 +13,13 @@
*
* @return void
*/
- public function boot()
- {
- //
+ public function boot() {
+ // Blade templates can invoke AuthController::getRoute as authurl()
+ Blade::directive('authurl', function ($expression) {
+ preg_match("@\('(.*)'\)@", $expression, $matches); // ('foo') → foo
+ $action = $matches[1];
+ return url(AuthController::getRoute($action));
+ });
}
/**
diff --git a/config/auth.php b/config/auth.php
--- a/config/auth.php
+++ b/config/auth.php
@@ -104,4 +104,15 @@
],
],
+ /*
+ |--------------------------------------------------------------------------
+ | Routes
+ |--------------------------------------------------------------------------
+ |
+ | Routes handled by AuthController and PasswordController should start by:
+ |
+ */
+
+ 'route' => '/auth',
+
];
diff --git a/resources/views/app.blade.php b/resources/views/app.blade.php
--- a/resources/views/app.blade.php
+++ b/resources/views/app.blade.php
@@ -41,7 +41,7 @@
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{ Auth::user()->getName() }} <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
- <li><a href="{{ url('/auth/logout') }}">@lang('panel.logout')</a></li>
+ <li><a href="@authurl('logout')">@lang('panel.logout')</a></li>
</ul>
</li>
</ul>
diff --git a/resources/views/auth/fatal-error.blade.php b/resources/views/auth/fatal-error.blade.php
new file mode 100644
--- /dev/null
+++ b/resources/views/auth/fatal-error.blade.php
@@ -0,0 +1,12 @@
+@extends('auth.master')
+
+@section('card-content')
+ <h1 class="title">@lang('app.title')</h1>
+ <p>@lang('auth.fatal-error')</p>
+ <p class="errors">
+@foreach ($errors->all() as $error)
+ {{ $error }}<br />
+@endforeach
+ </p>
+ <a href="@authurl('login')" class="action-link">@lang('login.goto-login')</a>
+@endsection
diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php
--- a/resources/views/auth/login.blade.php
+++ b/resources/views/auth/login.blade.php
@@ -3,7 +3,7 @@
@section('card-content')
<h1 class="title">@lang('app.title')</h1>
<img id="profile-img" class="profile-img-card" src="/images/profile-img-blank.png" alt="@lang('login.blankAvatarAlt')" />
- <form class="form-signin" role="form" method="POST" action="{{ url('/auth/login') }}">
+ <form class="form-signin" role="form" method="POST" action="@authurl('login')">
<div id="identity">
<span id="reauth-username" class="reauth-username"></span>
<input type="text" name="username" id="inputUsername" class="form-control"
@@ -15,7 +15,7 @@
@foreach ($errors->all() as $error)
{{ $error }}<br />
@endforeach
- <a href="{{ url('/auth/recover') }}" class="action-link">@lang('login.passwordRecovery')</a>
+ <a href="@authurl('recover')" class="action-link">@lang('login.passwordRecovery')</a>
</p>
@endif
@@ -27,7 +27,7 @@
</form>
<!-- /form -->
@if (count($errors) == 0)
- <a href="{{ url('/auth/recover') }}" class="action-link">@lang('login.passwordRecovery')</a><br />
+ <a href="@authurl('recover')" class="action-link">@lang('login.passwordRecovery')</a><br />
@endif
- <a href="{{ url('/auth/register') }}" class="action-link">@lang('login.registerAccount')</a>
+ <a href="@authurl('register')" class="action-link">@lang('login.registerAccount')</a>
@endsection
diff --git a/resources/views/auth/recover.blade.php b/resources/views/auth/recover.blade.php
--- a/resources/views/auth/recover.blade.php
+++ b/resources/views/auth/recover.blade.php
@@ -7,7 +7,7 @@
<p class="center"><img src="{{ url('/images/white-check.svg') }}" alt="Check mark" width="100px" /></p>
<p class="nav"><a href="{{ url('/') }}">@lang('pagination.previous') Back to login screen</a></p>
@else
- <form class="form-signin form-recover" role="form" method="POST" action="{{ url('/auth/recover') }}">
+ <form class="form-signin form-recover" role="form" method="POST" action="@authurl('recover')">
<div id="identity">
<input type="email" name="email" id="inputEmail" class="form-control"
value="{{ old('email') }}" placeholder="@lang('login.email')" required autofocus />
diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php
--- a/resources/views/auth/register.blade.php
+++ b/resources/views/auth/register.blade.php
@@ -2,7 +2,7 @@
@section('card-content')
<h1 class="title">@lang('login.registerAccount')</h1>
- <form class="form-signin form-register" role="form" method="POST" action="{{ url('/auth/register') }}">
+ <form class="form-signin form-register" role="form" method="POST" action="@authurl('register')">
<div id="identity">
<span id="reauth-username" class="reauth-username"></span>
<label for="inputUsername">@lang('login.username')</label>
diff --git a/resources/views/auth/reset.blade.php b/resources/views/auth/reset.blade.php
--- a/resources/views/auth/reset.blade.php
+++ b/resources/views/auth/reset.blade.php
@@ -3,7 +3,7 @@
@section('card-content')
<div class="container-fluid">
<h1 class="title">@lang('login.resetPassword')</h1>
- <form class="form-signin form-reset" role="form" method="POST" action="{{ url('/auth/reset') }}">
+ <form class="form-signin form-reset" role="form" method="POST" action="@authurl('reset')">
<div id="identity">
<label for="inputEmail">@lang('login.email')</label>
<input type="email" name="email" id="inputEmail" class="form-control"
diff --git a/resources/views/emails/password.blade.php b/resources/views/emails/password.blade.php
--- a/resources/views/emails/password.blade.php
+++ b/resources/views/emails/password.blade.php
@@ -10,7 +10,7 @@
@lang('emails.reset-password-callforaction')
-{{ url('auth/reset/' . $token) }}
+@authurl('reset/{{ $token }}')
@lang('emails.reset-password-origin')
diff --git a/tests/Controller/Auth/AuthControllerTest.php b/tests/Controller/Auth/AuthControllerTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Controller/Auth/AuthControllerTest.php
@@ -0,0 +1,18 @@
+<?php
+
+use AuthGrove\Http\Controllers\Auth\AuthController;
+
+/**
+ * Test User model.
+ */
+class AuthControllerTest extends TestCase {
+
+ function testGetRoute () {
+ $this->assertSame('/auth/login', AuthController::getRoute('login'));
+ $this->assertSame('/auth', AuthController::getRoute(''));
+ $this->assertSame('/auth', AuthController::getRoute(null));
+ $this->assertSame('/auth', AuthController::getRoute(false));
+ $this->assertSame('/auth/0', AuthController::getRoute(0));
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 17, 08:23 (21 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2248876
Default Alt Text
D449.id1089.diff (10 KB)

Event Timeline