Skip to content
This repository was archived by the owner on Jan 18, 2018. It is now read-only.

Commit 147d607

Browse files
Released 0.2.1
1 parent c9b558e commit 147d607

5 files changed

Lines changed: 49 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ CHANGE LOG
77
* Upgrade to Laravel 4.2
88

99

10+
## V0.2.1 Alpha (24/05/2014)
11+
12+
* Added the "auth" helper to the blade compiler
13+
14+
1015
## V0.2 Alpha (21/04/2014)
1116

1217
* PHP 5.6 and HHVM compatibility

src/CredentialsServiceProvider.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,37 @@ public function boot()
4545
{
4646
$this->package('graham-campbell/credentials', 'graham-campbell/credentials', __DIR__);
4747

48+
$this->setupBlade();
49+
4850
$this->setupViewer();
4951

5052
include __DIR__.'/routes.php';
5153
include __DIR__.'/filters.php';
5254
include __DIR__.'/listeners.php';
5355
}
5456

57+
/**
58+
* Setup the blade compiler class.
59+
*
60+
* @return void
61+
*/
62+
protected function setupBlade()
63+
{
64+
$blade = $this->app['view']->getEngineResolver()->resolve('blade')->getCompiler();
65+
66+
$blade->extend(function ($value, $compiler) {
67+
$pattern = $compiler->createMatcher('auth');
68+
$replace = '$1<?php if (\GrahamCampbell\Credentials\Facades\Credentials::check() && \GrahamCampbell\Credentials\Facades\Credentials::hasAccess$2): ?>';
69+
return preg_replace($pattern, $replace, $value);
70+
});
71+
72+
$blade->extend(function ($value, $compiler) {
73+
$pattern = $compiler->createPlainMatcher('endauth');
74+
$replace = '$1<?php endif; ?>$2';
75+
return preg_replace($pattern, $replace, $value);
76+
});
77+
}
78+
5579
/**
5680
* Setup the viewer class.
5781
*

src/views/users/edit.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
<div class="pull-right">
2626
&nbsp;<a class="btn btn-success" href="{{ URL::route('users.show', array('users' => $user->id)) }}"><i class="fa fa-file-text"></i> Show User</a>
2727
&nbsp;<a class="btn btn-warning" href="#suspend_user" data-toggle="modal" data-target="#suspend_user"><i class="fa fa-ban"></i> Suspend User</a>
28-
@if (Credentials::check() && Credentials::hasAccess('admin'))
28+
@auth('admin')
2929
&nbsp;<a class="btn btn-inverse" href="#reset_user" data-toggle="modal" data-target="#reset_user"><i class="fa fa-lock"></i> Reset Password</a>
3030
&nbsp;<a class="btn btn-danger" href="#delete_user" data-toggle="modal" data-target="#delete_user"><i class="fa fa-times"></i> Delete</a>
31-
@endif
31+
@endauth
3232
</div>
3333
</div>
3434
</div>
@@ -53,10 +53,10 @@
5353

5454
@section('bottom')
5555
@include('graham-campbell/credentials::users.suspend')
56-
@if (Credentials::check() && Credentials::hasAccess('admin'))
56+
@auth('admin')
5757
@include('graham-campbell/credentials::users.reset')
5858
@include('graham-campbell/credentials::users.delete')
59-
@endif
59+
@endauth
6060
@stop
6161

6262
@section('css')

src/views/users/index.blade.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
<div class="col-xs-8">
1616
<p class="lead">Here is a list of all the current users:</p>
1717
</div>
18-
@if (Credentials::check() && Credentials::hasAccess('admin'))
18+
@auth('admin')
1919
<div class="col-xs-4">
2020
<div class="pull-right">
2121
<a class="btn btn-primary" href="{{ URL::route('users.create') }}"><i class="fa fa-user"></i> New User</a>
2222
</div>
2323
</div>
24-
@endif
24+
@endauth
2525
</div>
2626
<hr>
2727
<div class="well">
@@ -38,14 +38,14 @@
3838
<td>{{ $user->email }}</td>
3939
<td>
4040
&nbsp;<a class="btn btn-success" href="{{ URL::route('users.show', array('users' => $user->id)) }}"><i class="fa fa-file-text"></i> Show</a>
41-
@if (Credentials::check() && Credentials::hasAccess('admin'))
41+
@auth('admin')
4242
&nbsp;<a class="btn btn-info" href="{{ URL::route('users.edit', array('users' => $user->id)) }}"><i class="fa fa-pencil-square-o"></i> Edit</a>
43-
@endif
43+
@endauth
4444
&nbsp;<a class="btn btn-warning" href="#suspend_user_{{ $user->id }}" data-toggle="modal" data-target="#suspend_user_{{ $user->id }}"><i class="fa fa-ban"></i> Suspend</a>
45-
@if (Credentials::check() && Credentials::hasAccess('admin'))
45+
@auth('admin')
4646
&nbsp;<a class="btn btn-inverse" href="#reset_user_{{ $user->id }}" data-toggle="modal" data-target="#reset_user_{{ $user->id }}"><i class="fa fa-lock"></i> Reset Password</a>
4747
&nbsp;<a class="btn btn-danger" href="#delete_user_{{ $user->id }}" data-toggle="modal" data-target="#delete_user_{{ $user->id }}"><i class="fa fa-times"></i> Delete</a>
48-
@endif
48+
@endauth
4949
</td>
5050
</tr>
5151
@endforeach
@@ -57,8 +57,8 @@
5757

5858
@section('bottom')
5959
@include('graham-campbell/credentials::users.suspends')
60-
@if (Credentials::check() && Credentials::hasAccess('admin'))
60+
@auth('admin')
6161
@include('graham-campbell/credentials::users.resets')
6262
@include('graham-campbell/credentials::users.deletes')
63-
@endif
63+
@endauth
6464
@stop

src/views/users/show.blade.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
</div>
2424
<div class="col-xs-6">
2525
<div class="pull-right">
26-
@if (Credentials::check() && Credentials::hasAccess('admin'))
26+
@auth('admin')
2727
&nbsp;<a class="btn btn-info" href="{{ URL::route('users.edit', array('users' => $user->id)) }}"><i class="fa fa-pencil-square-o"></i> Edit User</a>
28-
@endif
28+
@endauth
2929
&nbsp;<a class="btn btn-warning" href="#suspend_user" data-toggle="modal" data-target="#suspend_user"><i class="fa fa-ban"></i> Suspend User</a>
30-
@if (Credentials::check() && Credentials::hasAccess('admin'))
30+
@auth('admin')
3131
&nbsp;<a class="btn btn-inverse" href="#reset_user" data-toggle="modal" data-target="#reset_user"><i class="fa fa-lock"></i> Reset Password</a>
3232
&nbsp;<a class="btn btn-danger" href="#delete_user" data-toggle="modal" data-target="#delete_user"><i class="fa fa-times"></i> Delete</a>
33-
@endif
33+
@endauth
3434
</div>
3535
</div>
3636
</div>
@@ -74,22 +74,22 @@
7474
</div>
7575
</div>
7676
</div>
77-
@if (Credentials::check() && Credentials::hasAccess('admin'))
77+
@auth('admin')
7878
<hr>
7979
<h3>User Object</h3>
8080
<div>
8181
<pre>{{ var_dump($user) }}</pre>
8282
</div>
83-
@endif
83+
@endauth
8484
@stop
8585

8686
@section('bottom')
8787
@include('graham-campbell/credentials::users.suspend')
88-
@if (Credentials::check() && Credentials::hasAccess('admin'))
88+
@auth('admin')
8989
@if (Config::get('graham-campbell/credentials::activation'))
9090
@include('graham-campbell/credentials::users.resend')
9191
@endif
9292
@include('graham-campbell/credentials::users.reset')
9393
@include('graham-campbell/credentials::users.delete')
94-
@endif
94+
@endauth
9595
@stop

0 commit comments

Comments
 (0)