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/next/pages/api/v2/accounts/set-password.ts
Views: 687
1
/*
2
Set password for an existing account.
3
*/
4
5
import setPassword from "@cocalc/server/accounts/set-password";
6
import getAccountId from "lib/account/get-account";
7
import getParams from "lib/api/get-params";
8
9
import { apiRoute, apiRouteOperation } from "lib/api";
10
import { SuccessStatus } from "lib/api/status";
11
import {
12
SetAccountPasswordInputSchema,
13
SetAccountPasswordOutputSchema,
14
} from "lib/api/schema/accounts/set-password";
15
16
async function handle(req, res) {
17
const account_id = await getAccountId(req);
18
if (account_id == null) {
19
res.json({ error: "must be signed in" });
20
return;
21
}
22
const { currentPassword, newPassword } = getParams(req);
23
try {
24
await setPassword(account_id, currentPassword, newPassword);
25
res.json(SuccessStatus);
26
} catch (err) {
27
res.json({ error: err.message });
28
}
29
}
30
31
export default apiRoute({
32
setPassword: apiRouteOperation({
33
method: "POST",
34
openApiOperation: {
35
tags: ["Accounts"],
36
},
37
})
38
.input({
39
contentType: "application/json",
40
body: SetAccountPasswordInputSchema,
41
})
42
.outputs([
43
{
44
status: 200,
45
contentType: "application/json",
46
body: SetAccountPasswordOutputSchema,
47
},
48
])
49
.handler(handle),
50
});
51
52