-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ntd1683/UI-Admin
Recaptcha + Profile
- Loading branch information
Showing
47 changed files
with
1,437 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.