1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-05 10:22:31 +01:00

oapi: finish users

This commit is contained in:
Puyodead1 2023-03-25 18:01:56 -04:00
parent 1ce7879ee8
commit 860b9d583e
No known key found for this signature in database
GPG Key ID: A4FA4FEC0DD353FC
14 changed files with 14995 additions and 71 deletions

View File

@ -3865,6 +3865,33 @@
"width"
]
},
"BackupCode": {
"type": "object",
"properties": {
"user": {
"$ref": "#/components/schemas/User"
},
"code": {
"type": "string"
},
"consumed": {
"type": "boolean"
},
"expired": {
"type": "boolean"
},
"id": {
"type": "string"
}
},
"required": [
"code",
"consumed",
"expired",
"id",
"user"
]
},
"PublicConnectedAccount": {
"type": "object",
"properties": {
@ -6599,6 +6626,35 @@
"token"
]
},
"TokenOnlyResponse": {
"type": "object",
"properties": {
"token": {
"type": "string"
}
},
"required": [
"token"
]
},
"TokenWithBackupCodesResponse": {
"type": "object",
"properties": {
"token": {
"type": "string"
},
"backup_codes": {
"type": "array",
"items": {
"$ref": "#/components/schemas/BackupCode"
}
}
},
"required": [
"backup_codes",
"token"
]
},
"UserNoteResponse": {
"type": "object",
"properties": {
@ -6918,28 +6974,24 @@
}
},
"UserBackupCodesResponse": {
"type": "array",
"items": {
"$ref": "#/components/schemas/BackupCode"
}
},
"WebAuthnCreateResponse": {
"type": "object",
"properties": {
"expired": {},
"user": {
"$ref": "#/components/schemas/User"
},
"code": {
"name": {
"type": "string"
},
"consumed": {
"type": "boolean"
},
"id": {
"type": "string"
}
},
"required": [
"code",
"consumed",
"expired",
"id",
"user"
"name"
]
},
"WebhookCreateResponse": {
@ -7347,8 +7399,25 @@
}
},
"responses": {
"default": {
"description": "No description available"
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/WebAuthnCreateResponse"
}
}
}
},
"400": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/APIErrorResponse"
}
}
}
}
},
"tags": [
@ -7364,7 +7433,7 @@
}
],
"responses": {
"default": {
"204": {
"description": "No description available"
}
},
@ -7402,8 +7471,35 @@
}
},
"responses": {
"default": {
"description": "No description available"
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/TokenWithBackupCodesResponse"
}
}
}
},
"400": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/APIErrorResponse"
}
}
}
},
"404": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/APIErrorResponse"
}
}
}
}
},
"tags": [
@ -7429,8 +7525,25 @@
}
},
"responses": {
"default": {
"description": "No description available"
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/TokenOnlyResponse"
}
}
}
},
"400": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/APIErrorResponse"
}
}
}
}
},
"tags": [
@ -7726,8 +7839,28 @@
}
},
"responses": {
"default": {
"200": {
"description": "No description available"
},
"400": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/APIErrorResponse"
}
}
}
},
"404": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/APIErrorResponse"
}
}
}
}
},
"parameters": [
@ -12327,7 +12460,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/TokenResponse"
"$ref": "#/components/schemas/TokenOnlyResponse"
}
}
}
@ -12366,7 +12499,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/TokenResponse"
"$ref": "#/components/schemas/TokenOnlyResponse"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -35,8 +35,8 @@ router.post(
"/",
route({
responses: {
200: {
body: "TokenResponse",
204: {
body: "TokenOnlyResponse",
},
400: {
body: "APIErrorResponse",

View File

@ -45,7 +45,7 @@ router.post(
route({
requestBody: "RegisterSchema",
responses: {
200: { body: "TokenResponse" },
200: { body: "TokenOnlyResponse" },
400: { body: "APIErrorOrCaptchaResponse" },
},
}),

View File

@ -38,7 +38,7 @@ router.post(
requestBody: "PasswordResetSchema",
responses: {
200: {
body: "TokenResponse",
body: "TokenOnlyResponse",
},
400: {
body: "APIErrorOrCaptchaResponse",

View File

@ -28,17 +28,37 @@ import { Request, Response, Router } from "express";
const router = Router();
// GET doesn't exist on discord.com
router.get("/", route({}), async (req: Request, res: Response) => {
const user = await Member.findOneOrFail({
where: { id: req.user_id, guild_id: req.params.guild_id },
select: ["settings"],
});
return res.json(user.settings);
});
router.get(
"/",
route({
responses: {
200: {},
404: {},
},
}),
async (req: Request, res: Response) => {
const user = await Member.findOneOrFail({
where: { id: req.user_id, guild_id: req.params.guild_id },
select: ["settings"],
});
return res.json(user.settings);
},
);
router.patch(
"/",
route({ requestBody: "UserGuildSettingsSchema" }),
route({
requestBody: "UserGuildSettingsSchema",
responses: {
200: {},
400: {
body: "APIErrorResponse",
},
404: {
body: "APIErrorResponse",
},
},
}),
async (req: Request, res: Response) => {
const body = req.body as UserGuildSettingsSchema;

View File

@ -31,7 +31,17 @@ const router = Router();
router.post(
"/",
route({ requestBody: "TotpDisableSchema" }),
route({
requestBody: "TotpDisableSchema",
responses: {
200: {
body: "TokenOnlyResponse",
},
400: {
body: "APIErrorResponse",
},
},
}),
async (req: Request, res: Response) => {
const body = req.body as TotpDisableSchema;

View File

@ -32,7 +32,20 @@ const router = Router();
router.post(
"/",
route({ requestBody: "TotpEnableSchema" }),
route({
requestBody: "TotpEnableSchema",
responses: {
200: {
body: "TokenWithBackupCodesResponse",
},
400: {
body: "APIErrorResponse",
},
404: {
body: "APIErrorResponse",
},
},
}),
async (req: Request, res: Response) => {
const body = req.body as TotpEnableSchema;

View File

@ -21,21 +21,31 @@ import { SecurityKey, User } from "@spacebar/util";
import { Request, Response, Router } from "express";
const router = Router();
router.delete("/", route({}), async (req: Request, res: Response) => {
const { key_id } = req.params;
router.delete(
"/",
route({
responses: {
204: {},
},
}),
async (req: Request, res: Response) => {
const { key_id } = req.params;
await SecurityKey.delete({
id: key_id,
user_id: req.user_id,
});
await SecurityKey.delete({
id: key_id,
user_id: req.user_id,
});
const keys = await SecurityKey.count({ where: { user_id: req.user_id } });
const keys = await SecurityKey.count({
where: { user_id: req.user_id },
});
// disable webauthn if there are no keys left
if (keys === 0)
await User.update({ id: req.user_id }, { webauthn_enabled: false });
// disable webauthn if there are no keys left
if (keys === 0)
await User.update({ id: req.user_id }, { webauthn_enabled: false });
res.sendStatus(204);
});
res.sendStatus(204);
},
);
export default router;

View File

@ -73,7 +73,17 @@ router.get("/", route({}), async (req: Request, res: Response) => {
router.post(
"/",
route({ requestBody: "WebAuthnPostSchema" }),
route({
requestBody: "WebAuthnPostSchema",
responses: {
200: {
body: "WebAuthnCreateResponse",
},
400: {
body: "APIErrorResponse",
},
},
}),
async (req: Request, res: Response) => {
if (!WebAuthn.fido2) {
// TODO: I did this for typescript and I can't use !

View File

@ -1,6 +1,15 @@
import { UserSettings } from "../../entities";
import { BackupCode, UserSettings } from "../../entities";
export interface TokenResponse {
token: string;
settings: UserSettings;
}
export interface TokenOnlyResponse {
token: string;
}
export interface TokenWithBackupCodesResponse {
token: string;
backup_codes: BackupCode[];
}

View File

@ -1,5 +1,5 @@
import { DmChannelDTO } from "../../dtos";
import { Guild, PrivateUser, PublicUser, User } from "../../entities";
import { BackupCode, Guild, PrivateUser, PublicUser } from "../../entities";
export type PublicUserResponse = PublicUser;
export type PrivateUserResponse = PrivateUser;
@ -12,11 +12,4 @@ export type UserGuildsResponse = Guild[];
export type UserChannelsResponse = DmChannelDTO[];
export interface UserBackupCodesResponse {
expired: unknown;
user: User;
code: string;
consumed: boolean;
id: string;
}
[];
export type UserBackupCodesResponse = BackupCode[];

View File

@ -0,0 +1,4 @@
export interface WebAuthnCreateResponse {
name: string;
id: string;
}

View File

@ -44,4 +44,5 @@ export * from "./UserProfileResponse";
export * from "./UserRelationshipsResponse";
export * from "./UserRelationsResponse";
export * from "./UserResponse";
export * from "./WebAuthnCreateResponse";
export * from "./WebhookCreateResponse";