From 9645b5947e41835ecbc6339edb7ef5aa6e0cc514 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Thu, 14 Jul 2022 09:45:51 +0700 Subject: [PATCH] Fix password bugs (#2235) Signed-off-by: Andrey Sobolev --- .vscode/launch.json | 15 ++++ changelog.md | 10 ++- dev/tool/src/index.ts | 15 +++- packages/ui/src/components/EditBox.svelte | 3 +- plugins/login-resources/src/utils.ts | 12 ++- plugins/setting-assets/lang/en.json | 3 +- plugins/setting-assets/lang/ru.json | 3 +- .../src/components/Password.svelte | 17 ++++ .../src/components/Settings.svelte | 79 +++++++++++-------- .../src/components/WorkspaceSettings.svelte | 48 +++++++---- .../src/components/icons/Error.svelte | 9 +++ plugins/setting-resources/src/plugin.ts | 3 +- .../src/components/Templates.svelte | 6 +- .../src/components/Workbench.svelte | 6 +- server/account/src/index.ts | 15 ++++ 15 files changed, 178 insertions(+), 66 deletions(-) create mode 100644 plugins/setting-resources/src/components/icons/Error.svelte diff --git a/.vscode/launch.json b/.vscode/launch.json index 10c8eb81f3..835396d365 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -24,6 +24,21 @@ "cwd": "${workspaceRoot}/server/server", "protocol": "inspector" }, + { + "name": "Debug Account", + "type": "node", + "request": "launch", + "args": ["src/index.ts"], + "env": { + "MONGO_URL": "mongodb://localhost:27017", + "SERVER_SECRET": "secret", + "TRANSACTOR_URL": "ws:/localhost:3333" + }, + "runtimeArgs": ["--nolazy", "-r", "ts-node/register"], + "sourceMaps": true, + "cwd": "${workspaceRoot}/pods/account", + "protocol": "inspector" + }, { "type": "node", "request": "launch", diff --git a/changelog.md b/changelog.md index 86af0524b6..176e6deff5 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,13 @@ # Changelog -## 0.6.30 (upcoming) +## 0.6.31 (upcoming) + +Core: + +- Fix password change settings +- Fix settings collapse + +## 0.6.30 Core: @@ -38,7 +45,6 @@ Tracker: - Roadmap - Context menus (Priority/Status/Assignee) - Chunter: - Reactions on messages diff --git a/dev/tool/src/index.ts b/dev/tool/src/index.ts index a708fd48af..06192f85ab 100644 --- a/dev/tool/src/index.ts +++ b/dev/tool/src/index.ts @@ -23,9 +23,10 @@ import { dropWorkspace, getAccount, getWorkspace, - setRole, listAccounts, listWorkspaces, + replacePassword, + setRole, upgradeWorkspace } from '@anticrm/account' import { setMetadata } from '@anticrm/platform' @@ -94,6 +95,18 @@ program }) }) +program + .command('reset-account ') + .description('create user and corresponding account in master database') + .option('-p, --password ', 'new user password') + .action(async (email: string, cmd) => { + const { mongodbUri } = prepareTools() + return await withDatabase(mongodbUri, async (db) => { + console.log(`update account ${email} ${cmd.first as string} ${cmd.last as string}...`) + await replacePassword(db, email, cmd.password) + }) + }) + program .command('assign-workspace ') .description('assign workspace') diff --git a/packages/ui/src/components/EditBox.svelte b/packages/ui/src/components/EditBox.svelte index 07360253aa..5a9332d73b 100644 --- a/packages/ui/src/components/EditBox.svelte +++ b/packages/ui/src/components/EditBox.svelte @@ -121,8 +121,9 @@ {/if} {#if format === 'password'} { diff --git a/plugins/setting-assets/lang/en.json b/plugins/setting-assets/lang/en.json index 031e4b5494..86a452c13f 100644 --- a/plugins/setting-assets/lang/en.json +++ b/plugins/setting-assets/lang/en.json @@ -53,6 +53,7 @@ "User": "User", "Maintainer": "Maintainer", "Owner": "Owner", - "Role": "Role" + "Role": "Role", + "FailedToSave": "Failed to update password" } } \ No newline at end of file diff --git a/plugins/setting-assets/lang/ru.json b/plugins/setting-assets/lang/ru.json index 90c659f71a..0edeaf8a15 100644 --- a/plugins/setting-assets/lang/ru.json +++ b/plugins/setting-assets/lang/ru.json @@ -53,6 +53,7 @@ "User": "Пользователь", "Maintainer": "Maintainer", "Owner": "Владелец", - "Role": "Роль" + "Role": "Роль", + "FailedToSave": "Не удалось обновить пароль" } } \ No newline at end of file diff --git a/plugins/setting-resources/src/components/Password.svelte b/plugins/setting-resources/src/components/Password.svelte index 9ecaf041bf..811fc3bc93 100644 --- a/plugins/setting-resources/src/components/Password.svelte +++ b/plugins/setting-resources/src/components/Password.svelte @@ -17,12 +17,15 @@ import presentation from '@anticrm/presentation' import { Button, EditBox, Icon, Label } from '@anticrm/ui' import { changePassword } from '@anticrm/login-resources' + import Error from './icons/Error.svelte' + import plugin from '../plugin' let oldPassword: string = '' let password: string = '' let password2: string = '' let label = presentation.string.Save let saved = false + let error = false $: disabled = password.length === 0 || oldPassword.length === 0 || oldPassword === password || password !== password2 || saved @@ -37,8 +40,16 @@ console.log(e) label = presentation.string.Save saved = false + error = true } } + + function updateSaved (p1: string, p2: string, p3: string): void { + saved = false + label = presentation.string.Save + error = false + } + $: updateSaved(oldPassword, password, password2)
@@ -48,6 +59,12 @@
+ {#if error} +
+ +
+ {/if}
-
-
- - + {#if visibileNav} +
+
+ + +
+ {#each categories as category, i} + {#if i > 0 && categories[i - 1].group !== category.group} +
+ {/if} + { + selectCategory(category.name) + }} + /> + {/each} +
+ + + +
- {#each categories as category, i} - {#if i > 0 && categories[i - 1].group !== category.group} -
- {/if} - { - selectCategory(category.name) - }} - /> - {/each} -
- - - -
-
+ {/if}
{#if category} - + { + selectCategory(categories[0].name) + } + }} + /> {/if}
diff --git a/plugins/setting-resources/src/components/WorkspaceSettings.svelte b/plugins/setting-resources/src/components/WorkspaceSettings.svelte index 1ba9866b8e..3cb95e1957 100644 --- a/plugins/setting-resources/src/components/WorkspaceSettings.svelte +++ b/plugins/setting-resources/src/components/WorkspaceSettings.svelte @@ -17,7 +17,7 @@ import { AccountRole, getCurrentAccount } from '@anticrm/core' import { createQuery } from '@anticrm/presentation' import setting, { SettingsCategory } from '@anticrm/setting' - import { Component, getCurrentLocation, Label, location, navigate } from '@anticrm/ui' + import ui, { Button, Component, getCurrentLocation, IconBack, Label, location, navigate } from '@anticrm/ui' import { onDestroy } from 'svelte' import CategoryElement from './CategoryElement.svelte' @@ -27,6 +27,9 @@ let categories: SettingsCategory[] = [] const account = getCurrentAccount() as EmployeeAccount + export let visibileNav = true + export let onFirstCategory: () => void + const settingsQuery = createQuery() settingsQuery.query( setting.class.WorkspaceSettingCategory, @@ -58,23 +61,34 @@
-
-
- - + {#if visibileNav} +
+
+
+
+
+ {#each categories as category} + { + selectCategory(category.name) + }} + /> + {/each}
- {#each categories as category} - { - selectCategory(category.name) - }} - /> - {/each} -
+ {/if}
{#if category} diff --git a/plugins/setting-resources/src/components/icons/Error.svelte b/plugins/setting-resources/src/components/icons/Error.svelte new file mode 100644 index 0000000000..e6bc282abc --- /dev/null +++ b/plugins/setting-resources/src/components/icons/Error.svelte @@ -0,0 +1,9 @@ + + + + diff --git a/plugins/setting-resources/src/plugin.ts b/plugins/setting-resources/src/plugin.ts index 79ee1fd42d..06e47baad6 100644 --- a/plugins/setting-resources/src/plugin.ts +++ b/plugins/setting-resources/src/plugin.ts @@ -47,6 +47,7 @@ export default mergeIds(settingId, setting, { User: '' as IntlString, Maintainer: '' as IntlString, Owner: '' as IntlString, - Role: '' as IntlString + Role: '' as IntlString, + FailedToSave: '' as IntlString } }) diff --git a/plugins/templates-resources/src/components/Templates.svelte b/plugins/templates-resources/src/components/Templates.svelte index 3234f7166d..0e67461b88 100644 --- a/plugins/templates-resources/src/components/Templates.svelte +++ b/plugins/templates-resources/src/components/Templates.svelte @@ -12,6 +12,7 @@ let templates: MessageTemplate[] = [] let selected: Ref | undefined let newTemplate: Data | undefined = undefined + let loading = true query.query(templatesPlugin.class.MessageTemplate, {}, (t) => { templates = t @@ -19,6 +20,7 @@ selected = undefined newTemplate = undefined } + loading = false }) const Mode = { @@ -79,7 +81,9 @@
diff --git a/plugins/workbench-resources/src/components/Workbench.svelte b/plugins/workbench-resources/src/components/Workbench.svelte index b40b181f72..1ec5f25ffa 100644 --- a/plugins/workbench-resources/src/components/Workbench.svelte +++ b/plugins/workbench-resources/src/components/Workbench.svelte @@ -488,14 +488,14 @@ }} > {#if currentApplication && currentApplication.component} - + {:else if specialComponent} {:else if currentView?.component !== undefined} - + {:else} {/if} diff --git a/server/account/src/index.ts b/server/account/src/index.ts index b9ea6f8072..fe1a5bac81 100644 --- a/server/account/src/index.ts +++ b/server/account/src/index.ts @@ -543,6 +543,21 @@ export async function changePassword (db: Db, token: string, oldPassword: string await db.collection(ACCOUNT_COLLECTION).updateOne({ _id: account._id }, { $set: { salt, hash } }) } +/** + * @public + */ +export async function replacePassword (db: Db, email: string, password: string): Promise { + const account = await getAccount(db, email) + + if (account === null) { + throw new PlatformError(new Status(Severity.ERROR, accountPlugin.status.InvalidPassword, { account: email })) + } + const salt = randomBytes(32) + const hash = hashWithSalt(password, salt) + + await db.collection(ACCOUNT_COLLECTION).updateOne({ _id: account._id }, { $set: { salt, hash } }) +} + /** * @public */