diff --git a/CHANGELOG.md b/CHANGELOG.md
index 190bd65..c82ba30 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,11 @@ CHANGE LOG
* Upgrade to Laravel 4.2
+## V0.2.1 Alpha (24/05/2014)
+
+* Added the "auth" helper to the blade compiler
+
+
## V0.2 Alpha (21/04/2014)
* PHP 5.6 and HHVM compatibility
diff --git a/src/CredentialsServiceProvider.php b/src/CredentialsServiceProvider.php
index eaae116..9927a11 100644
--- a/src/CredentialsServiceProvider.php
+++ b/src/CredentialsServiceProvider.php
@@ -45,6 +45,8 @@ public function boot()
{
$this->package('graham-campbell/credentials', 'graham-campbell/credentials', __DIR__);
+ $this->setupBlade();
+
$this->setupViewer();
include __DIR__.'/routes.php';
@@ -52,6 +54,28 @@ public function boot()
include __DIR__.'/listeners.php';
}
+ /**
+ * Setup the blade compiler class.
+ *
+ * @return void
+ */
+ protected function setupBlade()
+ {
+ $blade = $this->app['view']->getEngineResolver()->resolve('blade')->getCompiler();
+
+ $blade->extend(function ($value, $compiler) {
+ $pattern = $compiler->createMatcher('auth');
+ $replace = '$1';
+ return preg_replace($pattern, $replace, $value);
+ });
+
+ $blade->extend(function ($value, $compiler) {
+ $pattern = $compiler->createPlainMatcher('endauth');
+ $replace = '$1$2';
+ return preg_replace($pattern, $replace, $value);
+ });
+ }
+
/**
* Setup the viewer class.
*
diff --git a/src/views/users/edit.blade.php b/src/views/users/edit.blade.php
index 6b505de..8110985 100644
--- a/src/views/users/edit.blade.php
+++ b/src/views/users/edit.blade.php
@@ -25,10 +25,10 @@
@@ -53,10 +53,10 @@
@section('bottom')
@include('graham-campbell/credentials::users.suspend')
-@if (Credentials::check() && Credentials::hasAccess('admin'))
+@auth('admin')
@include('graham-campbell/credentials::users.reset')
@include('graham-campbell/credentials::users.delete')
-@endif
+@endauth
@stop
@section('css')
diff --git a/src/views/users/index.blade.php b/src/views/users/index.blade.php
index 62e472e..ceda50b 100644
--- a/src/views/users/index.blade.php
+++ b/src/views/users/index.blade.php
@@ -15,13 +15,13 @@
Here is a list of all the current users:
- @if (Credentials::check() && Credentials::hasAccess('admin'))
+ @auth('admin')
- @endif
+ @endauth
@@ -38,14 +38,14 @@
{{ $user->email }} |
Show
- @if (Credentials::check() && Credentials::hasAccess('admin'))
+ @auth('admin')
Edit
- @endif
+ @endauth
Suspend
- @if (Credentials::check() && Credentials::hasAccess('admin'))
+ @auth('admin')
Reset Password
Delete
- @endif
+ @endauth
|
@endforeach
@@ -57,8 +57,8 @@
@section('bottom')
@include('graham-campbell/credentials::users.suspends')
-@if (Credentials::check() && Credentials::hasAccess('admin'))
+@auth('admin')
@include('graham-campbell/credentials::users.resets')
@include('graham-campbell/credentials::users.deletes')
-@endif
+@endauth
@stop
diff --git a/src/views/users/show.blade.php b/src/views/users/show.blade.php
index 9d29d84..d533aff 100644
--- a/src/views/users/show.blade.php
+++ b/src/views/users/show.blade.php
@@ -23,14 +23,14 @@
- @if (Credentials::check() && Credentials::hasAccess('admin'))
+ @auth('admin')
Edit User
- @endif
+ @endauth
Suspend User
- @if (Credentials::check() && Credentials::hasAccess('admin'))
+ @auth('admin')
Reset Password
Delete
- @endif
+ @endauth
@@ -74,22 +74,22 @@
-@if (Credentials::check() && Credentials::hasAccess('admin'))
+@auth('admin')
User Object
-@endif
+@endauth
@stop
@section('bottom')
@include('graham-campbell/credentials::users.suspend')
-@if (Credentials::check() && Credentials::hasAccess('admin'))
+@auth('admin')
@if (Config::get('graham-campbell/credentials::activation'))
@include('graham-campbell/credentials::users.resend')
@endif
@include('graham-campbell/credentials::users.reset')
@include('graham-campbell/credentials::users.delete')
-@endif
+@endauth
@stop