Page MenuHomeDevCentral

No OneTemporary

diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php
index 7c7560d..404662f 100644
--- a/app/Http/Controllers/Auth/AuthController.php
+++ b/app/Http/Controllers/Auth/AuthController.php
@@ -1,78 +1,110 @@
<?php
namespace AuthGrove\Http\Controllers\Auth;
use Illuminate\Contracts\Auth\Registrar as RegistrarContract;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use AuthGrove\Http\Controllers\Controller;
use AuthGrove\Services\Registrar;
use AuthGrove\Models\User;
+use Config;
use Route;
class AuthController extends Controller implements RegistrarContract
{
/*
|--------------------------------------------------------------------------
| 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, ThrottlesLogins, Registrar;
/**
* Where to redirect users after login / registration.
*
* @var string
*/
protected $redirectTo = '/';
/**
* The field to use as username
*
* @var string
*/
protected $username = 'username';
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
$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
index 195cada..37d4d02 100644
--- a/app/Providers/AppServiceProvider.php
+++ b/app/Providers/AppServiceProvider.php
@@ -1,30 +1,38 @@
<?php namespace AuthGrove\Providers;
use Illuminate\Support\ServiceProvider;
+use AuthGrove\Http\Controllers\Auth\AuthController;
+
+use Blade;
+
class AppServiceProvider extends ServiceProvider {
/**
* Bootstrap any application services.
*
* @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));
+ });
}
/**
* Register any application services.
*
* This service provider is a great spot to register your various container
* bindings with the application. As you can see, we are registering our
* "Registrar" implementation here. You can add your own bindings too!
*
* @return void
*/
public function register()
{
}
}
diff --git a/config/auth.php b/config/auth.php
index 670166b..4fe6353 100644
--- a/config/auth.php
+++ b/config/auth.php
@@ -1,107 +1,118 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => AuthGrove\Models\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| Here you may set the options for resetting passwords including the view
| that is your password reset e-mail. You may also set the name of the
| table that maintains all of the reset tokens for your application.
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'email' => 'emails.password',
'table' => 'password_resets',
'expire' => 60,
],
],
+ /*
+ |--------------------------------------------------------------------------
+ | 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
index 01ae6e6..7589289 100644
--- a/resources/views/app.blade.php
+++ b/resources/views/app.blade.php
@@ -1,58 +1,58 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>@lang('app.title')</title>
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.min.css" rel='stylesheet' type='text/css' />
<link href="{{ asset('/css/app.css') }}" rel="stylesheet">
<!-- Fonts -->
<link href='//fonts.googleapis.com/css?family=Roboto:400,300' rel='stylesheet' type='text/css'>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">@lang('panel.toggle-navigation')</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">@lang('app.title')</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="{{ url('/') }}">@lang('panel.home')</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<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>
</div>
</div>
</nav>
@yield('content')
<!-- Scripts -->
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/js/bootstrap.min.js"></script>
</body>
</html>
diff --git a/resources/views/auth/fatal-error.blade.php b/resources/views/auth/fatal-error.blade.php
new file mode 100644
index 0000000..77ffc9c
--- /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
index 71d5edc..68890f6 100644
--- a/resources/views/auth/login.blade.php
+++ b/resources/views/auth/login.blade.php
@@ -1,33 +1,33 @@
@extends('auth.master')
@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"
value="{{ old('username') }}" placeholder="@lang('login.username')" required autofocus />
<input type="password" name="password" id="inputPassword" class="form-control" placeholder="@lang('login.password')" required />
</div>@if (count($errors) > 0)
<p class="errors">
@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
<div id="remember" class="checkbox">
<label><input type="checkbox" name="remember">@lang('login.remember')</label>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<button class="btn btn-lg btn-primary btn-block btn-signin" type="submit">@lang('login.loginButton')</button>
</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
index 8c5b6eb..cfc5873 100644
--- a/resources/views/auth/recover.blade.php
+++ b/resources/views/auth/recover.blade.php
@@ -1,28 +1,28 @@
@extends('auth.master')
@section('card-content')
<h1 class="title">@lang('login.recoverAccess')</h1>
@if (session('status'))
<p class="success">{{ session('status') }}</p>
<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 />
</div>@if (count($errors) > 0)
<p class="errors">
@foreach ($errors->all() as $error)
{{ $error }}<br />
@endforeach
</p>
@endif
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<button class="btn btn-lg btn-primary btn-block btn-signin" type="submit">@lang('login.recoverButton')</button>
</form>
@endif
@endsection
diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php
index 20e8b7e..99ea3e7 100644
--- a/resources/views/auth/register.blade.php
+++ b/resources/views/auth/register.blade.php
@@ -1,33 +1,33 @@
@extends('auth.master')
@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>
<input type="text" name="username" id="inputUsername" class="form-control"
value="{{ old('username') }}" placeholder="@lang('login.usernamePlaceholder')" required autofocus />
<label for="inputFullname">@lang('login.fullname')</label>
<input type="text" name="fullname" id="inputFullname" class="form-control"
value="{{ old('fullname') }}" placeholder="@lang('login.fullnamePlaceholder')" autofocus />
<label for="inputEmail">@lang('login.email')</label>
<input type="email" name="email" id="inputEmail" class="form-control"
value="{{ old('email') }}" placeholder="@lang('login.emailPlaceholder')" required autofocus />
<label for="inputPassword">@lang('login.passwordBoth')</label>
<input type="password" name="password" id="inputPassword" class="form-control" placeholder="@lang('login.passwordPlaceholder')" required />
<input type="password" name="password_confirmation" id="inputPasswordConfirm" class="form-control" placeholder="@lang('login.passwordConfirmPlaceholder')" required />
</div>@if (count($errors) > 0)
<p class="errors">
@foreach ($errors->all() as $error)
{{ $error }}<br />
@endforeach
</p>
@endif
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<button class="btn btn-lg btn-primary btn-block btn-signin" type="submit">@lang('login.registerButton')</button>
</form>
<!-- /form -->
@endsection
diff --git a/resources/views/auth/reset.blade.php b/resources/views/auth/reset.blade.php
index cb4b8b2..c0e4b1c 100644
--- a/resources/views/auth/reset.blade.php
+++ b/resources/views/auth/reset.blade.php
@@ -1,27 +1,27 @@
@extends('auth.master')
@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"
value="{{ old('email') }}" placeholder="@lang('login.emailPlaceholder')" required autofocus />
<label for="inputPassword">@lang('login.passwordBoth')</label>
<input type="password" name="password" id="inputPassword" class="form-control" placeholder="@lang('login.passwordPlaceholder')" required />
<input type="password" name="password_confirmation" id="inputPasswordConfirm" class="form-control" placeholder="@lang('login.passwordConfirmPlaceholder')" required />
</div>@if (count($errors) > 0)
<p class="errors">
@foreach ($errors->all() as $error)
{{ $error }}<br />
@endforeach
</p>
@endif
<input type="hidden" name="token" value="{{ $token }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<button class="btn btn-lg btn-primary btn-block btn-signin" type="submit">@lang('login.resetButton')</button>
</form>
</div>
@endsection
diff --git a/resources/views/emails/password.blade.php b/resources/views/emails/password.blade.php
index 0dd3218..4d97a3e 100644
--- a/resources/views/emails/password.blade.php
+++ b/resources/views/emails/password.blade.php
@@ -1,18 +1,18 @@
@extends('emails.master')
@section('mail-content')
@lang('emails.reset-password-intro')
@lang('emails.reset-password-login')
{{ $user->username }}
@lang('emails.reset-password-callforaction')
-{{ url('auth/reset/' . $token) }}
+@authurl('reset/{{ $token }}')
@lang('emails.reset-password-origin')
{{ \Keruald\get_remote_addr() }}
@endsection
diff --git a/tests/Controller/Auth/AuthControllerTest.php b/tests/Controller/Auth/AuthControllerTest.php
new file mode 100644
index 0000000..a3a4227
--- /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/x-diff
Expires
Wed, Mar 18, 12:27 (1 d, 6 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3538062
Default Alt Text
(22 KB)

Event Timeline