Skip to content

Commit

Permalink
Middleware admin si implementare roluri. Design pagina de welcome inc…
Browse files Browse the repository at this point in the history
…eput
  • Loading branch information
brobert04 committed Dec 14, 2022
1 parent dcb6b42 commit 5658c98
Show file tree
Hide file tree
Showing 15 changed files with 11,833 additions and 133 deletions.
2 changes: 1 addition & 1 deletion _template/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="row justify-content-center">
<div class="col-lg-6">
<div class="text-center mt-4">
<img class="mb-4 img-error" src="../public/admin/assets/img/error-404-monochrome.svg" />
<img class="mb-4 img-error" src="../public/img/error-404-monochrome.svg" />
<p class="lead">This requested URL was not found on this server.</p>
<a href="index.html">
<i class="fas fa-arrow-left me-1"></i>
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/Admin/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

class UsersController extends Controller
{
public function __construct(){
$this->middleware('admin');
}
public function showUsers(){
$users = User::all()->sortBy('name');
return view('admin.users')->with('users', $users);
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Kernel extends HttpKernel
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,

];

/**
Expand Down Expand Up @@ -63,5 +64,6 @@ class Kernel extends HttpKernel
'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'admin' => \App\Http\Middleware\IsAdmin::class,
];
}
24 changes: 24 additions & 0 deletions app/Http/Middleware/IsAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class IsAdmin
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
{
if(auth()->user() && auth()->user()->role=="admin"){
return $next($request);
}
return redirect('dashboard');
}
}
4 changes: 4 additions & 0 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public function definition()
'email_verified_at' => now(),
'password' => bcrypt('password'), // password
'remember_token' => Str::random(10),
'phone' => fake()->e164PhoneNumber(),
'address' => fake()->city().', '.fake()->streetAddress().', '.fake()->country(),
'created_at' => fake()->dateTimeBetween('-2 year', 'now'),
'role' => fake()->randomElement(['editor', 'autor ']),
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('role')->default('editor')->nullable();
$table->string('profile_picture')->default('default.png')->nullable();
$table->string('phone')->nullable();
$table->string('address')->nullable();

});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('Users', function (Blueprint $table) {
$table->dropColumn('role');
$table->dropColumn('profile_picture');
$table->dropColumn('phone');
$table->dropColumn('address');
});
}
};
9 changes: 9 additions & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Database\Seeders;

// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use App\Models\User;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
Expand All @@ -15,6 +16,14 @@ class DatabaseSeeder extends Seeder
public function run()
{
\App\Models\User::factory(100)->create();
User::create([
'name' => 'Administrator',
'email' => '[email protected]',
'password'=>bcrypt('password'),
'phone' => '+40734124908',
'address' => 'Bucuresti',
'role' => 'admin'
]);

// \App\Models\User::factory()->create([
// 'name' => 'Test User',
Expand Down
1 change: 0 additions & 1 deletion public/admin/assets/img/error-404-monochrome.svg

This file was deleted.

Loading

0 comments on commit 5658c98

Please sign in to comment.