Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/util/db-schema/registration-tokens.ts
5963 views
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
ephemeral: null,
44
customize: null,
45
} as { [key in RegistrationTokenSetFields]: null },
46
},
47
get: {
48
admin: true,
49
instead_of_query,
50
pg_where: [], // no limits
51
fields: {
52
token: null,
53
descr: null,
54
expires: null,
55
counter: null,
56
limit: null,
57
disabled: null,
58
ephemeral: null,
59
customize: null,
60
} as { [key in RegistrationTokenGetFields]: null },
61
},
62
},
63
},
64
fields: {
65
token: { type: "string" },
66
descr: { type: "string" },
67
counter: { type: "number", desc: "how many accounts are created" },
68
expires: {
69
type: "timestamp",
70
desc: "optional – the time, when this token is no longer valid",
71
},
72
limit: { type: "number", desc: "optional – maximum number of accounts" },
73
disabled: { type: "boolean", desc: "set to true to disable this token" },
74
ephemeral: {
75
type: "number",
76
desc: "optional – lifetime in milliseconds for accounts/projects created via this token",
77
},
78
customize: {
79
type: "map",
80
desc: "Optional account customization overrides applied when redeeming this token.",
81
},
82
},
83
});
84
85