mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
32 lines
997 B
TypeScript
32 lines
997 B
TypeScript
import { apiPost } from '../../apis/HttpRequest'
|
|
import CONFIG from '../../config'
|
|
import { isHexPublicKey } from '../../util/validate'
|
|
|
|
// target can be email, username or public_key
|
|
// groupId if not null and another community, try to get public key from there
|
|
export default async function getPublicKey(target: string, sessionId:number, groupId: number = 0): Promise<string | undefined>
|
|
{
|
|
// if it is already a public key, return it
|
|
if(isHexPublicKey(target)) {
|
|
return target
|
|
}
|
|
|
|
// assume it is a email address if it's contain a @
|
|
if(/@/i.test(target)) {
|
|
const result = await apiPost(CONFIG.LOGIN_API_URL + 'getUserInfos', {
|
|
session_id: sessionId,
|
|
email: target,
|
|
ask: ['user.pubkeyhex']
|
|
})
|
|
if (result.success) {
|
|
return result.data.userData.pubkeyhex
|
|
}
|
|
}
|
|
|
|
// if username is used add code here
|
|
|
|
// if we have multiple communities add code here
|
|
|
|
return undefined
|
|
|
|
} |