Skip to content

Commit b0d6574

Browse files
committed
Admin - Restructure accounts, move administrators and add 'is_preview' settings
1 parent b4c7212 commit b0d6574

File tree

18 files changed

+762
-303
lines changed

18 files changed

+762
-303
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ A Laravel CMS Starter project with AdminLTE theme and core features.
1111
- Password: github
1212

1313
### What is New?
14-
- Upgraded to Laravel 5.5 and added many new 'components (blog, news, banners, etc)'
14+
- Upgraded to Laravel 5.6 and added many new 'components (blog, news, banners, etc)'
1515
- Page Builder (CRUD website pages with 3 different components)
16+
- Add config/app.php - "is_preview". This is to prevent users to delete pages and users from the demo site.
1617

1718
## Features / What it includes
1819
- Admin LTE admin theme
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Admin\Accounts;
4+
5+
use App\Http\Controllers\Admin\AdminController;
6+
use App\Mail\AdminInvitRegistration;
7+
use App\Models\Role;
8+
use App\Models\UserInvite;
9+
use App\User;
10+
use App\Models\UsersInvite;
11+
use Illuminate\Http\Request;
12+
use Mail;
13+
use Titan\Controllers\TitanAdminController;
14+
15+
class AdministratorsController extends AdminController
16+
{
17+
/**
18+
* Show all the administrators
19+
*
20+
* @return mixed
21+
*/
22+
public function index()
23+
{
24+
save_resource_url();
25+
26+
$items = User::with('roles')->whereRole(Role::$BASE_ADMIN)->get();
27+
28+
return $this->view('accounts.administrators.index', compact('items'));
29+
}
30+
31+
/**
32+
* Show the invites
33+
*
34+
* @return mixed
35+
*/
36+
public function showInvites()
37+
{
38+
$items = UserInvite::orderBy('created_at')->get();
39+
40+
return $this->view('accounts.administrators.invite')->with('items', $items);
41+
}
42+
43+
/**
44+
* @param \Illuminate\Http\Request $request
45+
* @return mixed
46+
*/
47+
public function postInvite(Request $request)
48+
{
49+
$this->validate($request, [
50+
'email' => 'required|email|unique:users' // |unique:user_invites
51+
]);
52+
53+
// if already exist - send invite again
54+
$row = UserInvite::where('email', input('email'))->first();
55+
if (!$row) {
56+
// create row
57+
$row = UserInvite::create([
58+
'email' => input('email'),
59+
'token' => '-',
60+
'invited_by' => user()->id,
61+
]);
62+
}
63+
64+
// send mail to email
65+
Mail::send(new AdminInvitRegistration($row));
66+
67+
notify()->success('Success', 'Invitation sent to ' . $row->email,
68+
'thumbs-up bounce animated');
69+
70+
return redirect_to_resource();
71+
}
72+
73+
/**
74+
* Show the form for editing the specified faq.
75+
*
76+
* @param User $administrator
77+
* @return Response
78+
*/
79+
public function edit(User $administrator)
80+
{
81+
$roles = Role::getAllLists();
82+
83+
return $this->view('accounts.administrators.create_edit', compact('roles'))
84+
->with('item', $administrator);
85+
}
86+
87+
/**
88+
* Update the specified faq in storage.
89+
* @param User $administrator
90+
* @param Request $request
91+
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
92+
*/
93+
public function update(User $administrator, Request $request)
94+
{
95+
$this->validate($request, [
96+
'firstname' => 'required',
97+
'lastname' => 'required',
98+
'roles' => 'required|array',
99+
]);
100+
101+
$this->updateEntry($administrator, $request->only([
102+
'firstname',
103+
'lastname',
104+
'cellphone',
105+
'telephone',
106+
'born_at'
107+
]));
108+
109+
$administrator->roles()->sync(input('roles'));
110+
111+
return redirect_to_resource();
112+
}
113+
114+
/**
115+
* Remove the specified faq from storage.
116+
* @param User $administrator
117+
* @param Request $request
118+
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
119+
*/
120+
public function destroy(User $administrator, Request $request)
121+
{
122+
if ($administrator->id <= 3) {
123+
notify()->warning('Whoops', 'You can not delete this user.');
124+
}
125+
else {
126+
$this->deleteEntry($administrator, $request);
127+
}
128+
129+
return redirect_to_resource();
130+
}
131+
}

app/Http/Controllers/Admin/Pages/PagesController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ public function update(Page $page)
119119
public function destroy(Page $page)
120120
{
121121
// for the showcase - do not delete 'active' pages
122-
if ($page->id < 30) {
123-
notify()->error('Whoops', "Did you really try to delete this page?");
122+
if (config('app.is_preview') || $page->id < 30) {
123+
notify()->error('Whoops', "Site is in 'preview' mode. Please disable or nice try...");
124124

125125
return redirect_to_resource();
126126
}

app/Http/Controllers/Admin/Settings/NavigationController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ public function update($id, Request $request)
150150
*/
151151
public function destroy($id, Request $request)
152152
{
153+
// for the showcase - do not delete 'active' pages
154+
if (config('app.is_preview') || $id < 58) {
155+
notify()->error('Whoops', "Site is in 'preview' mode. Please disable or nice try...");
156+
157+
return redirect_to_resource();
158+
}
159+
153160
$navigation = NavigationAdmin::findOrFail($id);
154161
$this->deleteEntry($navigation, $request);
155162

app/Http/Middleware/AuthenticateAdmin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AuthenticateAdmin
1818
public function handle($request, Closure $next, $guard = null)
1919
{
2020
// not logged in as an admin - logout and go home
21-
if (!user()->isBaseAdmin()) {
21+
if (!user()->isAdmin()) {
2222
\Auth::logout();
2323

2424
return redirect()->guest('/');

app/Models/Traits/UserAdmin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ trait UserAdmin
1111
* On /admin login validation and all /admin navigation
1212
* @return bool
1313
*/
14-
public function isBaseAdmin()
14+
public function isAdmin()
1515
{
1616
return $this->hasRole(Role::$BASE_ADMIN);
1717
}
@@ -20,7 +20,7 @@ public function isBaseAdmin()
2020
* If User is admin
2121
* @return bool
2222
*/
23-
public function isAdmin()
23+
public function isSuperAdmin()
2424
{
2525
return $this->hasRole(Role::$ADMIN);
2626
}

config/app.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
'google_analytics' => env('GOOGLE_ANALYTICS', ''),
1212
'google_map_key' => env('GOOGLE_MAP_KEY', ''),
1313

14+
// https://github.com/bpocallaghan/laravel-admin-starter
15+
// This will add the 'preview' text / user roles validation
16+
// Set to false or remove key will ignore the 'preview' settings
17+
'is_preview' => true,
18+
1419
'debug_blacklist' => [
1520
'_ENV' => array_keys($_ENV),
1621
'_COOKIE' => array_keys($_COOKIE),

database/seeds/RoleTableSeeder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ public function run()
2020
// basic user (website or/and admin or any other accounts)
2121
Role::create([
2222
'icon' => 'user',
23-
'name' => 'Base User',
23+
'name' => 'User',
2424
'slug' => '/',
2525
'keyword' => 'user',
2626
]);
2727

2828
// base admin role (to be able to log into /admin)
2929
Role::create([
3030
'icon' => 'user-secret',
31-
'name' => 'Basic Admin',
31+
'name' => 'Base Admin',
3232
'slug' => '/admin',
3333
'keyword' => 'base_admin',
3434
]);

database/seeds/UserTableSeeder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ public function run(Faker\Generator $faker)
8181
*/
8282
private function addAllRolesToUser($user)
8383
{
84-
$roles = Role::all()->pluck('keyword', 'id')->values();
84+
// only 2 - to 5 are needed
85+
$roles = Role::whereBetween('id', [2, 5])
86+
->pluck('keyword', 'id')
87+
->values();
8588

8689
$user->syncRoles($roles);
8790
}
Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,59 @@
1-
id,title,description,slug,url,icon,help_index_title,help_index_content,help_create_title,help_create_content,help_edit_title,help_edit_content,list_order,is_hidden,parent_id,url_parent_id,roles,
2-
1,Dashboard,Dashboard,/,/admin,dashboard,,,,,,,1,0,0,0,2,
3-
2,Analytics,Google Analytics,analytics,/admin/analytics,line-chart,,,,,,,11,0,0,0,"3,4",
4-
3,Summary,,,/admin/analytics,star-half-o,,,,,,,2,0,2,2,"3,4",
5-
4,Devices,,devices,/admin/analytics/devices,tablet,,,,,,,1,0,2,2,"3,4",
6-
5,Demographics,,demographics,/admin/analytics/demographics,female,,,,,,,4,0,2,2,"3,4",
7-
6,Visits and Referrals,,visits-and-referrals,/admin/analytics/visits-and-referrals,cloud,,,,,,,5,0,2,2,"3,4",
8-
7,Interests,,interests,/admin/analytics/interests,heart,,,,,,,3,0,2,2,"3,4",
9-
8,Latest Activity,Latest Activity,latest-activity,/admin/latest-activity,history,,,,,,,2,0,0,0,4,
10-
9,Website,,website,/admin/latest-activity/website,home,,,,,,,1,0,8,8,4,
11-
10,Admin,Admin,admin,/admin/latest-activity/admin,lock,,,,,,,2,0,8,8,4,
12-
11,Testimonials,Testimonials,testimonials,/admin/general/testimonials,commenting-o,Info,List of all the testimonials on the website,How,Please complete the form to create the testimonial,How,Please complete the form to edit the selected testimonial,3,0,17,17,4,
13-
12,Locations,,locations,/admin/general/locations,globe,,,,,,,6,0,17,17,4,
14-
13,Countries,Countries,countries,/admin/general/locations/countries,map-marker,,,,,,,4,0,12,12,4,
15-
14,Provinces,Provinces,provinces,/admin/general/locations/provinces,map-marker,,,,,,,3,0,12,12,4,
16-
15,Cities,,cities,/admin/general/locations/cities,map-marker,,,,,,,2,0,12,12,4,
17-
16,Suburbs,,suburbs,/admin/general/locations/suburbs,map-marker,,,,,,,1,0,12,12,4,
18-
17,General,General Website,general,/admin/general,cubes,,,,,,,3,0,0,0,4,
19-
18,Reports,,reports,/admin/reports,bar-chart,,,,,,,12,0,0,0,4,
20-
19,Summary,,summary,/admin/reports/summary,align-left,,,,,,,1,0,18,18,4,
21-
20,Contact Us,,contact-us,/admin/reports/contact-us,comments-o,,,,,,,2,0,18,18,4,
22-
21,Settings,,settings,/admin/settings,cogs,,,,,,,13,0,0,0,4,
23-
22,Subscription Plans,Subscription Plans,subscription-plans,/admin/settings/subscription-plans,money,,,,,,,3,0,21,21,4,
24-
23,Features,Features,features,/admin/settings/subscription-plans/features,tags,,,,,,,4,1,22,22,4,
25-
24,Pages,Pages,pages,/admin/pages,navicon,Help,All the menu items for the website.,Help,You can set the HTML Title and HTML Description.<br/>You can select the parent (under which navigation is this item).<br/>You can specify if the menu is hidden.,,,4,0,0,0,4,
26-
25,Changelogs,,changelogs,/admin/settings/changelogs,file-text-o,,,,,,,2,0,21,21,4,
27-
26,Navigation,,navigation,/admin/settings/navigation,align-center,Help,Helpfull text here - explaining what u can do here...,Information,Please complete the form to create the navigation,,,6,0,21,21,4,
28-
27,Administrators,,administrators,/admin/settings/administrators,users,,,,,,,7,0,21,21,4,
29-
28,Admin Invites,,invites,/admin/settings/administrators/invites,,,,,,,,1,1,27,27,4,
30-
29,Profile,,profile,/admin/profile,user,,,,,,,14,1,0,0,4,
31-
30,Navigation Order,Navigation Order,order,/admin/settings/navigation/order,list-ol,,,,,,,1,1,26,26,4,
32-
31,Navigation Order,Navigation Order,order,/admin/pages/order,list-ol,,,,,,,1,1,24,24,4,
33-
32,Banners,Banners,banners,/admin/general/banners,image,,,,,,,2,0,17,17,4,
34-
33,Corporate,Corporate,corporate,/admin/corporate,bank,,,,,,,8,0,0,0,4,
35-
34,Roles,Roles,roles,/admin/settings/roles,universal-access,,,,,,,1,0,21,21,4,
36-
35,Tenders,Tenders,tenders,/admin/corporate/tenders,tags,,,,,,,1,0,33,33,4,
37-
36,Blog,Blog,blog,/admin/blog,newspaper-o,,,,,,,6,0,0,0,4,
38-
37,Articles,Articles,articles,/admin/blog/articles,newspaper-o,,,,,,,1,0,36,36,4,
39-
38,Categories,Categories,categories,/admin/blog/categories,cubes,,,,,,,2,0,36,36,4,
40-
39,Tags,Tags,tags,/admin/general/tags,tags,,,,,,,1,0,17,17,4,
41-
40,FAQ,FAQ,faqs,/admin/faqs,question,,,,,,,9,0,0,0,4,
42-
41,FAQ Questions,FAQ Questions,,/admin/faqs,question,,,,,,,2,0,40,40,4,
43-
42,Categories,Categories,categories,/admin/faqs/categories,cubes,,,,,,,1,0,40,40,4,
44-
43,Vacancies,Vacancies,vacancies,/admin/corporate/vacancies,vcard-o,,,,,,,2,0,33,33,4,
45-
44,Annual Reports,Annual Reports,annual-reports,/admin/corporate/annual-reports,files-o,,,,,,,3,0,33,33,4,
46-
45,News and Events,News and Events,news-and-events,/admin/news-and-events,newspaper-o,,,,,,,7,0,0,0,4,
47-
46,News and Events,News and Events,news,/admin/news-and-events/news,newspaper-o,,,,,,,2,0,45,45,4,
48-
47,Categories,Categories,categories,/admin/news-and-events/categories,cubes,,,,,,,1,0,45,45,4,
49-
48,Gallery,Images,photos,/admin/photos,image,,,,,,,5,0,0,0,4,
50-
49,Photos,Photos,,/admin/photos,image,,,,,,,2,0,48,48,4,
51-
50,Albums,Albums,albums,/admin/photos/albums,cubes,,,,,,,1,0,48,48,4,
52-
51,Settings,Settings,settings,/admin/settings/settings,cog,,,,,,,5,0,21,21,4,
53-
52,Newsletter,Newsletter,newsletter,/admin/newsletter,newspaper-o,,,,,,,10,0,0,0,4,
54-
53,Subscribers,Newsletter Subscribers,subscribers,/admin/newsletter/subscribers,users,,,,,,,1,0,52,525,4,
55-
54,Clients,Clients,clients,/admin/general/clients,users,,,,,,,5,0,17,17,4,
56-
55,Documents,Documents,documents,/admin/documents,files-o,,,,,,,10,0,0,0,4,
57-
56,Categories,Categories,categories,/admin/documents/categories,cubes,,,,,,,1,0,55,55,4,
58-
57,Documents,Documents,,/admin/documents,file-o,,,,,,,2,0,55,55,4,
1+
id,title,description,slug,url,icon,help_index_title,help_index_content,help_create_title,help_create_content,help_edit_title,help_edit_content,list_order,is_hidden,parent_id,url_parent_id,roles
2+
1,Dashboard,Dashboard,/,/admin,dashboard,,,,,,,1,0,0,0,2
3+
2,Analytics,Google Analytics,analytics,/admin/analytics,line-chart,,,,,,,13,0,0,0,"3,6"
4+
3,Summary,,,/admin/analytics,star-half-o,,,,,,,2,0,2,2,"3,6"
5+
4,Devices,,devices,/admin/analytics/devices,tablet,,,,,,,1,0,2,2,"3,6"
6+
5,Demographics,,demographics,/admin/analytics/demographics,female,,,,,,,4,0,2,2,"3,6"
7+
6,Visits and Referrals,,visits-and-referrals,/admin/analytics/visits-and-referrals,cloud,,,,,,,5,0,2,2,"3,6"
8+
7,Interests,,interests,/admin/analytics/interests,heart,,,,,,,3,0,2,2,"3,6"
9+
8,Latest Activity,Latest Activity,latest-activity,/admin/latest-activity,history,,,,,,,2,0,0,0,4
10+
9,Website,,website,/admin/latest-activity/website,home,,,,,,,1,0,8,8,4
11+
10,Admin,Admin,admin,/admin/latest-activity/admin,lock,,,,,,,2,0,8,8,4
12+
11,Testimonials,Testimonials,testimonials,/admin/general/testimonials,commenting-o,Info,List of all the testimonials on the website,How,Please complete the form to create the testimonial,How,Please complete the form to edit the selected testimonial,3,0,17,17,4
13+
12,Locations,,locations,/admin/general/locations,globe,,,,,,,4,0,17,17,4
14+
13,Countries,Countries,countries,/admin/general/locations/countries,map-marker,,,,,,,4,0,12,12,4
15+
14,Provinces,Provinces,provinces,/admin/general/locations/provinces,map-marker,,,,,,,3,0,12,12,4
16+
15,Cities,,cities,/admin/general/locations/cities,map-marker,,,,,,,2,0,12,12,4
17+
16,Suburbs,,suburbs,/admin/general/locations/suburbs,map-marker,,,,,,,1,0,12,12,4
18+
17,General,General Website,general,/admin/general,cubes,,,,,,,3,0,0,0,4
19+
18,Reports,,reports,/admin/reports,bar-chart,,,,,,,14,0,0,0,4
20+
19,Summary,,summary,/admin/reports/summary,align-left,,,,,,,1,0,18,18,4
21+
20,Contact Us,,contact-us,/admin/reports/contact-us,comments-o,,,,,,,2,0,18,18,4
22+
21,Settings,,settings,/admin/settings,cogs,,,,,,,15,0,0,0,4
23+
22,Subscription Plans,Subscription Plans,subscription-plans,/admin/settings/subscription-plans,money,,,,,,,5,0,21,21,4
24+
23,Features,Features,features,/admin/settings/subscription-plans/features,tags,,,,,,,1,1,22,22,4
25+
24,Pages,Pages,pages,/admin/pages,navicon,Help,All the menu items for the website.,Help,You can set the HTML Title and HTML Description.<br/>You can select the parent (under which navigation is this item).<br/>You can specify if the menu is hidden.,,,4,0,0,0,4
26+
25,Changelogs,,changelogs,/admin/settings/changelogs,file-text-o,,,,,,,3,0,21,21,4
27+
26,Navigation,,navigation,/admin/settings/navigation,align-center,Help,Helpfull text here - explaining what u can do here...,Information,Please complete the form to create the navigation,,,4,0,21,21,4
28+
27,Administrators,,administrators,/admin/accounts/administrators,users,,,,,,,2,0,58,58,4
29+
28,Admin Invites,,invites,/admin/accounts/administrators/invites,,,,,,,,1,1,27,27,4
30+
29,Profile,,profile,/admin/profile,user,,,,,,,16,1,0,0,4
31+
30,Navigation Order,Navigation Order,order,/admin/settings/navigation/order,list-ol,,,,,,,1,1,26,26,4
32+
31,Navigation Order,Navigation Order,order,/admin/pages/order,list-ol,,,,,,,1,1,24,24,4
33+
32,Banners,Banners,banners,/admin/general/banners,image,,,,,,,2,0,17,17,4
34+
33,Corporate,Corporate,corporate,/admin/corporate,bank,,,,,,,9,0,0,0,4
35+
34,Roles,Roles,roles,/admin/settings/roles,universal-access,,,,,,,1,0,21,21,4
36+
35,Tenders,Tenders,tenders,/admin/corporate/tenders,tags,,,,,,,1,0,33,33,4
37+
36,Blog,Blog,blog,/admin/blog,newspaper-o,,,,,,,7,0,0,0,4
38+
37,Articles,Articles,articles,/admin/blog/articles,newspaper-o,,,,,,,1,0,36,36,4
39+
38,Categories,Categories,categories,/admin/blog/categories,cubes,,,,,,,2,0,36,36,4
40+
39,Tags,Tags,tags,/admin/general/tags,tags,,,,,,,1,0,17,17,4
41+
40,FAQ,FAQ,faqs,/admin/faqs,question,,,,,,,10,0,0,0,4
42+
41,FAQ Questions,FAQ Questions,,/admin/faqs,question,,,,,,,2,0,40,40,4
43+
42,Categories,Categories,categories,/admin/faqs/categories,cubes,,,,,,,1,0,40,40,4
44+
43,Vacancies,Vacancies,vacancies,/admin/corporate/vacancies,vcard-o,,,,,,,2,0,33,33,4
45+
44,Annual Reports,Annual Reports,annual-reports,/admin/corporate/annual-reports,files-o,,,,,,,3,0,33,33,4
46+
45,News and Events,News and Events,news-and-events,/admin/news-and-events,newspaper-o,,,,,,,8,0,0,0,4
47+
46,News and Events,News and Events,news,/admin/news-and-events/news,newspaper-o,,,,,,,2,0,45,45,4
48+
47,Categories,Categories,categories,/admin/news-and-events/categories,cubes,,,,,,,1,0,45,45,4
49+
48,Gallery,Images,photos,/admin/photos,image,,,,,,,6,0,0,0,4
50+
49,Photos,Photos,,/admin/photos,image,,,,,,,2,0,48,48,4
51+
50,Albums,Albums,albums,/admin/photos/albums,cubes,,,,,,,1,0,48,48,4
52+
51,Settings,Settings,settings,/admin/settings/settings,cog,,,,,,,2,0,21,21,4
53+
52,Newsletter,Newsletter,newsletter,/admin/newsletter,newspaper-o,,,,,,,11,0,0,0,4
54+
53,Subscribers,Newsletter Subscribers,subscribers,/admin/newsletter/subscribers,users,,,,,,,1,0,52,52,4
55+
54,Clients,Clients,clients,/admin/accounts/clients,users,,,,,,,1,0,58,58,4
56+
55,Documents,Documents,documents,/admin/documents,files-o,,,,,,,12,0,0,0,4
57+
56,Categories,Categories,categories,/admin/documents/categories,cubes,,,,,,,1,0,55,55,4
58+
57,Documents,Documents,,/admin/documents,file-o,,,,,,,2,0,55,55,4
59+
58,Accounts,Accounts,accounts,/admin/accounts,users,,,,,,,5,0,0,0,4

0 commit comments

Comments
 (0)