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