update
This commit is contained in:
@@ -324,6 +324,64 @@ class CustomerController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function sendPasswordEmail(Request $request, string $uuid): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'password' => 'required|string|min:8|max:64',
|
||||
]);
|
||||
|
||||
$customer = $this->customerRepository->findBy('uuid', $uuid);
|
||||
|
||||
if (!$customer) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => "Can't find customer by UUID #" . $uuid,
|
||||
], 404);
|
||||
}
|
||||
|
||||
$password = (string) $request->input('password');
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$this->customerRepository->update($customer->id, [
|
||||
'password' => Hash::make($password),
|
||||
]);
|
||||
|
||||
\Illuminate\Support\Facades\Mail::to($customer->email)->send(
|
||||
new \App\Mail\Customer\PasswordResetByAdmin([
|
||||
'fullname' => $customer->fullname,
|
||||
'email' => $customer->email,
|
||||
'password' => $password,
|
||||
])
|
||||
);
|
||||
|
||||
Log::create([
|
||||
'agent' => 'admin',
|
||||
'client_ip' => $request->ip(),
|
||||
'description' => sprintf(
|
||||
'Admin gửi lại mật khẩu mới cho customer %s',
|
||||
$customer->email,
|
||||
),
|
||||
'customer_id' => $customer->id,
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Đã gửi mật khẩu mới cho khách hàng.',
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => $e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function addCredit(Request $request, string $uuid): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
@@ -562,6 +620,82 @@ class CustomerController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function getDnsDomains(string $uuid): JsonResponse
|
||||
{
|
||||
$customer = $this->customerRepository->findBy('uuid', $uuid);
|
||||
|
||||
if (!$customer) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => "Can't find customer by UUID #" . $uuid,
|
||||
], 404);
|
||||
}
|
||||
|
||||
$domains = \App\Models\DnsDomain::query()
|
||||
->with('server:id,name,ip_address')
|
||||
->withCount(['ns', 'record'])
|
||||
->whereHas('customer', fn ($q) => $q->where('customers.id', $customer->id))
|
||||
->orderByDesc('id')
|
||||
->get()
|
||||
->map(function ($d) {
|
||||
return [
|
||||
'id' => $d->id,
|
||||
'domain_name' => $d->domain_name,
|
||||
'is_created' => (int) $d->is_created,
|
||||
'plesk_id' => $d->plesk_id,
|
||||
'ns_count' => (int) ($d->ns_count ?? 0),
|
||||
'record_count' => (int) ($d->record_count ?? 0),
|
||||
'server' => $d->server ? [
|
||||
'id' => $d->server->id,
|
||||
'name' => $d->server->name,
|
||||
'ip_address' => $d->server->ip_address,
|
||||
] : null,
|
||||
'created_at' => $d->created_at,
|
||||
'updated_at' => $d->updated_at,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => $domains,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getDnsDomainRecords(string $uuid, int $domainId): JsonResponse
|
||||
{
|
||||
$customer = $this->customerRepository->findBy('uuid', $uuid);
|
||||
|
||||
if (!$customer) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => "Can't find customer by UUID #" . $uuid,
|
||||
], 404);
|
||||
}
|
||||
|
||||
$owns = \Illuminate\Support\Facades\DB::table('dns_domain_user')
|
||||
->where('domain_id', $domainId)
|
||||
->where('user_id', $customer->id)
|
||||
->exists();
|
||||
|
||||
if (!$owns) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => 'Domain không thuộc về khách hàng này',
|
||||
], 403);
|
||||
}
|
||||
|
||||
$records = \App\Models\DnsRecord::query()
|
||||
->where('dns_manager_domain_id', $domainId)
|
||||
->orderBy('type')
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => $records,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getServices(string $uuid, Request $request): JsonResponse
|
||||
{
|
||||
$services = $this->serviceRepository->filter(
|
||||
|
||||
Reference in New Issue
Block a user