underpost 2.6.3 → 2.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +13 -13
- package/.env.development +7 -7
- package/.env.production +7 -7
- package/.env.test +7 -7
- package/.github/workflows/publish.yml +26 -0
- package/.nycrc +9 -9
- package/.prettierignore +12 -12
- package/.prettierrc +9 -9
- package/.vscode/extensions.json +72 -72
- package/.vscode/settings.json +100 -99
- package/AUTHORS.md +10 -0
- package/CHANGELOG.md +91 -0
- package/Dockerfile +89 -89
- package/LICENSE +21 -21
- package/README.md +96 -96
- package/bin/db.js +172 -119
- package/bin/deploy.js +582 -626
- package/bin/dns.js +1 -1
- package/bin/file.js +92 -92
- package/bin/index.js +53 -34
- package/bin/install.js +398 -357
- package/bin/shortcut.js +44 -44
- package/bin/ssl.js +65 -61
- package/bin/util.js +182 -182
- package/bin/vs.js +35 -35
- package/conf.js +251 -249
- package/docker-compose.yml +67 -67
- package/jsconfig.json +7 -7
- package/jsdoc.json +32 -32
- package/nodemon.json +6 -6
- package/package.json +137 -128
- package/prometheus.yml +36 -36
- package/setup.sh +24 -24
- package/src/api/core/core.controller.js +69 -69
- package/src/api/core/core.model.js +11 -11
- package/src/api/core/core.router.js +23 -23
- package/src/api/core/core.service.js +29 -29
- package/src/api/crypto/crypto.controller.js +51 -51
- package/src/api/crypto/crypto.model.js +23 -23
- package/src/api/crypto/crypto.router.js +20 -20
- package/src/api/crypto/crypto.service.js +64 -64
- package/src/api/default/default.controller.js +69 -69
- package/src/api/default/default.model.js +20 -20
- package/src/api/default/default.router.js +23 -23
- package/src/api/default/default.service.js +31 -31
- package/src/api/file/file.controller.js +53 -51
- package/src/api/file/file.model.js +19 -19
- package/src/api/file/file.router.js +21 -20
- package/src/api/file/file.service.js +76 -70
- package/src/api/instance/instance.controller.js +69 -69
- package/src/api/instance/instance.model.js +36 -36
- package/src/api/instance/instance.router.js +33 -33
- package/src/api/instance/instance.service.js +48 -48
- package/src/api/test/test.controller.js +59 -59
- package/src/api/test/test.model.js +14 -14
- package/src/api/test/test.router.js +21 -21
- package/src/api/test/test.service.js +35 -35
- package/src/api/user/user.build.js +16 -0
- package/src/api/user/user.controller.js +70 -70
- package/src/api/user/user.model.js +65 -65
- package/src/api/user/user.router.js +345 -345
- package/src/api/user/user.service.js +479 -479
- package/src/api.js +23 -23
- package/src/client/Default.index.js +40 -40
- package/src/client/components/core/Account.js +290 -290
- package/src/client/components/core/AgGrid.js +160 -160
- package/src/client/components/core/Auth.js +19 -19
- package/src/client/components/core/Badge.js +32 -32
- package/src/client/components/core/BlockChain.js +41 -41
- package/src/client/components/core/Blog.js +9 -9
- package/src/client/components/core/BtnIcon.js +101 -94
- package/src/client/components/core/CalendarCore.js +458 -319
- package/src/client/components/core/Chat.js +64 -64
- package/src/client/components/core/ColorPalette.js +5267 -5267
- package/src/client/components/core/CommonJs.js +735 -732
- package/src/client/components/core/Content.js +193 -49
- package/src/client/components/core/Css.js +1064 -1027
- package/src/client/components/core/CssCore.js +817 -796
- package/src/client/components/core/D3Chart.js +44 -44
- package/src/client/components/core/Docs.js +229 -229
- package/src/client/components/core/DropDown.js +164 -164
- package/src/client/components/core/EventsUI.js +46 -54
- package/src/client/components/core/FileExplorer.js +699 -624
- package/src/client/components/core/FullScreen.js +45 -45
- package/src/client/components/core/Input.js +346 -259
- package/src/client/components/core/JoyStick.js +77 -77
- package/src/client/components/core/Keyboard.js +73 -73
- package/src/client/components/core/LoadingAnimation.js +179 -157
- package/src/client/components/core/LogIn.js +187 -181
- package/src/client/components/core/LogOut.js +58 -52
- package/src/client/components/core/Logger.js +26 -26
- package/src/client/components/core/Modal.js +1612 -1596
- package/src/client/components/core/NotificationManager.js +84 -84
- package/src/client/components/core/Panel.js +613 -413
- package/src/client/components/core/PanelForm.js +468 -0
- package/src/client/components/core/Polyhedron.js +162 -162
- package/src/client/components/core/Recover.js +204 -204
- package/src/client/components/core/Responsive.js +53 -53
- package/src/client/components/core/RichText.js +51 -27
- package/src/client/components/core/Router.js +76 -77
- package/src/client/components/core/Scroll.js +34 -0
- package/src/client/components/core/SignUp.js +125 -125
- package/src/client/components/core/SocketIo.js +72 -72
- package/src/client/components/core/Stream.js +113 -113
- package/src/client/components/core/ToggleSwitch.js +87 -87
- package/src/client/components/core/ToolTip.js +26 -26
- package/src/client/components/core/Translate.js +437 -408
- package/src/client/components/core/Validator.js +100 -100
- package/src/client/components/core/VanillaJs.js +460 -457
- package/src/client/components/core/Wallet.js +106 -106
- package/src/client/components/core/Webhook.js +25 -25
- package/src/client/components/core/Worker.js +272 -272
- package/src/client/components/default/CommonDefault.js +29 -29
- package/src/client/components/default/CssDefault.js +13 -13
- package/src/client/components/default/ElementsDefault.js +38 -38
- package/src/client/components/default/LogInDefault.js +41 -41
- package/src/client/components/default/LogOutDefault.js +28 -28
- package/src/client/components/default/MenuDefault.js +389 -389
- package/src/client/components/default/RoutesDefault.js +48 -48
- package/src/client/components/default/SettingsDefault.js +16 -16
- package/src/client/components/default/SignUpDefault.js +9 -9
- package/src/client/components/default/SocketIoDefault.js +54 -54
- package/src/client/components/default/TranslateDefault.js +7 -7
- package/src/client/public/default/assets/mailer/api-user-check.png +0 -0
- package/src/client/public/default/assets/mailer/api-user-invalid-token.png +0 -0
- package/src/client/public/default/assets/mailer/api-user-recover.png +0 -0
- package/src/client/public/default/browserconfig.xml +11 -11
- package/src/client/public/default/manifest.webmanifest +68 -68
- package/src/client/public/default/plantuml/client-conf.svg +1 -0
- package/src/client/public/default/plantuml/client-schema.svg +1 -0
- package/src/client/public/default/plantuml/cron-conf.svg +1 -0
- package/src/client/public/default/plantuml/cron-schema.svg +1 -0
- package/src/client/public/default/plantuml/server-conf.svg +1 -0
- package/src/client/public/default/plantuml/server-schema.svg +1 -0
- package/src/client/public/default/plantuml/ssr-conf.svg +1 -0
- package/src/client/public/default/plantuml/ssr-schema.svg +1 -0
- package/src/client/public/default/sitemap +147 -147
- package/src/client/public/default/yandex-browser-manifest.json +8 -8
- package/src/client/public/doc/sitemap +147 -147
- package/src/client/public/test/sitemap +147 -147
- package/src/client/services/core/core.service.js +170 -152
- package/src/client/services/crypto/crypto.service.js +70 -70
- package/src/client/services/default/default.management.js +345 -345
- package/src/client/services/default/default.service.js +89 -89
- package/src/client/services/file/file.service.js +70 -70
- package/src/client/services/instance/instance.management.js +74 -74
- package/src/client/services/instance/instance.service.js +89 -89
- package/src/client/services/test/test.service.js +70 -70
- package/src/client/services/user/user.management.js +50 -50
- package/src/client/services/user/user.service.js +89 -89
- package/src/client/ssr/Render.js +16 -16
- package/src/client/ssr/body-components/CacheControl.js +114 -113
- package/src/client/ssr/body-components/DefaultSplashScreen.js +79 -79
- package/src/client/ssr/email-components/DefaultRecoverEmail.js +21 -21
- package/src/client/ssr/email-components/DefaultVerifyEmail.js +17 -17
- package/src/client/ssr/head-components/Css.js +241 -241
- package/src/client/ssr/head-components/DefaultScripts.js +3 -3
- package/src/client/ssr/head-components/Microdata.js +11 -11
- package/src/client/ssr/head-components/Production.js +1 -1
- package/src/client/ssr/head-components/PwaDefault.js +59 -59
- package/src/client/ssr/head-components/Seo.js +14 -14
- package/src/client/sw/default.sw.js +201 -201
- package/src/client/sw/template.sw.js +84 -84
- package/src/client.build.js +22 -22
- package/src/client.dev.js +21 -21
- package/src/cron.js +25 -25
- package/src/db/DataBaseProvider.js +34 -34
- package/src/db/mariadb/MariaDB.js +33 -33
- package/src/db/mongo/MongooseDB.js +46 -46
- package/src/dns.js +22 -22
- package/src/index.js +42 -0
- package/src/mailer/EmailRender.js +69 -69
- package/src/mailer/MailerProvider.js +96 -96
- package/src/proxy.js +22 -22
- package/src/runtime/lampp/Lampp.js +69 -44
- package/src/runtime/nginx/Nginx.js +3 -3
- package/src/runtime/xampp/Xampp.js +49 -49
- package/src/server/auth.js +235 -204
- package/src/server/backup.js +101 -84
- package/src/server/client-build-live.js +72 -72
- package/src/server/client-build.js +705 -699
- package/src/server/client-dev-server.js +60 -58
- package/src/server/client-formatted.js +48 -48
- package/src/server/client-icons.js +149 -150
- package/src/server/conf.js +860 -611
- package/src/server/dns.js +98 -87
- package/src/server/downloader.js +42 -42
- package/src/server/logger.js +180 -135
- package/src/server/network.js +122 -122
- package/src/server/peer.js +33 -33
- package/src/server/process.js +66 -66
- package/src/server/prompt-optimizer.js +28 -0
- package/src/server/proxy.js +118 -118
- package/src/server/runtime.js +444 -393
- package/src/server/ssl.js +109 -107
- package/src/server.js +25 -25
- package/src/ws/IoInterface.js +45 -45
- package/src/ws/IoServer.js +39 -39
- package/src/ws/core/channels/core.ws.chat.js +23 -23
- package/src/ws/core/channels/core.ws.mailer.js +35 -35
- package/src/ws/core/channels/core.ws.stream.js +31 -31
- package/src/ws/core/core.ws.connection.js +28 -28
- package/src/ws/core/core.ws.emit.js +14 -14
- package/src/ws/core/core.ws.server.js +24 -24
- package/src/ws/core/management/core.ws.chat.js +8 -8
- package/src/ws/core/management/core.ws.mailer.js +16 -16
- package/src/ws/core/management/core.ws.stream.js +8 -8
- package/src/ws/default/channels/default.ws.main.js +16 -16
- package/src/ws/default/default.ws.connection.js +22 -22
- package/src/ws/default/default.ws.emit.js +14 -14
- package/src/ws/default/default.ws.server.js +20 -20
- package/src/ws/default/management/default.ws.main.js +8 -8
- package/startup.js +11 -11
- package/supervisord-openssh-server.conf +4 -4
- package/test/api.test.js +60 -60
- package/bin/help.js +0 -110
|
@@ -1,290 +1,290 @@
|
|
|
1
|
-
import { UserService } from '../../services/user/user.service.js';
|
|
2
|
-
import { BtnIcon } from './BtnIcon.js';
|
|
3
|
-
import { newInstance, s4 } from './CommonJs.js';
|
|
4
|
-
import { renderStatus, renderWave } from './Css.js';
|
|
5
|
-
import { EventsUI } from './EventsUI.js';
|
|
6
|
-
import { fileFormDataFactory, Input } from './Input.js';
|
|
7
|
-
import { LogIn } from './LogIn.js';
|
|
8
|
-
import { LogOut } from './LogOut.js';
|
|
9
|
-
import { Modal } from './Modal.js';
|
|
10
|
-
import { NotificationManager } from './NotificationManager.js';
|
|
11
|
-
import { Translate } from './Translate.js';
|
|
12
|
-
import { Validator } from './Validator.js';
|
|
13
|
-
import { append, htmls, s } from './VanillaJs.js';
|
|
14
|
-
|
|
15
|
-
const Account = {
|
|
16
|
-
UpdateEvent: {},
|
|
17
|
-
Render: async function (options = { user: {}, bottomRender: async () => '', idModal: '' }) {
|
|
18
|
-
// app profile page design example
|
|
19
|
-
// CSS animated backgrounds
|
|
20
|
-
let { user, idModal } = options;
|
|
21
|
-
const waveAnimationId = 'account-wave';
|
|
22
|
-
const profileFileAccept = ['image/png', 'image/jpeg'];
|
|
23
|
-
setTimeout(async () => {
|
|
24
|
-
if (LogIn.Scope.user.main.model.user.profileImage) {
|
|
25
|
-
append(
|
|
26
|
-
`.wave-animation-container-${waveAnimationId}`,
|
|
27
|
-
html` <div class="abs center account-profile-image-container">
|
|
28
|
-
<img
|
|
29
|
-
class="abs center account-profile-image"
|
|
30
|
-
style="opacity: 1"
|
|
31
|
-
src="${LogIn.Scope.user.main.model.user.profileImage.imageSrc}"
|
|
32
|
-
/>
|
|
33
|
-
</div>
|
|
34
|
-
<div class="abs center account-profile-image-loading" style="color: white"></div>`,
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const formData = [
|
|
39
|
-
{
|
|
40
|
-
model: 'username',
|
|
41
|
-
id: `account-username`,
|
|
42
|
-
rules: [{ type: 'isEmpty' }, { type: 'isLength', options: { min: 2, max: 20 } }],
|
|
43
|
-
},
|
|
44
|
-
{ model: 'email', id: `account-email`, rules: [{ type: 'isEmpty' }, { type: 'isEmail' }] },
|
|
45
|
-
{
|
|
46
|
-
model: 'password',
|
|
47
|
-
defaultValue: '*******',
|
|
48
|
-
id: `account-password`,
|
|
49
|
-
rules: [{ type: 'isStrongPassword' }],
|
|
50
|
-
},
|
|
51
|
-
];
|
|
52
|
-
const validators = await Validator.instance(formData);
|
|
53
|
-
|
|
54
|
-
for (const inputData of formData) {
|
|
55
|
-
s(`.${inputData.id}`).value =
|
|
56
|
-
!user[inputData.model] && inputData.defaultValue ? inputData.defaultValue : user[inputData.model];
|
|
57
|
-
}
|
|
58
|
-
let lastUser;
|
|
59
|
-
const submit = async () => {
|
|
60
|
-
lastUser = newInstance(user);
|
|
61
|
-
const { errorMessage } = await validators();
|
|
62
|
-
if (errorMessage) return;
|
|
63
|
-
const body = {};
|
|
64
|
-
for (const inputData of formData) {
|
|
65
|
-
if (!s(`.${inputData.id}`).value || s(`.${inputData.id}`).value === 'undefined') continue;
|
|
66
|
-
if ('model' in inputData) {
|
|
67
|
-
body[inputData.model] = s(`.${inputData.id}`).value;
|
|
68
|
-
user[inputData.model] = s(`.${inputData.id}`).value;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
const result = await UserService.put({ id: user._id, body });
|
|
72
|
-
NotificationManager.Push({
|
|
73
|
-
html:
|
|
74
|
-
result.status === 'error' && result.message
|
|
75
|
-
? result.message
|
|
76
|
-
: Translate.Render(`${result.status}-update-user`),
|
|
77
|
-
status: result.status,
|
|
78
|
-
});
|
|
79
|
-
if (result.status === 'success') {
|
|
80
|
-
user = result.data;
|
|
81
|
-
this.triggerUpdateEvent({ user });
|
|
82
|
-
if (lastUser.emailConfirmed !== user.emailConfirmed) {
|
|
83
|
-
this.renderVerifyEmailStatus(user);
|
|
84
|
-
}
|
|
85
|
-
lastUser = newInstance(user);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
EventsUI.onClick(`.btn-account`, async (e) => {
|
|
89
|
-
e.preventDefault();
|
|
90
|
-
await submit();
|
|
91
|
-
});
|
|
92
|
-
EventsUI.onClick(`.btn-account-update-username`, async (e) => {
|
|
93
|
-
e.preventDefault();
|
|
94
|
-
await submit();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
if (s(`.btn-confirm-email`))
|
|
98
|
-
EventsUI.onClick(`.btn-confirm-email`, async (e) => {
|
|
99
|
-
e.preventDefault();
|
|
100
|
-
const result = await UserService.post({
|
|
101
|
-
id: 'mailer/verify-email',
|
|
102
|
-
body: { email: s(`.account-email`).value },
|
|
103
|
-
});
|
|
104
|
-
NotificationManager.Push({
|
|
105
|
-
html: result.status === 'error' ? result.message : Translate.Render(`email send`),
|
|
106
|
-
status: result.status,
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
this.renderVerifyEmailStatus(user);
|
|
110
|
-
|
|
111
|
-
s(`.${waveAnimationId}`).style.cursor = 'pointer';
|
|
112
|
-
s(`.${waveAnimationId}`).onclick = async (e) => {
|
|
113
|
-
e.preventDefault();
|
|
114
|
-
s(`.account-profile-image-input`).click();
|
|
115
|
-
};
|
|
116
|
-
EventsUI.onChange(
|
|
117
|
-
`.account-profile-image-input`,
|
|
118
|
-
async (e) => {
|
|
119
|
-
e.preventDefault();
|
|
120
|
-
s(`.account-profile-image`).style.opacity = 0;
|
|
121
|
-
const formFile = fileFormDataFactory(e, profileFileAccept);
|
|
122
|
-
|
|
123
|
-
const { status, data } = await UserService.put({
|
|
124
|
-
id: `profile-image/${user._id}`,
|
|
125
|
-
body: formFile,
|
|
126
|
-
headerId: 'file',
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
if (status === 'success') {
|
|
130
|
-
user.profileImageId = data.profileImageId;
|
|
131
|
-
delete LogIn.Scope.user.main.model.user.profileImage;
|
|
132
|
-
await LogIn.Trigger({ user });
|
|
133
|
-
s(`.account-profile-image`).src = LogIn.Scope.user.main.model.user.profileImage.imageSrc;
|
|
134
|
-
} else {
|
|
135
|
-
NotificationManager.Push({
|
|
136
|
-
html: Translate.Render('file-upload-failed'),
|
|
137
|
-
status: 'error',
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
s(`.account-profile-image`).style.opacity = 1;
|
|
142
|
-
},
|
|
143
|
-
{ loadingContainer: `.account-profile-image-loading` },
|
|
144
|
-
);
|
|
145
|
-
s(`.btn-account-change-password`).onclick = (e) => {
|
|
146
|
-
e.preventDefault();
|
|
147
|
-
// s(`.btn-close-modal-account`).click();
|
|
148
|
-
s(`.main-btn-recover`).click();
|
|
149
|
-
};
|
|
150
|
-
s(`.btn-account-delete-confirm`).onclick = async (e) => {
|
|
151
|
-
e.preventDefault();
|
|
152
|
-
const confirmResult = await Modal.RenderConfirm({
|
|
153
|
-
html: async () => {
|
|
154
|
-
return html`
|
|
155
|
-
<div class="in section-mp" style="text-align: center">${Translate.Render('confirm-delete-account')}</div>
|
|
156
|
-
`;
|
|
157
|
-
},
|
|
158
|
-
id: 'delete-account-modal',
|
|
159
|
-
});
|
|
160
|
-
if (confirmResult.status === 'cancelled') return;
|
|
161
|
-
s(`.btn-account-delete-confirm`).classList.add('hide');
|
|
162
|
-
s(`.btn-account-delete`).classList.remove('hide');
|
|
163
|
-
s(`.btn-account-delete`).click();
|
|
164
|
-
};
|
|
165
|
-
EventsUI.onClick(`.btn-account-delete`, async (e) => {
|
|
166
|
-
e.preventDefault();
|
|
167
|
-
const result = await UserService.delete({ id: user._id });
|
|
168
|
-
NotificationManager.Push({
|
|
169
|
-
html: result.status === 'error' ? result.message : Translate.Render(`success-delete-account`),
|
|
170
|
-
status: result.status,
|
|
171
|
-
});
|
|
172
|
-
s(`.btn-account-delete-confirm`).classList.remove('hide');
|
|
173
|
-
s(`.btn-account-delete`).classList.add('hide');
|
|
174
|
-
if (result.status === 'success') {
|
|
175
|
-
LogOut.Trigger();
|
|
176
|
-
s(`.main-btn-home`).click();
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
return html`
|
|
181
|
-
<input type="file" accept="${profileFileAccept.join(', ')}" class="account-profile-image-input hide" />
|
|
182
|
-
${renderWave({ id: waveAnimationId })}
|
|
183
|
-
|
|
184
|
-
<form class="in">
|
|
185
|
-
<div class="in">
|
|
186
|
-
${await Input.Render({
|
|
187
|
-
id: `account-username`,
|
|
188
|
-
type: 'text',
|
|
189
|
-
label: html`<i class="fa-solid fa-pen-to-square"></i> ${Translate.Render('username')}`,
|
|
190
|
-
containerClass: 'inl section-mp width-mini-box input-container',
|
|
191
|
-
placeholder: true,
|
|
192
|
-
disabled: false,
|
|
193
|
-
extension: async () =>
|
|
194
|
-
html`${await BtnIcon.Render({
|
|
195
|
-
class: `wfa btn-input-extension btn-account-update-username`,
|
|
196
|
-
type: 'button',
|
|
197
|
-
style: 'text-align: left',
|
|
198
|
-
label: html`${Translate.Render(`update`)}`,
|
|
199
|
-
})}`,
|
|
200
|
-
})}
|
|
201
|
-
</div>
|
|
202
|
-
<div class="in">
|
|
203
|
-
${await Input.Render({
|
|
204
|
-
id: `account-email`,
|
|
205
|
-
type: 'email',
|
|
206
|
-
label: html`<i class="fa-solid fa-envelope"></i> ${Translate.Render('email')}`,
|
|
207
|
-
containerClass: 'inl section-mp width-mini-box input-container',
|
|
208
|
-
placeholder: true,
|
|
209
|
-
autocomplete: 'email',
|
|
210
|
-
disabled: user.emailConfirmed,
|
|
211
|
-
extension: !(options && options.disabled && options.disabled.includes('emailConfirm'))
|
|
212
|
-
? async () => html`<div class="in verify-email-status"></div>
|
|
213
|
-
${await BtnIcon.Render({
|
|
214
|
-
class: `wfa btn-input-extension btn-confirm-email`,
|
|
215
|
-
type: 'button',
|
|
216
|
-
style: 'text-align: left',
|
|
217
|
-
label: html`<div class="in">
|
|
218
|
-
<i class="fa-solid fa-paper-plane"></i> ${Translate.Render('send')}
|
|
219
|
-
${Translate.Render('verify-email')}
|
|
220
|
-
</div> `,
|
|
221
|
-
})}`
|
|
222
|
-
: undefined,
|
|
223
|
-
})}
|
|
224
|
-
</div>
|
|
225
|
-
<div class="in">
|
|
226
|
-
${await Input.Render({
|
|
227
|
-
id: `account-password`,
|
|
228
|
-
type: 'password',
|
|
229
|
-
autocomplete: 'new-password',
|
|
230
|
-
label: html`<i class="fa-solid fa-lock"></i> ${Translate.Render('password')}`,
|
|
231
|
-
containerClass: 'inl section-mp width-mini-box input-container',
|
|
232
|
-
placeholder: true,
|
|
233
|
-
disabled: true,
|
|
234
|
-
disabledEye: true,
|
|
235
|
-
extension: async () =>
|
|
236
|
-
html`${await BtnIcon.Render({
|
|
237
|
-
class: `wfa btn-input-extension btn-account-change-password`,
|
|
238
|
-
type: 'button',
|
|
239
|
-
style: 'text-align: left',
|
|
240
|
-
label: html`${Translate.Render(`change-password`)}`,
|
|
241
|
-
})}`,
|
|
242
|
-
})}
|
|
243
|
-
</div>
|
|
244
|
-
${options?.bottomRender ? await options.bottomRender() : ``}
|
|
245
|
-
<div class="in hide">
|
|
246
|
-
${await BtnIcon.Render({
|
|
247
|
-
class: 'section-mp form-button btn-account',
|
|
248
|
-
label: Translate.Render('update'),
|
|
249
|
-
type: 'submit',
|
|
250
|
-
})}
|
|
251
|
-
</div>
|
|
252
|
-
</form>
|
|
253
|
-
<div class="in">
|
|
254
|
-
${await BtnIcon.Render({
|
|
255
|
-
class: 'section-mp form-button btn-account-delete hide',
|
|
256
|
-
label: html` ${Translate.Render(`delete-account`)}`,
|
|
257
|
-
type: 'button',
|
|
258
|
-
style: 'color: #5f5f5f',
|
|
259
|
-
})}
|
|
260
|
-
${await BtnIcon.Render({
|
|
261
|
-
class: 'section-mp form-button btn-account-delete-confirm',
|
|
262
|
-
label: html` ${Translate.Render(`delete-account`)}`,
|
|
263
|
-
type: 'button',
|
|
264
|
-
style: 'color: #5f5f5f',
|
|
265
|
-
})}
|
|
266
|
-
</div>
|
|
267
|
-
`;
|
|
268
|
-
},
|
|
269
|
-
triggerUpdateEvent: async function (options = { user: {} }) {
|
|
270
|
-
for (const updateEvent of Object.keys(this.UpdateEvent)) {
|
|
271
|
-
await this.UpdateEvent[updateEvent](options);
|
|
272
|
-
}
|
|
273
|
-
},
|
|
274
|
-
renderVerifyEmailStatus: function (user) {
|
|
275
|
-
if (s('.verify-email-status')) {
|
|
276
|
-
if (s(`.btn-confirm-email`)) {
|
|
277
|
-
if (user.emailConfirmed) s(`.btn-confirm-email`).classList.add('hide');
|
|
278
|
-
else s(`.btn-confirm-email`).classList.remove('hide');
|
|
279
|
-
}
|
|
280
|
-
htmls(
|
|
281
|
-
'.verify-email-status',
|
|
282
|
-
html`${renderStatus(user.emailConfirmed ? 'success' : 'error', { class: 'inl' })} ${Translate.Render('email')}
|
|
283
|
-
${Translate.Render(user.emailConfirmed ? 'confirmed' : 'unconfirmed')}`,
|
|
284
|
-
);
|
|
285
|
-
if (user.emailConfirmed === true) s(`.account-email`).setAttribute('disabled', '');
|
|
286
|
-
}
|
|
287
|
-
},
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
export { Account };
|
|
1
|
+
import { UserService } from '../../services/user/user.service.js';
|
|
2
|
+
import { BtnIcon } from './BtnIcon.js';
|
|
3
|
+
import { newInstance, s4 } from './CommonJs.js';
|
|
4
|
+
import { renderStatus, renderWave } from './Css.js';
|
|
5
|
+
import { EventsUI } from './EventsUI.js';
|
|
6
|
+
import { fileFormDataFactory, Input } from './Input.js';
|
|
7
|
+
import { LogIn } from './LogIn.js';
|
|
8
|
+
import { LogOut } from './LogOut.js';
|
|
9
|
+
import { Modal } from './Modal.js';
|
|
10
|
+
import { NotificationManager } from './NotificationManager.js';
|
|
11
|
+
import { Translate } from './Translate.js';
|
|
12
|
+
import { Validator } from './Validator.js';
|
|
13
|
+
import { append, htmls, s } from './VanillaJs.js';
|
|
14
|
+
|
|
15
|
+
const Account = {
|
|
16
|
+
UpdateEvent: {},
|
|
17
|
+
Render: async function (options = { user: {}, bottomRender: async () => '', idModal: '' }) {
|
|
18
|
+
// app profile page design example
|
|
19
|
+
// CSS animated backgrounds
|
|
20
|
+
let { user, idModal } = options;
|
|
21
|
+
const waveAnimationId = 'account-wave';
|
|
22
|
+
const profileFileAccept = ['image/png', 'image/jpeg'];
|
|
23
|
+
setTimeout(async () => {
|
|
24
|
+
if (LogIn.Scope.user.main.model.user.profileImage) {
|
|
25
|
+
append(
|
|
26
|
+
`.wave-animation-container-${waveAnimationId}`,
|
|
27
|
+
html` <div class="abs center account-profile-image-container">
|
|
28
|
+
<img
|
|
29
|
+
class="abs center account-profile-image"
|
|
30
|
+
style="opacity: 1"
|
|
31
|
+
src="${LogIn.Scope.user.main.model.user.profileImage.imageSrc}"
|
|
32
|
+
/>
|
|
33
|
+
</div>
|
|
34
|
+
<div class="abs center account-profile-image-loading" style="color: white"></div>`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const formData = [
|
|
39
|
+
{
|
|
40
|
+
model: 'username',
|
|
41
|
+
id: `account-username`,
|
|
42
|
+
rules: [{ type: 'isEmpty' }, { type: 'isLength', options: { min: 2, max: 20 } }],
|
|
43
|
+
},
|
|
44
|
+
{ model: 'email', id: `account-email`, rules: [{ type: 'isEmpty' }, { type: 'isEmail' }] },
|
|
45
|
+
{
|
|
46
|
+
model: 'password',
|
|
47
|
+
defaultValue: '*******',
|
|
48
|
+
id: `account-password`,
|
|
49
|
+
rules: [{ type: 'isStrongPassword' }],
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
const validators = await Validator.instance(formData);
|
|
53
|
+
|
|
54
|
+
for (const inputData of formData) {
|
|
55
|
+
s(`.${inputData.id}`).value =
|
|
56
|
+
!user[inputData.model] && inputData.defaultValue ? inputData.defaultValue : user[inputData.model];
|
|
57
|
+
}
|
|
58
|
+
let lastUser;
|
|
59
|
+
const submit = async () => {
|
|
60
|
+
lastUser = newInstance(user);
|
|
61
|
+
const { errorMessage } = await validators();
|
|
62
|
+
if (errorMessage) return;
|
|
63
|
+
const body = {};
|
|
64
|
+
for (const inputData of formData) {
|
|
65
|
+
if (!s(`.${inputData.id}`).value || s(`.${inputData.id}`).value === 'undefined') continue;
|
|
66
|
+
if ('model' in inputData) {
|
|
67
|
+
body[inputData.model] = s(`.${inputData.id}`).value;
|
|
68
|
+
user[inputData.model] = s(`.${inputData.id}`).value;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const result = await UserService.put({ id: user._id, body });
|
|
72
|
+
NotificationManager.Push({
|
|
73
|
+
html:
|
|
74
|
+
result.status === 'error' && result.message
|
|
75
|
+
? result.message
|
|
76
|
+
: Translate.Render(`${result.status}-update-user`),
|
|
77
|
+
status: result.status,
|
|
78
|
+
});
|
|
79
|
+
if (result.status === 'success') {
|
|
80
|
+
user = result.data;
|
|
81
|
+
this.triggerUpdateEvent({ user });
|
|
82
|
+
if (lastUser.emailConfirmed !== user.emailConfirmed) {
|
|
83
|
+
this.renderVerifyEmailStatus(user);
|
|
84
|
+
}
|
|
85
|
+
lastUser = newInstance(user);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
EventsUI.onClick(`.btn-account`, async (e) => {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
await submit();
|
|
91
|
+
});
|
|
92
|
+
EventsUI.onClick(`.btn-account-update-username`, async (e) => {
|
|
93
|
+
e.preventDefault();
|
|
94
|
+
await submit();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
if (s(`.btn-confirm-email`))
|
|
98
|
+
EventsUI.onClick(`.btn-confirm-email`, async (e) => {
|
|
99
|
+
e.preventDefault();
|
|
100
|
+
const result = await UserService.post({
|
|
101
|
+
id: 'mailer/verify-email',
|
|
102
|
+
body: { email: s(`.account-email`).value },
|
|
103
|
+
});
|
|
104
|
+
NotificationManager.Push({
|
|
105
|
+
html: result.status === 'error' ? result.message : Translate.Render(`email send`),
|
|
106
|
+
status: result.status,
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
this.renderVerifyEmailStatus(user);
|
|
110
|
+
|
|
111
|
+
s(`.${waveAnimationId}`).style.cursor = 'pointer';
|
|
112
|
+
s(`.${waveAnimationId}`).onclick = async (e) => {
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
s(`.account-profile-image-input`).click();
|
|
115
|
+
};
|
|
116
|
+
EventsUI.onChange(
|
|
117
|
+
`.account-profile-image-input`,
|
|
118
|
+
async (e) => {
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
s(`.account-profile-image`).style.opacity = 0;
|
|
121
|
+
const formFile = fileFormDataFactory(e, profileFileAccept);
|
|
122
|
+
|
|
123
|
+
const { status, data } = await UserService.put({
|
|
124
|
+
id: `profile-image/${user._id}`,
|
|
125
|
+
body: formFile,
|
|
126
|
+
headerId: 'file',
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
if (status === 'success') {
|
|
130
|
+
user.profileImageId = data.profileImageId;
|
|
131
|
+
delete LogIn.Scope.user.main.model.user.profileImage;
|
|
132
|
+
await LogIn.Trigger({ user });
|
|
133
|
+
s(`.account-profile-image`).src = LogIn.Scope.user.main.model.user.profileImage.imageSrc;
|
|
134
|
+
} else {
|
|
135
|
+
NotificationManager.Push({
|
|
136
|
+
html: Translate.Render('file-upload-failed'),
|
|
137
|
+
status: 'error',
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
s(`.account-profile-image`).style.opacity = 1;
|
|
142
|
+
},
|
|
143
|
+
{ loadingContainer: `.account-profile-image-loading` },
|
|
144
|
+
);
|
|
145
|
+
s(`.btn-account-change-password`).onclick = (e) => {
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
// s(`.btn-close-modal-account`).click();
|
|
148
|
+
s(`.main-btn-recover`).click();
|
|
149
|
+
};
|
|
150
|
+
s(`.btn-account-delete-confirm`).onclick = async (e) => {
|
|
151
|
+
e.preventDefault();
|
|
152
|
+
const confirmResult = await Modal.RenderConfirm({
|
|
153
|
+
html: async () => {
|
|
154
|
+
return html`
|
|
155
|
+
<div class="in section-mp" style="text-align: center">${Translate.Render('confirm-delete-account')}</div>
|
|
156
|
+
`;
|
|
157
|
+
},
|
|
158
|
+
id: 'delete-account-modal',
|
|
159
|
+
});
|
|
160
|
+
if (confirmResult.status === 'cancelled') return;
|
|
161
|
+
s(`.btn-account-delete-confirm`).classList.add('hide');
|
|
162
|
+
s(`.btn-account-delete`).classList.remove('hide');
|
|
163
|
+
s(`.btn-account-delete`).click();
|
|
164
|
+
};
|
|
165
|
+
EventsUI.onClick(`.btn-account-delete`, async (e) => {
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
const result = await UserService.delete({ id: user._id });
|
|
168
|
+
NotificationManager.Push({
|
|
169
|
+
html: result.status === 'error' ? result.message : Translate.Render(`success-delete-account`),
|
|
170
|
+
status: result.status,
|
|
171
|
+
});
|
|
172
|
+
s(`.btn-account-delete-confirm`).classList.remove('hide');
|
|
173
|
+
s(`.btn-account-delete`).classList.add('hide');
|
|
174
|
+
if (result.status === 'success') {
|
|
175
|
+
LogOut.Trigger();
|
|
176
|
+
s(`.main-btn-home`).click();
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
return html`
|
|
181
|
+
<input type="file" accept="${profileFileAccept.join(', ')}" class="account-profile-image-input hide" />
|
|
182
|
+
${renderWave({ id: waveAnimationId })}
|
|
183
|
+
|
|
184
|
+
<form class="in">
|
|
185
|
+
<div class="in">
|
|
186
|
+
${await Input.Render({
|
|
187
|
+
id: `account-username`,
|
|
188
|
+
type: 'text',
|
|
189
|
+
label: html`<i class="fa-solid fa-pen-to-square"></i> ${Translate.Render('username')}`,
|
|
190
|
+
containerClass: 'inl section-mp width-mini-box input-container',
|
|
191
|
+
placeholder: true,
|
|
192
|
+
disabled: false,
|
|
193
|
+
extension: async () =>
|
|
194
|
+
html`${await BtnIcon.Render({
|
|
195
|
+
class: `wfa btn-input-extension btn-account-update-username`,
|
|
196
|
+
type: 'button',
|
|
197
|
+
style: 'text-align: left',
|
|
198
|
+
label: html`${Translate.Render(`update`)}`,
|
|
199
|
+
})}`,
|
|
200
|
+
})}
|
|
201
|
+
</div>
|
|
202
|
+
<div class="in">
|
|
203
|
+
${await Input.Render({
|
|
204
|
+
id: `account-email`,
|
|
205
|
+
type: 'email',
|
|
206
|
+
label: html`<i class="fa-solid fa-envelope"></i> ${Translate.Render('email')}`,
|
|
207
|
+
containerClass: 'inl section-mp width-mini-box input-container',
|
|
208
|
+
placeholder: true,
|
|
209
|
+
autocomplete: 'email',
|
|
210
|
+
disabled: user.emailConfirmed,
|
|
211
|
+
extension: !(options && options.disabled && options.disabled.includes('emailConfirm'))
|
|
212
|
+
? async () => html`<div class="in verify-email-status"></div>
|
|
213
|
+
${await BtnIcon.Render({
|
|
214
|
+
class: `wfa btn-input-extension btn-confirm-email`,
|
|
215
|
+
type: 'button',
|
|
216
|
+
style: 'text-align: left',
|
|
217
|
+
label: html`<div class="in">
|
|
218
|
+
<i class="fa-solid fa-paper-plane"></i> ${Translate.Render('send')}
|
|
219
|
+
${Translate.Render('verify-email')}
|
|
220
|
+
</div> `,
|
|
221
|
+
})}`
|
|
222
|
+
: undefined,
|
|
223
|
+
})}
|
|
224
|
+
</div>
|
|
225
|
+
<div class="in">
|
|
226
|
+
${await Input.Render({
|
|
227
|
+
id: `account-password`,
|
|
228
|
+
type: 'password',
|
|
229
|
+
autocomplete: 'new-password',
|
|
230
|
+
label: html`<i class="fa-solid fa-lock"></i> ${Translate.Render('password')}`,
|
|
231
|
+
containerClass: 'inl section-mp width-mini-box input-container',
|
|
232
|
+
placeholder: true,
|
|
233
|
+
disabled: true,
|
|
234
|
+
disabledEye: true,
|
|
235
|
+
extension: async () =>
|
|
236
|
+
html`${await BtnIcon.Render({
|
|
237
|
+
class: `wfa btn-input-extension btn-account-change-password`,
|
|
238
|
+
type: 'button',
|
|
239
|
+
style: 'text-align: left',
|
|
240
|
+
label: html`${Translate.Render(`change-password`)}`,
|
|
241
|
+
})}`,
|
|
242
|
+
})}
|
|
243
|
+
</div>
|
|
244
|
+
${options?.bottomRender ? await options.bottomRender() : ``}
|
|
245
|
+
<div class="in hide">
|
|
246
|
+
${await BtnIcon.Render({
|
|
247
|
+
class: 'section-mp form-button btn-account',
|
|
248
|
+
label: Translate.Render('update'),
|
|
249
|
+
type: 'submit',
|
|
250
|
+
})}
|
|
251
|
+
</div>
|
|
252
|
+
</form>
|
|
253
|
+
<div class="in">
|
|
254
|
+
${await BtnIcon.Render({
|
|
255
|
+
class: 'section-mp form-button btn-account-delete hide',
|
|
256
|
+
label: html` ${Translate.Render(`delete-account`)}`,
|
|
257
|
+
type: 'button',
|
|
258
|
+
style: 'color: #5f5f5f',
|
|
259
|
+
})}
|
|
260
|
+
${await BtnIcon.Render({
|
|
261
|
+
class: 'section-mp form-button btn-account-delete-confirm',
|
|
262
|
+
label: html` ${Translate.Render(`delete-account`)}`,
|
|
263
|
+
type: 'button',
|
|
264
|
+
style: 'color: #5f5f5f',
|
|
265
|
+
})}
|
|
266
|
+
</div>
|
|
267
|
+
`;
|
|
268
|
+
},
|
|
269
|
+
triggerUpdateEvent: async function (options = { user: {} }) {
|
|
270
|
+
for (const updateEvent of Object.keys(this.UpdateEvent)) {
|
|
271
|
+
await this.UpdateEvent[updateEvent](options);
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
renderVerifyEmailStatus: function (user) {
|
|
275
|
+
if (s('.verify-email-status')) {
|
|
276
|
+
if (s(`.btn-confirm-email`)) {
|
|
277
|
+
if (user.emailConfirmed) s(`.btn-confirm-email`).classList.add('hide');
|
|
278
|
+
else s(`.btn-confirm-email`).classList.remove('hide');
|
|
279
|
+
}
|
|
280
|
+
htmls(
|
|
281
|
+
'.verify-email-status',
|
|
282
|
+
html`${renderStatus(user.emailConfirmed ? 'success' : 'error', { class: 'inl' })} ${Translate.Render('email')}
|
|
283
|
+
${Translate.Render(user.emailConfirmed ? 'confirmed' : 'unconfirmed')}`,
|
|
284
|
+
);
|
|
285
|
+
if (user.emailConfirmed === true) s(`.account-email`).setAttribute('disabled', '');
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
export { Account };
|