diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 6675612..b1e3bdc 100644 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -366,14 +366,31 @@ final class ApiController extends Controller $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Account', 'Account successfully created', $account); } + /** + * Create profile for account + * + * @param Account $account Account to create profile for + * @param RequestAbstract $request Request + * + * @return void + * + * @api + * + * @since 1.0.0 + */ private function createProfileForAccount(Account $account, RequestAbstract $request) : void { if (((string) ($request->getData('password') ?? '')) !== '' && ((string) ($request->getData('login') ?? '')) !== '' ) { - $this->app->moduleManager->get('Profile')->apiProfileCreateDbEntry(new \Modules\Profile\Models\Profile($account), $request); + $old = clone $account; - $this->updateModel($request, $account, $account, function() use($account) : void { + $this->app->moduleManager->get('Profile')->apiProfileCreateDbEntry( + new \Modules\Profile\Models\Profile($account), + $request + ); + + $this->updateModel($request, $old, $account, function() use($account) : void { $account->setLoginTries((int) $this->app->appSettings->get(Settings::LOGIN_TRIES)); AccountMapper::update($account); }, 'account'); @@ -442,6 +459,11 @@ final class ApiController extends Controller $old = clone AccountMapper::get((int) $request->getData('id')); $new = $this->updateAccountFromRequest($request); $this->updateModel($request, $old, $new, AccountMapper::class, 'account'); + + if (\Modules\Profile\Models\ProfileMapper::getFor($new->getId(), 'account') instanceof \Modules\Profile\Models\NullProfile) { + $this->createProfileForAccount($new, $request); + } + $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Account', 'Account successfully updated', $new); } diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php index 4a02e7b..09a6826 100644 --- a/Theme/Backend/Lang/en.lang.php +++ b/Theme/Backend/Lang/en.lang.php @@ -31,6 +31,7 @@ return [ 'Component' => 'Component', 'Country' => 'Country', 'Create' => 'Create', + 'CreateProfile' => 'Create Profile', 'Created' => 'Created', 'CreatedBy' => 'Created By', 'Currency' => 'Currency', diff --git a/Theme/Backend/accounts-single.tpl.php b/Theme/Backend/accounts-single.tpl.php index a858eb6..a595c5f 100644 --- a/Theme/Backend/accounts-single.tpl.php +++ b/Theme/Backend/accounts-single.tpl.php @@ -32,7 +32,7 @@ echo $this->getData('nav')->render(); ?>
| - |
| + |