diff --git a/Admin/Install/Navigation.install.json b/Admin/Install/Navigation.install.json index 1590191..c921fde 100755 --- a/Admin/Install/Navigation.install.json +++ b/Admin/Install/Navigation.install.json @@ -18,7 +18,7 @@ "pid": "/", "type": 2, "subtype": 1, - "name": "General", + "name": "Settings", "uri": "{/prefix}admin/settings/general?{?}", "target": "self", "icon": null, diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 850cb97..c6184f8 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -584,7 +584,7 @@ }, "group_permission_from": { "name": "group_permission_from", - "type": "INT", + "type": "VARCHAR(255)", "default": null, "null": true }, @@ -781,7 +781,7 @@ }, "account_permission_from": { "name": "account_permission_from", - "type": "INT", + "type": "VARCHAR(255)", "default": null, "null": true }, diff --git a/Admin/Routes/Web/Api.php b/Admin/Routes/Web/Api.php index 8098bac..e850aba 100755 --- a/Admin/Routes/Web/Api.php +++ b/Admin/Routes/Web/Api.php @@ -170,7 +170,7 @@ return [ 'dest' => '\Modules\Admin\Controller\ApiController:apiSettingsAccountLocalizationSet', 'verb' => RouteVerb::SET, 'permission' => [ - 'module' => AdminApiController::MODULE_NAME, + 'module' => ApiController::MODULE_NAME, 'type' => PermissionType::MODIFY, 'state' => PermissionState::ACCOUNT_SETTINGS, ], diff --git a/Controller/ApiController.php b/Controller/ApiController.php index e409760..8737f4f 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -55,8 +55,13 @@ use phpOMS\System\File\Local\File; use phpOMS\System\MimeType; use phpOMS\Uri\HttpUri; use phpOMS\Utils\Parser\Markdown\Markdown; -use phpOMS\Validation\Network\Email; +use phpOMS\Validation\Network\Email as EmailValidator; use phpOMS\Version\Version; +use phpOMS\Message\Mail\Email; +use phpOMS\Message\Mail\Imap; +use phpOMS\Message\Mail\MailHandler; +use phpOMS\Message\Mail\SubmitType; +use phpOMS\System\CharsetType; /** * Admin controller class. @@ -131,7 +136,7 @@ final class ApiController extends Controller } /** - * Api method to login + * Api method to send forgotten password email * * @param RequestAbstract $request Request * @param ResponseAbstract $response Response @@ -145,6 +150,65 @@ final class ApiController extends Controller */ public function apiForgot(RequestAbstract $request, ResponseAbstract $response, $data = null) : void { + $account = AccountMapper::getBy((string) $request->getData('login'), 'login'); + + $forgotten = $this->app->appSettings->get( + null, + ['forgott_date', 'forgrott_count'], + self::MODULE_NAME, + null, + $account->getId() + ); + + if ((int) $forgotten['forgrotten_count'] > 3) { + $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); + $response->set($request->uri->__toString(), [ + 'status' => NotificationLevel::ERROR, + 'title' => 'Password Reset', + 'message' => 'Password reset failed due to invalid login data or too many reset attemps.', + 'response' => null, + ]); + } + + $handler = new MailHandler(); + $handler->setMailer(SubmitType::MAIL); + + $mail = new Email(); + $mail->setFrom('test1@orange-management.email', 'Orange-Management'); + $mail->addTo($account->email, \trim($account->name1 . ' ' . $account->name2 . ' ' . $account->name3)); + $mail->subject = 'Orange Management: Forgot Password'; + $mail->body = 'Please reset your password at: .....'; + + $this->app->appSettings->set([ + ['name' => 'forgott_date', 'module' => self::MODULE_NAME, 'account' => $account->getId(), 'content' => (string) \time()], + ['name' => 'forgotten_count', 'module' => self::MODULE_NAME, 'account' => $account->getId(), 'content' => (string) (((int) $forgotten['forgrotten_count']) + 1)], + ], true); + + $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); + $response->set($request->uri->__toString(), [ + 'status' => NotificationLevel::OK, + 'title' => 'Password Reset', + 'message' => 'You received a pasword reset email.', + 'response' => null, + ]); + } + + /** + * Api method to reset the password + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiResetPassword(RequestAbstract $request, ResponseAbstract $response, $data = null) : void + { + // @todo: implement } /** @@ -707,7 +771,7 @@ final class ApiController extends Controller if (($val['name1'] = empty($request->getData('name1'))) || ($val['type'] = !AccountType::isValidValue((int) $request->getData('type'))) || ($val['status'] = !AccountStatus::isValidValue((int) $request->getData('status'))) - || ($val['email'] = !empty($request->getData('email')) && !Email::isValid((string) $request->getData('email'))) + || ($val['email'] = !empty($request->getData('email')) && !EmailValidator::isValid((string) $request->getData('email'))) ) { return $val; } diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 7dedbb4..a39b7f2 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -31,6 +31,7 @@ use phpOMS\Message\ResponseAbstract; use phpOMS\Module\ModuleInfo; use phpOMS\Utils\StringUtils; use phpOMS\Views\View; +use Model\SettingMapper; /** * Admin controller class. @@ -78,15 +79,18 @@ final class BackendController extends Controller public function viewSettingsGeneral(RequestAbstract $request, ResponseAbstract $response, $data = null) : RenderableInterface { $view = new View($this->app->l11nManager, $request, $response); - $settings = $this->app->appSettings->get(null, [ + $generalSettings = $this->app->appSettings->get(null, [ SettingsEnum::PASSWORD_PATTERN, SettingsEnum::LOGIN_TIMEOUT, SettingsEnum::PASSWORD_INTERVAL, SettingsEnum::PASSWORD_HISTORY, SettingsEnum::LOGIN_TRIES, SettingsEnum::LOGGING_STATUS, SettingsEnum::LOGGING_PATH, SettingsEnum::DEFAULT_ORGANIZATION, SettingsEnum::LOGIN_STATUS, SettingsEnum::DEFAULT_LOCALIZATION, SettingsEnum::ADMIN_MAIL, ]); $view->setTemplate('/Modules/Admin/Theme/Backend/settings-general'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000104001, $request, $response)); - $view->setData('settings', $settings); - $view->setData('defaultlocalization', LocalizationMapper::get((int) $settings[SettingsEnum::DEFAULT_LOCALIZATION])); + $view->setData('generalSettings', $generalSettings); + $view->setData('defaultlocalization', LocalizationMapper::get((int) $generalSettings[SettingsEnum::DEFAULT_LOCALIZATION])); + $view->setData('settings', SettingMapper::getAll()); + + return $view; } diff --git a/Models/AccountPermission.php b/Models/AccountPermission.php index 9de596c..e6b5074 100755 --- a/Models/AccountPermission.php +++ b/Models/AccountPermission.php @@ -44,7 +44,7 @@ class AccountPermission extends PermissionAbstract * @param null|int $unit Unit Unit to check (null if all are acceptable) * @param null|string $app App App to check (null if all are acceptable) * @param null|string $module Module to check (null if all are acceptable) - * @param int $from Module providing this permission + * @param null|string $from Module providing this permission * @param null|int $type Type (e.g. customer) (null if all are acceptable) * @param null|int $element (e.g. customer id) (null if all are acceptable) * @param null|int $component (e.g. address) (null if all are acceptable) @@ -57,7 +57,7 @@ class AccountPermission extends PermissionAbstract int $unit = null, string $app = null, string $module = null, - int $from = 0, + string $from = null, int $type = null, int $element = null, int $component = null, diff --git a/Models/AccountPermissionMapper.php b/Models/AccountPermissionMapper.php index ea0b888..e9c57a8 100755 --- a/Models/AccountPermissionMapper.php +++ b/Models/AccountPermissionMapper.php @@ -38,7 +38,7 @@ final class AccountPermissionMapper extends DataMapperAbstract 'account_permission_unit' => ['name' => 'account_permission_unit', 'type' => 'int', 'internal' => 'unit'], 'account_permission_app' => ['name' => 'account_permission_app', 'type' => 'string', 'internal' => 'app'], 'account_permission_module' => ['name' => 'account_permission_module', 'type' => 'string', 'internal' => 'module'], - 'account_permission_from' => ['name' => 'account_permission_from', 'type' => 'int', 'internal' => 'from'], + 'account_permission_from' => ['name' => 'account_permission_from', 'type' => 'string', 'internal' => 'from'], 'account_permission_type' => ['name' => 'account_permission_type', 'type' => 'int', 'internal' => 'type'], 'account_permission_element' => ['name' => 'account_permission_element', 'type' => 'int', 'internal' => 'element'], 'account_permission_component' => ['name' => 'account_permission_component', 'type' => 'int', 'internal' => 'component'], diff --git a/Models/Address.php b/Models/Address.php index 622944b..385c307 100755 --- a/Models/Address.php +++ b/Models/Address.php @@ -41,4 +41,46 @@ class Address extends Location * @since 1.0.0 */ public string $addition = ''; + + /** + * {@inheritdoc} + */ + public function toArray() : array + { + $data = parent::toArray(); + + $data['name'] = $this->name; + $data['addition'] = $this->addition; + + return $data; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } + + /** + * {@inheritdoc} + */ + public function serialize() : string + { + return (string) \json_encode($this->jsonSerialize()); + } + + /** + * {@inheritdoc} + */ + public function unserialize($serialized) : void + { + parent::unserialize($serialized); + + $data = \json_decode($serialized, true); + + $this->name = $data['name']; + $this->addition = $data['addition']; + } } diff --git a/Models/GroupPermission.php b/Models/GroupPermission.php index 37ac851..775b368 100755 --- a/Models/GroupPermission.php +++ b/Models/GroupPermission.php @@ -44,7 +44,7 @@ class GroupPermission extends PermissionAbstract * @param null|int $unit Unit Unit to check (null if all are acceptable) * @param null|string $app App App to check (null if all are acceptable) * @param null|string $module Module to check (null if all are acceptable) - * @param int $from Module providing this permission + * @param null|string $from Module providing this permission * @param null|int $type Type (e.g. customer) (null if all are acceptable) * @param null|int $element (e.g. customer id) (null if all are acceptable) * @param null|int $component (e.g. address) (null if all are acceptable) @@ -57,7 +57,7 @@ class GroupPermission extends PermissionAbstract int $unit = null, string $app = null, string $module = null, - int $from = 0, + string $from = null, int $type = null, int $element = null, int $component = null, diff --git a/Models/GroupPermissionMapper.php b/Models/GroupPermissionMapper.php index 408fc14..bcc6131 100755 --- a/Models/GroupPermissionMapper.php +++ b/Models/GroupPermissionMapper.php @@ -38,7 +38,7 @@ final class GroupPermissionMapper extends DataMapperAbstract 'group_permission_unit' => ['name' => 'group_permission_unit', 'type' => 'int', 'internal' => 'unit'], 'group_permission_app' => ['name' => 'group_permission_app', 'type' => 'string', 'internal' => 'app'], 'group_permission_module' => ['name' => 'group_permission_module', 'type' => 'string', 'internal' => 'module'], - 'group_permission_from' => ['name' => 'group_permission_from', 'type' => 'int', 'internal' => 'from'], + 'group_permission_from' => ['name' => 'group_permission_from', 'type' => 'string', 'internal' => 'from'], 'group_permission_type' => ['name' => 'group_permission_type', 'type' => 'int', 'internal' => 'type'], 'group_permission_element' => ['name' => 'group_permission_element', 'type' => 'int', 'internal' => 'element'], 'group_permission_component' => ['name' => 'group_permission_component', 'type' => 'int', 'internal' => 'component'], diff --git a/Theme/Backend/accounts-list.tpl.php b/Theme/Backend/accounts-list.tpl.php index b040f63..8e49350 100755 --- a/Theme/Backend/accounts-list.tpl.php +++ b/Theme/Backend/accounts-list.tpl.php @@ -29,9 +29,15 @@ echo $this->getData('nav')->render(); ?>
-
getHtml('Accounts'); ?>
+
+ getHtml('Accounts'); ?> + +
+
getHtml('ID', '0', '0'); ?> - + getHtml('Status'); ?>
@@ -80,23 +82,23 @@ $l11n = $this->getData('defaultlocalization') ?? new NullLocalization(); - + - + - + - + - +
@@ -118,7 +120,7 @@ $l11n = $this->getData('defaultlocalization') ?? new NullLocalization(); getHtml('Log'); ?> - +
@@ -544,5 +546,98 @@ $l11n = $this->getData('defaultlocalization') ?? new NullLocalization();
+ request->uri->fragment === 'c-tab-3' ? ' checked' : ''; ?>> +
+
+
+
+
getHtml('Settings'); ?>
+ + + + + $setting) : ++$count; + ?> + +
+ getHtml('ID', '0', '0'); ?> + + + + getHtml('Name'); ?> + + + + getHtml('Value'); ?> + getHtml('Module'); ?> + + + + getHtml('Group'); ?> + + + + getHtml('Account'); ?> + + + +
+ getId(); ?> + printHtml($setting->name); ?> + printHtml($setting->content); ?> + printHtml($setting->module); ?> + printHtml($setting->group); ?> + printHtml($setting->account); ?> + + +
getHtml('Empty', '0', '0'); ?> + +
+
+
+
+
+