create object
This commit is contained in:
parent
bbe5e468ce
commit
9d74f34b9a
@ -32,6 +32,12 @@ export type AccessToken = {
|
|||||||
user_id: string
|
user_id: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type UserInfo = {
|
||||||
|
admin: boolean
|
||||||
|
displayname: string
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
|
||||||
export function mapUser(rcUser: RcUser): MatrixUser {
|
export function mapUser(rcUser: RcUser): MatrixUser {
|
||||||
return {
|
return {
|
||||||
user_id: '',
|
user_id: '',
|
||||||
@ -75,10 +81,8 @@ async function registerUser(user: MatrixUser): Promise<AccessToken> {
|
|||||||
return (await axios.post('/_synapse/admin/v1/register', user)).data
|
return (await axios.post('/_synapse/admin/v1/register', user)).data
|
||||||
}
|
}
|
||||||
|
|
||||||
async function userAlreadyExists(user: MatrixUser): Promise<boolean> {
|
async function getUserData(user: MatrixUser): Promise<UserInfo> {
|
||||||
const user_data = (await axios.get('/_synapse/admin/v2/users/@' + user.username + ":" + getUserDomain())).data
|
return (await axios.get('/_synapse/admin/v2/users/@' + user.username + ":" + getUserDomain())).data
|
||||||
log.debug(`Mapping exists:`, user_data)
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function parseUserMemberships(rcUser: RcUser): Promise<void> {
|
async function parseUserMemberships(rcUser: RcUser): Promise<void> {
|
||||||
@ -123,9 +127,11 @@ export async function createMapping(
|
|||||||
|
|
||||||
export async function createUser(rcUser: RcUser): Promise<MatrixUser> {
|
export async function createUser(rcUser: RcUser): Promise<MatrixUser> {
|
||||||
const user = mapUser(rcUser)
|
const user = mapUser(rcUser)
|
||||||
if (await userAlreadyExists(user)) {
|
try {
|
||||||
log.info(`User ${rcUser.username} exists:`, user)
|
const user_data = await getUserData(user)
|
||||||
} else {
|
|
||||||
|
log.info(`User ${rcUser.username} exists:`, user_data)
|
||||||
|
} catch (error) {
|
||||||
const nonce = await getUserRegistrationNonce()
|
const nonce = await getUserRegistrationNonce()
|
||||||
const mac = generateHmac({ ...user, nonce })
|
const mac = generateHmac({ ...user, nonce })
|
||||||
const accessToken = await registerUser({ ...user, nonce, mac })
|
const accessToken = await registerUser({ ...user, nonce, mac })
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user