Page MenuHomeDevCentral

D521.id1272.diff
No OneTemporary

D521.id1272.diff

diff --git a/app/Helpers/.gitkeep b/app/Helpers/.gitkeep
deleted file mode 100644
diff --git a/app/Helpers/Routing.php b/app/Helpers/Routing.php
new file mode 100644
--- /dev/null
+++ b/app/Helpers/Routing.php
@@ -0,0 +1,28 @@
+<?php
+
+use AuthGrove\Http\Controllers\Auth\AuthController;
+
+/*
+|--------------------------------------------------------------------------
+| Blade helper global functions
+|--------------------------------------------------------------------------
+|
+| This file register global helper functions to act as convenient aliases
+| for methods normally requiring a fully qualified class name with namespaces
+| to use in Blade template.
+|
+| e.g. {{ authurl('login') }} is a shorthand syntax for the longer construct
+[ {{ url(AuthGrove\Http\Controllers\Auth\AuthController::getRoute('login')) }}
+|
+*/
+
+/**
+ * Gets the full URL of a specified auth route.
+ *
+ * @param string $action The authentication action (e.g. login) [facultative]
+ * @return string The full URL (e.g. https://grove.domain.tld/auth/login)
+ */
+function authurl ($action = '') {
+ $route = AuthController::getRoute($action);
+ return url($route);
+}
diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php
--- a/app/Providers/AppServiceProvider.php
+++ b/app/Providers/AppServiceProvider.php
@@ -2,10 +2,6 @@
use Illuminate\Support\ServiceProvider;
-use AuthGrove\Http\Controllers\Auth\AuthController;
-
-use Blade;
-
class AppServiceProvider extends ServiceProvider {
/**
@@ -14,12 +10,6 @@
* @return void
*/
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/app/Providers/HelpersServiceProvider.php b/app/Providers/HelpersServiceProvider.php
--- a/app/Providers/HelpersServiceProvider.php
+++ b/app/Providers/HelpersServiceProvider.php
@@ -21,6 +21,7 @@
* @return void
*/
public function register() {
+ require_once app_path() . '/Helpers/Routing.php';
}
}
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
@@ -42,7 +42,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="@authurl('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
--- a/resources/views/auth/fatal-error.blade.php
+++ b/resources/views/auth/fatal-error.blade.php
@@ -8,5 +8,5 @@
{{ $error }}<br />
@endforeach
</p>
- <a href="@authurl('login')" class="action-link">@lang('login.goto-login')</a>
+ <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="@authurl('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="@authurl('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="@authurl('recover')" class="action-link">@lang('login.passwordRecovery')</a><br />
+ <a href="{{ authurl('recover') }}" class="action-link">@lang('login.passwordRecovery')</a><br />
@endif
- <a href="@authurl('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="@authurl('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="@authurl('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="@authurl('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')
-@authurl('reset/{{ $token }}')
+{{ authurl("reset/$token") }}
@lang('emails.reset-password-origin')
diff --git a/tests/Helpers/RoutingTest.php b/tests/Helpers/RoutingTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Helpers/RoutingTest.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace AuthGrove\Tests\Helpers;
+
+use AuthGrove\Tests\TestCase;
+
+class RoutingTest extends TestCase {
+
+ function testGetRoute () {
+ $this->assertStringEndsWith('/auth/login', authurl('login'));
+ $this->assertStringEndsWith('/auth', authurl());
+ $this->assertStringEndsWith('/auth', authurl(''));
+ $this->assertStringEndsWith('/auth', authurl(null));
+ $this->assertStringEndsWith('/auth', authurl(false));
+ $this->assertStringEndsWith('/auth/0', authurl(0));
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 13:03 (8 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2260205
Default Alt Text
D521.id1272.diff (8 KB)

Event Timeline