This commit is contained in:
Bozhidar 2024-05-12 21:42:24 +03:00
parent 8231c20ed4
commit d45a7829e6
2 changed files with 47 additions and 13 deletions

View file

@ -36,14 +36,28 @@ class HostingSubscriptionsController extends ApiController
], 400);
}
if (isset($request->system_username)) {
$findHostingSubscription = HostingSubscription::where('system_username', $request->system_username)->first();
if ($findHostingSubscription) {
return response()->json([
'status' => 'error',
'message' => 'System username already exists',
], 400);
}
}
$hostingSubscription = new HostingSubscription();
$hostingSubscription->customer_id = $request->customer_id;
$hostingSubscription->hosting_plan_id = $request->hosting_plan_id;
$hostingSubscription->domain = $request->domain;
// $hostingSubscription->username = $request->username;
// $hostingSubscription->password = $request->password;
// $hostingSubscription->description = $request->description;
if (isset($request->system_username)) {
$hostingSubscription->system_username = $request->system_username;
}
if (isset($request->system_password)) {
$hostingSubscription->system_password = $request->system_password;
}
$hostingSubscription->setup_date = Carbon::now();
$hostingSubscription->save();

View file

@ -46,6 +46,9 @@ class HostingSubscription extends Model
throw new \Exception('Domain already exists');
}
$create = $model->_createLinuxWebUser($model);
if (isset($create['error'])) {
throw new \Exception($create['message']);
}
if (isset($create['system_username']) && isset($create['system_password'])) {
$model->system_username = $create['system_username'];
$model->system_password = $create['system_password'];
@ -125,6 +128,19 @@ class HostingSubscription extends Model
return [];
}
if (!empty($model->system_username)) {
$getLinuxUser = new GetLinuxUser();
$getLinuxUser->setUsername($model->system_username);
$linuxUser = $getLinuxUser->handle();
if (!empty($linuxUser)) {
return [
'error' => true,
'message' => 'System username already exists.'
];
}
}
if (empty($model->system_username)) {
$systemUsername = $this->_generateUsername($model->domain . $findCustomer->id);
if ($this->_startsWithNumber($systemUsername)) {
$systemUsername = $this->_generateUsername(Str::random(4));
@ -134,11 +150,15 @@ class HostingSubscription extends Model
$getLinuxUser->setUsername($systemUsername);
$linuxUser = $getLinuxUser->handle();
if (! empty($linuxUser)) {
$systemUsername = $this->_generateUsername($systemUsername.$findCustomer->id.Str::random(4));
if (!empty($linuxUser)) {
$systemUsername = $this->_generateUsername($systemUsername . $findCustomer->id . Str::random(4));
}
$systemPassword = Str::random(14);
} else {
$systemUsername = $model->system_username;
$systemPassword = $model->system_password;
}
$createLinuxWebUser = new CreateLinuxWebUser();
$createLinuxWebUser->setUsername($systemUsername);