You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
matrix-chat/src/lib/AdminAPI.js

41 lines
1.1 KiB
JavaScript

import rest from 'superagent';
export class AdminAPI{
constructor(baseUrl, accessToken){
this.baseUrl = baseUrl;
this.accessToken = accessToken;
}
async sendRequest({path, obj={}, method=rest=>rest.get}){
return await method(rest)(`${this.baseUrl}${path}?access_token=${this.accessToken}`)
.send(JSON.stringify(obj)).set('accept', 'json').then(res => {
return JSON.parse(res.text);
});
}
async getUsers(){
return await this.sendRequest({path: 'users'});
}
async resetPassword(userId, newPassword){
return await this.sendRequest({
path: `reset_password/${userId}`,
obj: {
new_password: newPassword,
logout_devices: true
}
});
}
async createUser(userId, password, displayName, avatarUrl=undefined){
return await this.sendRequest({
path: `reset_password/${userId}`,
method: rest=>rest.put,
obj: {
'password': password,
'displayname': displayName,
'avatar_url': avatarUrl,
'admin': false,
'deactivated': false
}
});
}
}