Skip to content

Commit

Permalink
Merge pull request #1 from ntd1683/UI-User
Browse files Browse the repository at this point in the history
UI user
  • Loading branch information
ntd1683 authored Dec 5, 2023
2 parents 481fe7c + 400150a commit 1d33130
Show file tree
Hide file tree
Showing 91 changed files with 5,064 additions and 26 deletions.
4 changes: 4 additions & 0 deletions app/Enums/UserLevelEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ final class UserLevelEnum extends AbstractEnum
public const CHEF = 2;
public const MANAGER = 3;

public const ADMIN = 4;

public static function getArrayView(): array
{
return [
'Staff' => self::STAFF,
'Cashier' => self::CASHIER,
'Chef' => self::CHEF,
'Manager' => self::MANAGER,
'Admin' => self::ADMIN,
];
}

Expand All @@ -26,6 +29,7 @@ public static function getArrayViewVN(): array
'Thu Ngân' => self::CASHIER,
'Đầu Bếp' => self::CHEF,
'Quản Lý' => self::MANAGER,
'Quản Trị Viên' => self::ADMIN,
];
}
}
1 change: 1 addition & 0 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
46 changes: 46 additions & 0 deletions app/Http/Controllers/Admin/AuthController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\LoginRequest;
use App\Http\Services\Admin\AuthServices;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;

class AuthController extends Controller
{
Protected AuthServices $authServices;

public function __construct()
{
$this->authServices = new AuthServices();
}

public function login() : View
{
return view('admin.auth.login');
}

public function logout()
{
Auth::logout();
return redirect()
->route('admin.login')
->with('success', trans("Logout Successfully"));
}

public function processLogin(LoginRequest $request)
{
$data = $request->validated();
$remember = $request->has('remember');

$result = $this->authServices->login($data['email'], $data['password'], $remember);
if ($result)
return redirect()->route('admin.index')->with("success", trans("Login Successfully"));

return redirect()->back()->withErrors(trans("Unknown error please try again"));
}
}
13 changes: 13 additions & 0 deletions app/Http/Controllers/Admin/HomepageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;

class HomepageController extends Controller
{
public function __invoke()
{
return view('admin.index');
}
}
65 changes: 65 additions & 0 deletions app/Http/Controllers/Admin/OptionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class OptionController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}

/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}

/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}
13 changes: 13 additions & 0 deletions app/Http/Controllers/User/HomepageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;

class HomepageController extends Controller
{
public function __invoke()
{
return view('index');
}
}
14 changes: 14 additions & 0 deletions app/Http/Controllers/User/OrderController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class OrderController extends Controller
{
public function cart()
{
return view('products.cart');
}
}
9 changes: 9 additions & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ class Kernel extends HttpKernel
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],

'admin' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],

'api' => [
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
Expand Down
24 changes: 24 additions & 0 deletions app/Http/Middleware/CheckLogoutMiddleware.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;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;

class CheckLogoutMiddleware
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (Auth::check())
return redirect()->route("index")->withErrors("You are already logged in!");

return $next($request);
}
}
24 changes: 24 additions & 0 deletions app/Http/Middleware/CheckStaffMiddleware.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;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;

class CheckStaffMiddleware
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (! Auth::check())
return redirect()->route('admin.login')->withErrors('You must login to continue');

return $next($request);
}
}
42 changes: 42 additions & 0 deletions app/Http/Requests/Auth/LoginRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Http\Requests\Auth;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;

class LoginRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return ! Auth::check();
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'email' => ["required", "email"],
'password' => ["required", "string", "min:4", "max:32"],
'remember' => ["nullable"],
];
}

public function messages(): array
{
return [
"required" => trans("Not be empty"),
"email" => trans("Unknown error please try again"),
"string" => trans("Unknown error please try again"),
"min:4" => trans("Fields must be more than 4 characters"),
"max:32" => trans("Fields must be less than 32 characters"),
];
}
}
29 changes: 29 additions & 0 deletions app/Http/Services/Admin/AuthServices.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Http\Services\Admin;

use App\Models\User;
use Illuminate\Support\Facades\Auth;

class AuthServices {

public function login(string $email, string $password, bool $remember): bool
{
if (Auth::attempt(["email" => $email, "password" => $password], $remember))
{
try {
$user = User::query()
->where('email', $email)
->firstOrFail();

Auth::login($user, $remember);

return true;
} catch (\Exception $e) {
return false;
}
}

return false;
}
}
18 changes: 18 additions & 0 deletions app/Models/Option.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Option extends Model
{
use HasFactory;

public $timestamps = true;

protected $fillable = [
'name',
'value',
];
}
5 changes: 5 additions & 0 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public function boot(): void

Route::middleware('web')
->group(base_path('routes/web.php'));

Route::middleware('admin')
->prefix('admin')
->name('admin.')
->group(base_path('routes/admin.php'));
});
}
}
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"require": {
"php": "^8.1",
"bensampo/laravel-enum": "^6.7",
"diglactic/laravel-breadcrumbs": "^8.1",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.3",
Expand All @@ -22,6 +23,9 @@
"spatie/laravel-ignition": "^2.0"
},
"autoload": {
"files": [
"app/Helpers/Helper.php"
],
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
Expand Down
Loading

0 comments on commit 1d33130

Please sign in to comment.