Skip to content

Commit

Permalink
Merge pull request #2 from ntd1683/UI-Admin
Browse files Browse the repository at this point in the history
Recaptcha + Profile
  • Loading branch information
ntd1683 authored Dec 12, 2023
2 parents 1d33130 + cc3eeba commit f065ceb
Show file tree
Hide file tree
Showing 47 changed files with 1,437 additions and 287 deletions.
50 changes: 50 additions & 0 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
<?php

use App\Http\Services\Admin\SettingService;

if (!function_exists('option')) {
function option($name, $default = '')
{
$settingService = new SettingService();
$value = $settingService->getValueByKey($name);

if ($value == null) {
return $default;
}

return $value;
}

if (!function_exists('getNameRouteMain')) {
function getNameRouteMain(): string
{
$arrRouteName = explode('.', request()->route()->getName());

$result = $arrRouteName[0];
if($arrRouteName[0] == 'admin') {
$result = $arrRouteName[1];
}

return $result == "index" ? "" : $result;
}
}

if (!function_exists('getSubtitle')) {
function getSubtitle(): string
{
$result = getNameRouteMain();

return $result == "" ? "" : ' - '. ucfirst($result);
}
}

if (!function_exists('getImageFromStorage')) {
function getImageFromStorage($value, $url): string
{
if ($value == '' || $value == null) {
return asset($url);
}

return Storage::url($value);
}
}
}
12 changes: 6 additions & 6 deletions app/Http/Controllers/Admin/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@

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

class AuthController extends Controller
{
Protected AuthServices $authServices;
Protected AuthService $authServices;

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

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

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

public function processLogin(LoginRequest $request)
public function processLogin(LoginRequest $request): RedirectResponse
{
$data = $request->validated();
$remember = $request->has('remember');
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Admin/HomepageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace App\Http\Controllers\Admin;

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

class HomepageController extends Controller
{
public function __invoke()
public function __invoke() : View
{
return view('admin.index');
}
Expand Down
65 changes: 0 additions & 65 deletions app/Http/Controllers/Admin/OptionController.php

This file was deleted.

40 changes: 40 additions & 0 deletions app/Http/Controllers/Admin/SettingController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\admin\SettingRequest;
use App\Http\Services\Admin\SettingService;
use Illuminate\View\View;

class SettingController extends Controller
{
protected SettingService $settingService;

public function __construct()
{
$this->settingService = new SettingService();
}
/**
* Display a listing of the resource.
*/
public function index(): View
{
return view("admin.setting");
}

/**
* Save the form for editing the specified resource.
*/
public function save(SettingRequest $request)
{
$data = $request->validated();
$result = $this->settingService->save($data);

if ($result)
return redirect()
->route("admin.index")
->with("success", trans("Update Successfully"));
return redirect()->back()->withErrors("Update Failed");
}
}
39 changes: 39 additions & 0 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests\admin\ProfileRequest;
use App\Http\Services\Admin\ProfileService;
use Illuminate\Http\Request;
use Illuminate\View\View;

class ProfileController extends Controller
{
protected ProfileService $profileService;

public function __construct()
{
$this->profileService = new ProfileService();
}

public function index(): View
{
$user = auth()->user();
return view("admin.profile", compact("user"));
}

public function save(ProfileRequest $request)
{
$data = $request->validated();

$result = $this->profileService->save($data);

if ($result)
return redirect()
->route("admin.index")
->with("success", trans("Update Successfully"));
$errors = session("errors");
$errors[] = "Update Failed";
return redirect()->back()->withErrors($errors);
}
}
3 changes: 2 additions & 1 deletion app/Http/Controllers/User/HomepageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace App\Http\Controllers\User;

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

class HomepageController extends Controller
{
public function __invoke()
public function __invoke(): View
{
return view('index');
}
Expand Down
24 changes: 24 additions & 0 deletions app/Http/Middleware/CheckAdminMiddleware.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 CheckAdminMiddleware
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (Auth::guest() || Auth::user()->level !== 4)
return redirect()->route('admin.login')->withErrors('You must login account admin to continue');

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

namespace App\Http\Repositories\Admin;


use App\Models\User;
use function Laravel\Prompts\password;

class ProfileRepository
{
protected User $user;

public function __construct()
{
$this->user = new User();
}

public function save(array $data): bool
{
try {
$user = $this->user::query()
->updateOrCreate([
"email" => auth()->user()->email,
], $data);

$user->save();
return true;
} catch (\Exception $e) {
return false;
}
}
}
43 changes: 43 additions & 0 deletions app/Http/Repositories/Admin/SettingRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Http\Repositories\Admin;

use App\Models\Option;
use Illuminate\Database\Eloquent\Builder;

class SettingRepository
{
protected Option $option;

public function __construct()
{
$this->option = new Option();
}

/**
* @param string $key
* @return Builder|Option
*/
public function getSetting(string $key): Builder|Option
{
return $this->option::query()
->where('name', $key)->firstOrFail();
}

public function save(string $key, string $value = null): bool
{
try {
$option = $this->option::query()
->updateOrCreate([
"name" => $key
], [
"value" => $value
]);

$option->save();
return true;
} catch (\Exception $e) {
return false;
}
}
}
Loading

0 comments on commit f065ceb

Please sign in to comment.