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/util/db-schema/registration-tokens.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
// An account token is a piece of additional information,
7
// which might be necessary to create an account.
8
// In the future, this might be extended to dispatch some action,
9
// like adding a student to a course, similar to account creation actions.
10
11
import {
12
Table,
13
RegistrationTokenSetFields,
14
RegistrationTokenGetFields,
15
} from "./types";
16
17
// this covers 3 cases: selecting all, updating one, and deleting one
18
async function instead_of_query(db, opts: any, cb: Function): Promise<void> {
19
const { options, query } = opts;
20
try {
21
cb(undefined, await db.registrationTokens(options, query));
22
} catch (err) {
23
cb(err);
24
}
25
}
26
27
Table({
28
name: "registration_tokens",
29
rules: {
30
primary_key: "token",
31
anonymous: false,
32
user_query: {
33
set: {
34
admin: true,
35
instead_of_query,
36
delete: true,
37
fields: {
38
token: null,
39
descr: null,
40
expires: null,
41
limit: null,
42
disabled: null,
43
} as { [key in RegistrationTokenSetFields]: null },
44
},
45
get: {
46
admin: true,
47
instead_of_query,
48
pg_where: [], // no limits
49
fields: {
50
token: null,
51
descr: null,
52
expires: null,
53
counter: null,
54
limit: null,
55
disabled: null,
56
} as { [key in RegistrationTokenGetFields]: null },
57
},
58
},
59
},
60
fields: {
61
token: { type: "string" },
62
descr: { type: "string" },
63
counter: { type: "number", desc: "how many accounts are created" },
64
expires: {
65
type: "timestamp",
66
desc: "optional – the time, when this token is no longer valid",
67
},
68
limit: { type: "number", desc: "optional – maximum number of accounts" },
69
disabled: { type: "boolean", desc: "set to true to disable this token" },
70
},
71
});
72
73