Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Зуев Егор
/
wiki.dev
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
Dan Brown
2015-12-31 17:57:34 +0000
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
9a470b07fdc2bbada54735bb9d07045b6ff937a9
9a470b07
1 parent
0d8ca224
Added public build folder and support for a demo mode
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
5 deletions
.gitignore
app/Http/Controllers/Controller.php
app/Http/Controllers/SettingController.php
app/Http/Controllers/UserController.php
public/build/.gitignore
.gitignore
View file @
9a470b0
...
...
@@ -9,7 +9,6 @@ Homestead.yaml
/public/js
/public/uploads
/public/bower
/public/build
/storage/images
_ide_helper.php
/storage/debugbar
\ No newline at end of file
...
...
app/Http/Controllers/Controller.php
View file @
9a470b0
...
...
@@ -43,6 +43,15 @@ abstract class Controller extends BaseController
}
/**
* Stops the application and shows a permission error if
* the application is in demo mode.
*/
protected
function
preventAccessForDemoUsers
()
{
if
(
env
(
'APP_ENV'
,
'production'
)
===
'demo'
)
$this
->
showPermissionError
();
}
/**
* Adds the page title into the view.
* @param $title
*/
...
...
@@ -52,6 +61,18 @@ abstract class Controller extends BaseController
}
/**
* On a permission error redirect to home and display
* the error as a notification.
*/
protected
function
showPermissionError
()
{
Session
::
flash
(
'error'
,
trans
(
'errors.permission'
));
throw
new
HttpResponseException
(
redirect
(
'/'
)
);
}
/**
* Checks for a permission.
*
* @param $permissionName
...
...
@@ -60,15 +81,18 @@ abstract class Controller extends BaseController
protected
function
checkPermission
(
$permissionName
)
{
if
(
!
$this
->
currentUser
||
!
$this
->
currentUser
->
can
(
$permissionName
))
{
Session
::
flash
(
'error'
,
trans
(
'errors.permission'
));
throw
new
HttpResponseException
(
redirect
(
'/'
)
);
$this
->
showPermissionError
();
}
return
true
;
}
/**
* Check if a user has a permission or bypass if the callback is true.
* @param $permissionName
* @param $callback
* @return bool
*/
protected
function
checkPermissionOr
(
$permissionName
,
$callback
)
{
$callbackResult
=
$callback
();
...
...
app/Http/Controllers/SettingController.php
View file @
9a470b0
...
...
@@ -31,13 +31,16 @@ class SettingController extends Controller
*/
public
function
update
(
Request
$request
)
{
$this
->
preventAccessForDemoUsers
();
$this
->
checkPermission
(
'settings-update'
);
// Cycles through posted settings and update them
foreach
(
$request
->
all
()
as
$name
=>
$value
)
{
if
(
strpos
(
$name
,
'setting-'
)
!==
0
)
continue
;
$key
=
str_replace
(
'setting-'
,
''
,
trim
(
$name
));
Setting
::
put
(
$key
,
$value
);
}
session
()
->
flash
(
'success'
,
'Settings Saved'
);
return
redirect
(
'/settings'
);
}
...
...
app/Http/Controllers/UserController.php
View file @
9a470b0
...
...
@@ -108,9 +108,11 @@ class UserController extends Controller
*/
public
function
update
(
Request
$request
,
$id
)
{
$this
->
preventAccessForDemoUsers
();
$this
->
checkPermissionOr
(
'user-update'
,
function
()
use
(
$id
)
{
return
$this
->
currentUser
->
id
==
$id
;
});
$this
->
validate
(
$request
,
[
'name'
=>
'required'
,
'email'
=>
'required|email|unique:users,email,'
.
$id
,
...
...
@@ -144,6 +146,7 @@ class UserController extends Controller
$this
->
checkPermissionOr
(
'user-delete'
,
function
()
use
(
$id
)
{
return
$this
->
currentUser
->
id
==
$id
;
});
$user
=
$this
->
user
->
findOrFail
(
$id
);
$this
->
setPageTitle
(
'Delete User '
.
$user
->
name
);
return
view
(
'users/delete'
,
[
'user'
=>
$user
]);
...
...
@@ -156,6 +159,7 @@ class UserController extends Controller
*/
public
function
destroy
(
$id
)
{
$this
->
preventAccessForDemoUsers
();
$this
->
checkPermissionOr
(
'user-delete'
,
function
()
use
(
$id
)
{
return
$this
->
currentUser
->
id
==
$id
;
});
...
...
public/build/.gitignore
0 → 100644
View file @
9a470b0
*
!.gitignore
Please
register
or
sign in
to post a comment