CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/client/admin.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import * as message from "@cocalc/util/message";
7
import { AsyncCall } from "./client";
8
import api from "./api";
9
10
export class AdminClient {
11
private async_call: AsyncCall;
12
13
constructor(async_call: AsyncCall) {
14
this.async_call = async_call;
15
}
16
17
public async admin_reset_password(email_address: string): Promise<string> {
18
return (
19
await this.async_call({
20
message: message.admin_reset_password({
21
email_address,
22
}),
23
allow_post: true,
24
})
25
).link;
26
}
27
28
public async admin_ban_user(
29
account_id: string,
30
ban: boolean = true, // if true, ban user -- if false, remove ban
31
): Promise<void> {
32
if (ban) {
33
await api("/accounts/ban", { account_id });
34
} else {
35
await api("/accounts/remove-ban", { account_id });
36
}
37
}
38
39
public async get_user_auth_token(account_id: string): Promise<string> {
40
return (
41
await this.async_call({
42
message: message.user_auth({ account_id, password: "" }),
43
allow_post: false,
44
})
45
).auth_token;
46
}
47
}
48
49