Skip to content

Commit 9a470b0

Browse files
committed
Added public build folder and support for a demo mode
1 parent 0d8ca22 commit 9a470b0

5 files changed

Lines changed: 37 additions & 5 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Homestead.yaml
99
/public/js
1010
/public/uploads
1111
/public/bower
12-
/public/build
1312
/storage/images
1413
_ide_helper.php
1514
/storage/debugbar

app/Http/Controllers/Controller.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ public function __construct()
4242
$this->signedIn = auth()->check();
4343
}
4444

45+
/**
46+
* Stops the application and shows a permission error if
47+
* the application is in demo mode.
48+
*/
49+
protected function preventAccessForDemoUsers()
50+
{
51+
if (env('APP_ENV', 'production') === 'demo') $this->showPermissionError();
52+
}
53+
4554
/**
4655
* Adds the page title into the view.
4756
* @param $title
@@ -51,6 +60,18 @@ public function setPageTitle($title)
5160
view()->share('pageTitle', $title);
5261
}
5362

63+
/**
64+
* On a permission error redirect to home and display
65+
* the error as a notification.
66+
*/
67+
protected function showPermissionError()
68+
{
69+
Session::flash('error', trans('errors.permission'));
70+
throw new HttpResponseException(
71+
redirect('/')
72+
);
73+
}
74+
5475
/**
5576
* Checks for a permission.
5677
*
@@ -60,15 +81,18 @@ public function setPageTitle($title)
6081
protected function checkPermission($permissionName)
6182
{
6283
if (!$this->currentUser || !$this->currentUser->can($permissionName)) {
63-
Session::flash('error', trans('errors.permission'));
64-
throw new HttpResponseException(
65-
redirect('/')
66-
);
84+
$this->showPermissionError();
6785
}
6886

6987
return true;
7088
}
7189

90+
/**
91+
* Check if a user has a permission or bypass if the callback is true.
92+
* @param $permissionName
93+
* @param $callback
94+
* @return bool
95+
*/
7296
protected function checkPermissionOr($permissionName, $callback)
7397
{
7498
$callbackResult = $callback();

app/Http/Controllers/SettingController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@ public function index()
3131
*/
3232
public function update(Request $request)
3333
{
34+
$this->preventAccessForDemoUsers();
3435
$this->checkPermission('settings-update');
36+
3537
// Cycles through posted settings and update them
3638
foreach($request->all() as $name => $value) {
3739
if(strpos($name, 'setting-') !== 0) continue;
3840
$key = str_replace('setting-', '', trim($name));
3941
Setting::put($key, $value);
4042
}
43+
4144
session()->flash('success', 'Settings Saved');
4245
return redirect('/settings');
4346
}

app/Http/Controllers/UserController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ public function edit($id, SocialAuthService $socialAuthService)
108108
*/
109109
public function update(Request $request, $id)
110110
{
111+
$this->preventAccessForDemoUsers();
111112
$this->checkPermissionOr('user-update', function () use ($id) {
112113
return $this->currentUser->id == $id;
113114
});
115+
114116
$this->validate($request, [
115117
'name' => 'required',
116118
'email' => 'required|email|unique:users,email,' . $id,
@@ -144,6 +146,7 @@ public function delete($id)
144146
$this->checkPermissionOr('user-delete', function () use ($id) {
145147
return $this->currentUser->id == $id;
146148
});
149+
147150
$user = $this->user->findOrFail($id);
148151
$this->setPageTitle('Delete User ' . $user->name);
149152
return view('users/delete', ['user' => $user]);
@@ -156,6 +159,7 @@ public function delete($id)
156159
*/
157160
public function destroy($id)
158161
{
162+
$this->preventAccessForDemoUsers();
159163
$this->checkPermissionOr('user-delete', function () use ($id) {
160164
return $this->currentUser->id == $id;
161165
});

public/build/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

0 commit comments

Comments
 (0)