73 lines
2.0 KiB
PHP
73 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Repositories\Setting\SettingRepositoryInterface;
|
|
use Exception;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Http\Facade\SignRSA;
|
|
|
|
class SettingController extends Controller
|
|
{
|
|
|
|
public function __construct(
|
|
public SettingRepositoryInterface $settingRepository
|
|
)
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$title = 'General Setting';
|
|
|
|
return view('administrator.pagesetting', compact('title'));
|
|
}
|
|
|
|
public function smtp()
|
|
{
|
|
$title = 'SMTP Setting';
|
|
|
|
return view('administrator.pagesmtp', compact('title'));
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
DB::beginTransaction();
|
|
try {
|
|
foreach ($request->except(['_token', '_method']) as $key => $value) {
|
|
if (!empty($key)) {
|
|
if (is_array($value)) {
|
|
$value = json_encode($value);
|
|
}
|
|
|
|
// Nếu key là smtp -> kiểm tra và mã hoá password nếu có
|
|
if ($key === 'smtp') {
|
|
$decoded = is_array($value) ? $value : json_decode($value, true);
|
|
|
|
if (isset($decoded['password']) && !empty($decoded['password'])) {
|
|
$decoded['password'] = SignRSA::EncryptFunc($decoded['password']);
|
|
}
|
|
|
|
$value = json_encode($decoded);
|
|
}
|
|
|
|
$this->settingRepository->updateOrCreateByKey($key, [
|
|
'key' => $key,
|
|
'value' => $value
|
|
]);
|
|
}
|
|
}
|
|
|
|
DB::commit();
|
|
} catch (Exception $error) {
|
|
DB::rollBack();
|
|
return back()->withErrors($error->getMessage());
|
|
}
|
|
|
|
return back()->with('success', 'Updated Successfully');
|
|
}
|
|
}
|