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); ], 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 = new HostingSubscription();
$hostingSubscription->customer_id = $request->customer_id; $hostingSubscription->customer_id = $request->customer_id;
$hostingSubscription->hosting_plan_id = $request->hosting_plan_id; $hostingSubscription->hosting_plan_id = $request->hosting_plan_id;
$hostingSubscription->domain = $request->domain; $hostingSubscription->domain = $request->domain;
// $hostingSubscription->username = $request->username; if (isset($request->system_username)) {
// $hostingSubscription->password = $request->password; $hostingSubscription->system_username = $request->system_username;
// $hostingSubscription->description = $request->description; }
if (isset($request->system_password)) {
$hostingSubscription->system_password = $request->system_password;
}
$hostingSubscription->setup_date = Carbon::now(); $hostingSubscription->setup_date = Carbon::now();
$hostingSubscription->save(); $hostingSubscription->save();

View file

@ -46,6 +46,9 @@ class HostingSubscription extends Model
throw new \Exception('Domain already exists'); throw new \Exception('Domain already exists');
} }
$create = $model->_createLinuxWebUser($model); $create = $model->_createLinuxWebUser($model);
if (isset($create['error'])) {
throw new \Exception($create['message']);
}
if (isset($create['system_username']) && isset($create['system_password'])) { if (isset($create['system_username']) && isset($create['system_password'])) {
$model->system_username = $create['system_username']; $model->system_username = $create['system_username'];
$model->system_password = $create['system_password']; $model->system_password = $create['system_password'];
@ -125,6 +128,19 @@ class HostingSubscription extends Model
return []; 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); $systemUsername = $this->_generateUsername($model->domain . $findCustomer->id);
if ($this->_startsWithNumber($systemUsername)) { if ($this->_startsWithNumber($systemUsername)) {
$systemUsername = $this->_generateUsername(Str::random(4)); $systemUsername = $this->_generateUsername(Str::random(4));
@ -139,6 +155,10 @@ class HostingSubscription extends Model
} }
$systemPassword = Str::random(14); $systemPassword = Str::random(14);
} else {
$systemUsername = $model->system_username;
$systemPassword = $model->system_password;
}
$createLinuxWebUser = new CreateLinuxWebUser(); $createLinuxWebUser = new CreateLinuxWebUser();
$createLinuxWebUser->setUsername($systemUsername); $createLinuxWebUser->setUsername($systemUsername);