mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-27 03:54:57 +02:00
@@ -1,18 +1,18 @@
|
||||
import { Analytics } from '@hcengineering/analytics'
|
||||
import client from '@hcengineering/client'
|
||||
import { setCurrentEmployee, type Employee } from '@hcengineering/contact'
|
||||
import core, {
|
||||
type Account,
|
||||
ClientConnectEvent,
|
||||
concatLink,
|
||||
setCurrentAccount,
|
||||
versionToString,
|
||||
type Account,
|
||||
type Client,
|
||||
type Version,
|
||||
type PersonId,
|
||||
type Ref,
|
||||
type PersonId
|
||||
type Version
|
||||
} from '@hcengineering/core'
|
||||
import { setCurrentEmployee, type Employee } from '@hcengineering/contact'
|
||||
import login, { loginId } from '@hcengineering/login'
|
||||
import login from '@hcengineering/login'
|
||||
import { getMetadata, getResource, setMetadata } from '@hcengineering/platform'
|
||||
import presentation, {
|
||||
loadServerConfig,
|
||||
@@ -21,9 +21,9 @@ import presentation, {
|
||||
setPresentationCookie,
|
||||
upgradeDownloadProgress
|
||||
} from '@hcengineering/presentation'
|
||||
import { desktopPlatform, getCurrentLocation, navigate } from '@hcengineering/ui'
|
||||
import { desktopPlatform, getCurrentLocation } from '@hcengineering/ui'
|
||||
import { logOut } from '@hcengineering/workbench'
|
||||
import { writable, get } from 'svelte/store'
|
||||
import { get, writable } from 'svelte/store'
|
||||
|
||||
export const versionError = writable<string | undefined>(undefined)
|
||||
|
||||
|
||||
@@ -300,17 +300,13 @@ export async function getAccount (doNavigate: boolean = true): Promise<LoginInfo
|
||||
|
||||
if (err.status.code === platform.status.Unauthorized) {
|
||||
setMetadata(presentation.metadata.Token, null)
|
||||
setMetadata(presentation.metadata.Workspace, null)
|
||||
setMetadata(presentation.metadata.WorkspaceId, null)
|
||||
setMetadataLocalStorage(login.metadata.LastToken, null)
|
||||
setMetadataLocalStorage(login.metadata.LoginEndpoint, null)
|
||||
setMetadataLocalStorage(login.metadata.LoginEmail, null)
|
||||
|
||||
|
||||
const loc = getCurrentLocation()
|
||||
loc.path[1] = 'login'
|
||||
loc.path.length = 2
|
||||
navigate(loc)
|
||||
return
|
||||
return null
|
||||
}
|
||||
|
||||
return null
|
||||
@@ -473,7 +469,7 @@ export function navigateToWorkspace (
|
||||
const newLoc: Location = { path: [workbenchId, workspaceUrl] }
|
||||
let last: Location | undefined
|
||||
try {
|
||||
last = JSON.parse(localStorage.getItem(`${locationStorageKeyId}_${workspace}`) ?? '')
|
||||
last = JSON.parse(localStorage.getItem(`${locationStorageKeyId}_${workspaceUrl}`) ?? '')
|
||||
} catch (err: any) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import type { PersonUuid, WorkspaceUuid } from '@hcengineering/core'
|
||||
import { generateToken } from '@hcengineering/server-token'
|
||||
|
||||
export function decodeTokenPayload (token: string): any {
|
||||
@@ -27,12 +28,14 @@ export function decodeTokenPayload (token: string): any {
|
||||
describe('generate-tokens', () => {
|
||||
it('should generate tokens', async () => {
|
||||
const extra: Record<string, any> = { confirmed: 'true' }
|
||||
const token = generateToken('mike@some.host', { name: '' }, extra, 'secret')
|
||||
const token = generateToken('mike@some.host' as PersonUuid, '' as WorkspaceUuid, extra, 'secret')
|
||||
console.log(token)
|
||||
const decodedPayload = decodeTokenPayload(token)
|
||||
expect(decodedPayload).toEqual({
|
||||
confirmed: 'true',
|
||||
email: 'mike@some.host',
|
||||
extra: {
|
||||
confirmed: 'true'
|
||||
},
|
||||
account: 'mike@some.host',
|
||||
workspace: ''
|
||||
})
|
||||
expect(decodedPayload.admin).not.toBe('true')
|
||||
|
||||
@@ -413,10 +413,13 @@ export async function createInviteLink (
|
||||
}
|
||||
|
||||
// TODO: Temporary solution to prevent spam using sendInvite
|
||||
const invitesSend = new Map<string, {
|
||||
const invitesSend = new Map<
|
||||
string,
|
||||
{
|
||||
lastSend: number
|
||||
totalSend: number
|
||||
}>()
|
||||
}
|
||||
>()
|
||||
|
||||
export async function sendInvite (
|
||||
ctx: MeasureContext,
|
||||
@@ -460,7 +463,7 @@ function checkRateLimit (email: string, workspaceName: string): void {
|
||||
if (lastInvites !== undefined) {
|
||||
lastInvites.totalSend++
|
||||
lastInvites.lastSend = now
|
||||
if (lastInvites.totalSend > 5 && (now - lastInvites.lastSend) < 60 * 1000) {
|
||||
if (lastInvites.totalSend > 5 && now - lastInvites.lastSend < 60 * 1000) {
|
||||
// Less 60 seconds between invites
|
||||
throw new PlatformError(
|
||||
new Status(Severity.ERROR, platform.status.WorkspaceRateLimit, { workspace: workspaceName })
|
||||
|
||||
Reference in New Issue
Block a user