mirror of
https://github.com/spacebarchat/server.git
synced 2026-10-23 00:03:05 +00:00
Prettier 1
This commit is contained in:
1 parent
41b700e12a
commit
23ad44a440
22 files changed
+102
-322
No files matched your search
@@ -29,13 +29,11 @@ router.get(
|
||||
query: {
|
||||
count: {
|
||||
type: "number",
|
||||
description:
|
||||
"The number of registration tokens to generate. Defaults to 1.",
|
||||
description: "The number of registration tokens to generate. Defaults to 1.",
|
||||
},
|
||||
length: {
|
||||
type: "number",
|
||||
description:
|
||||
"The length of each registration token. Defaults to 255.",
|
||||
description: "The length of each registration token. Defaults to 255.",
|
||||
},
|
||||
},
|
||||
right: "CREATE_REGISTRATION_TOKENS",
|
||||
@@ -43,20 +41,14 @@ router.get(
|
||||
}),
|
||||
async (req: Request, res: Response) => {
|
||||
const count = req.query.count ? parseInt(req.query.count as string) : 1;
|
||||
const length = req.query.length
|
||||
? parseInt(req.query.length as string)
|
||||
: 255;
|
||||
const length = req.query.length ? parseInt(req.query.length as string) : 255;
|
||||
|
||||
const tokens: ValidRegistrationToken[] = [];
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const token = ValidRegistrationToken.create({
|
||||
token: randomString(length),
|
||||
expires_at: new Date(
|
||||
Date.now() +
|
||||
Config.get().security
|
||||
.defaultRegistrationTokenExpiration,
|
||||
),
|
||||
expires_at: new Date(Date.now() + Config.get().security.defaultRegistrationTokenExpiration),
|
||||
});
|
||||
tokens.push(token);
|
||||
}
|
||||
@@ -68,14 +60,7 @@ router.get(
|
||||
transaction: false,
|
||||
});
|
||||
|
||||
const ret = req.query.include_url
|
||||
? tokens.map(
|
||||
(x) =>
|
||||
`${Config.get().general.frontPage}/register?token=${
|
||||
x.token
|
||||
}`,
|
||||
)
|
||||
: tokens.map((x) => x.token);
|
||||
const ret = req.query.include_url ? tokens.map((x) => `${Config.get().general.frontPage}/register?token=${x.token}`) : tokens.map((x) => x.token);
|
||||
|
||||
if (req.query.plain) return res.send(ret.join("\n"));
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import { BackupCode, User, generateToken } from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { verifyToken } from "node-2fa";
|
||||
import { TotpSchema } from "@spacebar/schemas"
|
||||
import { TotpSchema } from "@spacebar/schemas";
|
||||
const router = Router({ mergeParams: true });
|
||||
|
||||
router.post(
|
||||
@@ -60,11 +60,7 @@ router.post(
|
||||
|
||||
if (!backup) {
|
||||
const ret = verifyToken(user.totp_secret || "", code);
|
||||
if (!ret || ret.delta != 0)
|
||||
throw new HTTPError(
|
||||
req.t("auth:login.INVALID_TOTP_CODE"),
|
||||
60008,
|
||||
);
|
||||
if (!ret || ret.delta != 0) throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
|
||||
} else {
|
||||
backup.consumed = true;
|
||||
await backup.save();
|
||||
|
||||
@@ -17,17 +17,11 @@
|
||||
*/
|
||||
|
||||
import { route } from "@spacebar/api";
|
||||
import {
|
||||
generateToken,
|
||||
SecurityKey,
|
||||
User,
|
||||
verifyWebAuthnToken,
|
||||
WebAuthn,
|
||||
} from "@spacebar/util";
|
||||
import { generateToken, SecurityKey, User, verifyWebAuthnToken, WebAuthn } from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import { ExpectedAssertionResult } from "fido2-lib";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { WebAuthnTotpSchema } from "@spacebar/schemas"
|
||||
import { WebAuthnTotpSchema } from "@spacebar/schemas";
|
||||
const router = Router({ mergeParams: true });
|
||||
|
||||
function toArrayBuffer(buf: Buffer) {
|
||||
@@ -65,46 +59,31 @@ router.post(
|
||||
});
|
||||
|
||||
const ret = await verifyWebAuthnToken(ticket);
|
||||
if (!ret)
|
||||
throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
|
||||
if (!ret) throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
|
||||
|
||||
await User.update({ id: user.id }, { totp_last_ticket: "" });
|
||||
|
||||
const clientAttestationResponse = JSON.parse(code);
|
||||
|
||||
if (!clientAttestationResponse.rawId)
|
||||
throw new HTTPError("Missing rawId", 400);
|
||||
if (!clientAttestationResponse.rawId) throw new HTTPError("Missing rawId", 400);
|
||||
|
||||
clientAttestationResponse.rawId = toArrayBuffer(
|
||||
Buffer.from(clientAttestationResponse.rawId, "base64url"),
|
||||
);
|
||||
clientAttestationResponse.rawId = toArrayBuffer(Buffer.from(clientAttestationResponse.rawId, "base64url"));
|
||||
|
||||
const securityKey = await SecurityKey.findOneOrFail({
|
||||
where: {
|
||||
key_id: Buffer.from(
|
||||
clientAttestationResponse.rawId,
|
||||
"base64url",
|
||||
).toString("base64"),
|
||||
key_id: Buffer.from(clientAttestationResponse.rawId, "base64url").toString("base64"),
|
||||
},
|
||||
});
|
||||
|
||||
const assertionExpectations: ExpectedAssertionResult = JSON.parse(
|
||||
Buffer.from(
|
||||
clientAttestationResponse.response.clientDataJSON,
|
||||
"base64",
|
||||
).toString(),
|
||||
);
|
||||
const assertionExpectations: ExpectedAssertionResult = JSON.parse(Buffer.from(clientAttestationResponse.response.clientDataJSON, "base64").toString());
|
||||
|
||||
const authnResult = await WebAuthn.fido2.assertionResult(
|
||||
clientAttestationResponse,
|
||||
{
|
||||
...assertionExpectations,
|
||||
factor: "second",
|
||||
publicKey: securityKey.public_key,
|
||||
prevCounter: securityKey.counter,
|
||||
userHandle: securityKey.key_id,
|
||||
},
|
||||
);
|
||||
const authnResult = await WebAuthn.fido2.assertionResult(clientAttestationResponse, {
|
||||
...assertionExpectations,
|
||||
factor: "second",
|
||||
publicKey: securityKey.public_key,
|
||||
prevCounter: securityKey.counter,
|
||||
userHandle: securityKey.key_id,
|
||||
});
|
||||
|
||||
const counter = authnResult.authnrData.get("counter");
|
||||
|
||||
|
||||
@@ -17,16 +17,10 @@
|
||||
*/
|
||||
|
||||
import { route } from "@spacebar/api";
|
||||
import {
|
||||
checkToken,
|
||||
Email,
|
||||
FieldErrors,
|
||||
generateToken,
|
||||
User,
|
||||
} from "@spacebar/util";
|
||||
import { checkToken, Email, FieldErrors, generateToken, User } from "@spacebar/util";
|
||||
import bcrypt from "bcrypt";
|
||||
import { Request, Response, Router } from "express";
|
||||
import { PasswordResetSchema } from "@spacebar/schemas"
|
||||
import { PasswordResetSchema } from "@spacebar/schemas";
|
||||
|
||||
const router = Router({ mergeParams: true });
|
||||
|
||||
@@ -52,7 +46,7 @@ router.post(
|
||||
const userTokenData = await checkToken(token, {
|
||||
select: ["email"],
|
||||
fingerprint: req.fingerprint,
|
||||
ipAddress: req.ip
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
user = userTokenData.user;
|
||||
} catch {
|
||||
|
||||
@@ -77,7 +77,7 @@ router.post(
|
||||
try {
|
||||
const userTokenData = await checkToken(token, {
|
||||
fingerprint: req.fingerprint,
|
||||
ipAddress: req.ip
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
user = userTokenData.user;
|
||||
} catch {
|
||||
|
||||
@@ -56,9 +56,7 @@ router.post(
|
||||
return res.sendStatus(204);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error(
|
||||
`Failed to send verification email to ${user.username}#${user.discriminator}: ${e}`,
|
||||
);
|
||||
console.error(`Failed to send verification email to ${user.username}#${user.discriminator}: ${e}`);
|
||||
throw new HTTPError("Failed to send verification email", 500);
|
||||
});
|
||||
},
|
||||
|
||||
@@ -20,7 +20,7 @@ import { route } from "@spacebar/api";
|
||||
import { FieldErrors, User } from "@spacebar/util";
|
||||
import bcrypt from "bcrypt";
|
||||
import { Request, Response, Router } from "express";
|
||||
import { BackupCodesChallengeSchema } from "@spacebar/schemas"
|
||||
import { BackupCodesChallengeSchema } from "@spacebar/schemas";
|
||||
const router = Router({ mergeParams: true });
|
||||
|
||||
router.post(
|
||||
|
||||
Reference in new issue
Block a user