store user account

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov 2021-08-24 20:42:32 +02:00
parent 011e46af6a
commit e2b336d017
No known key found for this signature in database
GPG Key ID: C8787EFEB4B64AF0
8 changed files with 33 additions and 12 deletions

View File

@ -14,8 +14,8 @@
//
import { mergeIds } from '@anticrm/platform'
import type { Ref, Class, Space } from '@anticrm/core'
import contact, { contactId, Employee } from '@anticrm/contact'
import type { Ref, Space } from '@anticrm/core'
import contact, { contactId } from '@anticrm/contact'
import type { AnyComponent } from '@anticrm/ui'
import {} from '@anticrm/core'
@ -24,7 +24,6 @@ export const ids = mergeIds(contactId, contact, {
PersonPresenter: '' as AnyComponent
},
class: {
Employee: '' as Ref<Class<Employee>>
},
space: {
Employee: '' as Ref<Space>

View File

@ -57,6 +57,7 @@ export default plugin(contactId, {
class: {
Contact: '' as Ref<Class<Contact>>,
Person: '' as Ref<Class<Person>>,
Organization: '' as Ref<Class<Organization>>
Organization: '' as Ref<Class<Organization>>,
Employee: '' as Ref<Class<Employee>>
}
})

View File

@ -56,6 +56,7 @@
console.log('token', result.token)
setMetadataLocalStorage(login.metadata.LoginToken, result.token)
setMetadataLocalStorage(login.metadata.LoginEndpoint, result.endpoint)
setMetadataLocalStorage(login.metadata.LoginEmail, result.email)
navigate({ path: [workbench.component.WorkbenchApp] })
}
}

View File

@ -21,13 +21,14 @@ import login from '@anticrm/login'
export interface LoginInfo {
token: string
endpoint: string
email: string
}
/**
* Perform a login operation to required workspace with user credentials.
*/
export async function doLogin (
username: string,
email: string,
password: string,
workspace: string
): Promise<[Status, LoginInfo | undefined]> {
@ -41,13 +42,13 @@ export async function doLogin (
if (token !== undefined) {
const endpoint = getMetadata(login.metadata.OverrideEndpoint)
if (endpoint !== undefined) {
return [OK, { token, endpoint }]
return [OK, { token, endpoint, email }]
}
}
const request: Request<[string, string, string]> = {
method: 'login',
params: [username, password, workspace]
params: [email, password, workspace]
}
try {

View File

@ -40,6 +40,7 @@ export default plugin(loginId, {
UploadUrl: '' as Asset,
LoginToken: '' as Metadata<string>,
LoginEndpoint: '' as Metadata<string>,
LoginEmail: '' as Metadata<string>,
OverrideLoginToken: '' as Metadata<string>, // debug purposes
OverrideEndpoint: '' as Metadata<string>
},

View File

@ -27,6 +27,7 @@
"@anticrm/ui": "~0.6.0",
"@anticrm/view": "~0.6.0",
"@anticrm/presentation": "~0.6.1",
"@anticrm/login": "~0.6.1"
"@anticrm/login": "~0.6.1",
"@anticrm/contact": "~0.6.0"
}
}

View File

@ -21,20 +21,28 @@ import { navigate, Loading, fetchMetadataLocalStorage } from '@anticrm/ui'
import client from '@anticrm/client'
import login from '@anticrm/login'
import contact from '@anticrm/contact'
import Workbench from './Workbench.svelte'
import { setCurrentAccount } from '../utils'
async function connect(): Promise<Client | undefined> {
const token = fetchMetadataLocalStorage(login.metadata.LoginToken)
const endpoint = fetchMetadataLocalStorage(login.metadata.LoginEndpoint)
const email = fetchMetadataLocalStorage(login.metadata.LoginEmail)
if (token === null || endpoint === null) {
if (token === null || endpoint === null || email === null) {
navigate({ path: [login.component.LoginApp] })
return
}
const getClient = await getResource(client.function.GetClient)
return getClient(token, endpoint)
const instance = await getClient(token, endpoint)
const me = (await instance.findAll(contact.class.Employee, { email }))[0]
if (me !== undefined) {
setCurrentAccount(me._id)
}
return instance
}
</script>

View File

@ -14,11 +14,20 @@
// limitations under the License.
//
import type { Ref, Obj, Class, WithLookup } from '@anticrm/core'
import type { Asset, IntlString } from '@anticrm/platform'
import type { Ref, Obj, Class } from '@anticrm/core'
import type { Asset } from '@anticrm/platform'
import type { Client } from '@anticrm/core'
import type { Employee } from '@anticrm/contact'
export function classIcon(client: Client, _class: Ref<Class<Obj>>): Asset | undefined {
return client.getHierarchy().getClass(_class).icon
}
let currentAccount: Ref<Employee>
export function getCurrentAccount(): Ref<Employee> { return currentAccount }
export function setCurrentAccount(account: Ref<Employee>): void {
currentAccount = account
console.log('current account', currentAccount)
}