Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
webprofile-jwg2024
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Siti Aisah
webprofile-jwg2024
Commits
4a247b2b
Commit
4a247b2b
authored
Jan 29, 2020
by
Aan Choesni Herlingga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
login user berdasarkan role
parent
9058c99a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
2 deletions
+55
-2
app/Http/Kernel.php
+1
-0
app/Http/Middleware/Role.php
+48
-0
database/migrations/2014_10_12_000000_create_users_table.php
+2
-0
database/seeds/UsersTableSeeder.php
+2
-0
routes/webprofile/backend.php
+2
-2
No files found.
app/Http/Kernel.php
View file @
4a247b2b
...
@@ -61,6 +61,7 @@ class Kernel extends HttpKernel
...
@@ -61,6 +61,7 @@ class Kernel extends HttpKernel
'signed'
=>
\Illuminate\Routing\Middleware\ValidateSignature
::
class
,
'signed'
=>
\Illuminate\Routing\Middleware\ValidateSignature
::
class
,
'throttle'
=>
\Illuminate\Routing\Middleware\ThrottleRequests
::
class
,
'throttle'
=>
\Illuminate\Routing\Middleware\ThrottleRequests
::
class
,
'verified'
=>
\Illuminate\Auth\Middleware\EnsureEmailIsVerified
::
class
,
'verified'
=>
\Illuminate\Auth\Middleware\EnsureEmailIsVerified
::
class
,
'role'
=>
\App\Http\Middleware\Role
::
class
,
];
];
/**
/**
...
...
app/Http/Middleware/Role.php
0 → 100644
View file @
4a247b2b
<?php
namespace
App\Http\Middleware
;
use
Illuminate\Http\Request
;
use
Closure
;
class
Role
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public
function
__construct
(
Request
$request
)
{
$this
->
req
=
$request
;
}
public
function
handle
(
$request
,
Closure
$next
,
$role
)
{
if
(
!
auth
()
->
user
())
{
return
redirect
()
->
route
(
'login'
);
}
if
(
auth
()
->
user
()
->
is_active
!=
1
)
{
auth
()
->
logout
();
return
redirect
()
->
route
(
'login'
);
}
$roles
=
explode
(
'|'
,
$role
);
$accessPage
=
0
;
foreach
(
$roles
as
$r
)
{
if
(
auth
()
->
user
()
->
role
==
$r
)
{
$accessPage
=
1
;
}
}
if
(
$accessPage
==
1
)
{
return
$next
(
$request
);
}
return
redirect
(
'home'
);
}
}
database/migrations/2014_10_12_000000_create_users_table.php
View file @
4a247b2b
...
@@ -19,6 +19,8 @@ class CreateUsersTable extends Migration
...
@@ -19,6 +19,8 @@ class CreateUsersTable extends Migration
$table
->
string
(
'email'
)
->
unique
();
$table
->
string
(
'email'
)
->
unique
();
$table
->
timestamp
(
'email_verified_at'
)
->
nullable
();
$table
->
timestamp
(
'email_verified_at'
)
->
nullable
();
$table
->
string
(
'password'
);
$table
->
string
(
'password'
);
$table
->
string
(
'role'
,
100
);
$table
->
string
(
'is_active'
,
100
);
$table
->
rememberToken
();
$table
->
rememberToken
();
$table
->
timestamps
();
$table
->
timestamps
();
});
});
...
...
database/seeds/UsersTableSeeder.php
View file @
4a247b2b
...
@@ -21,6 +21,8 @@ class UsersTableSeeder extends Seeder
...
@@ -21,6 +21,8 @@ class UsersTableSeeder extends Seeder
'email_verified_at'
=>
null
,
'email_verified_at'
=>
null
,
'password'
=>
Hash
::
make
(
'anchuz2020'
),
'password'
=>
Hash
::
make
(
'anchuz2020'
),
'remember_token'
=>
null
,
'remember_token'
=>
null
,
'role'
=>
'admin'
,
'is_active'
=>
1
,
]);
]);
}
}
}
}
routes/webprofile/backend.php
View file @
4a247b2b
<?php
<?php
Route
::
group
([
'middleware'
=>
'auth'
],
function
()
{
Route
::
group
([
'middleware'
=>
'auth'
],
function
()
{
// Route::group(['middleware' => 'role:admin
'], function () {
Route
::
group
([
'middleware'
=>
'role:admin|editor
'
],
function
()
{
Route
::
group
([
'namespace'
=>
'Webprofile\Backend'
,
'prefix'
=>
'webprofile'
],
function
()
{
Route
::
group
([
'namespace'
=>
'Webprofile\Backend'
,
'prefix'
=>
'webprofile'
],
function
()
{
Route
::
resource
(
'category'
,
'CategoryController'
);
Route
::
resource
(
'category'
,
'CategoryController'
);
Route
::
resource
(
'posts'
,
'PostController'
);
Route
::
resource
(
'posts'
,
'PostController'
);
...
@@ -18,5 +18,5 @@ Route::group(['middleware' => 'auth'], function () {
...
@@ -18,5 +18,5 @@ Route::group(['middleware' => 'auth'], function () {
Route
::
get
(
'menu_up/{id}'
,
'MenuController@menu_up'
)
->
name
(
'menu_up'
);
Route
::
get
(
'menu_up/{id}'
,
'MenuController@menu_up'
)
->
name
(
'menu_up'
);
Route
::
get
(
'menu_down/{id}'
,
'MenuController@menu_down'
)
->
name
(
'menu_down'
);
Route
::
get
(
'menu_down/{id}'
,
'MenuController@menu_down'
)
->
name
(
'menu_down'
);
});
});
//
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment