oapi: finish users
This commit is contained in:
parent
1ce7879ee8
commit
860b9d583e
@ -3865,6 +3865,33 @@
|
|||||||
"width"
|
"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": {
|
"PublicConnectedAccount": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@ -6599,6 +6626,35 @@
|
|||||||
"token"
|
"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": {
|
"UserNoteResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@ -6918,28 +6974,24 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"UserBackupCodesResponse": {
|
"UserBackupCodesResponse": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/BackupCode"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"WebAuthnCreateResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"expired": {},
|
"name": {
|
||||||
"user": {
|
|
||||||
"$ref": "#/components/schemas/User"
|
|
||||||
},
|
|
||||||
"code": {
|
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"consumed": {
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"id": {
|
"id": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"code",
|
|
||||||
"consumed",
|
|
||||||
"expired",
|
|
||||||
"id",
|
"id",
|
||||||
"user"
|
"name"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"WebhookCreateResponse": {
|
"WebhookCreateResponse": {
|
||||||
@ -7347,8 +7399,25 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"responses": {
|
"responses": {
|
||||||
"default": {
|
"200": {
|
||||||
"description": "No description available"
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/WebAuthnCreateResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/APIErrorResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tags": [
|
"tags": [
|
||||||
@ -7364,7 +7433,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"default": {
|
"204": {
|
||||||
"description": "No description available"
|
"description": "No description available"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -7402,8 +7471,35 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"responses": {
|
"responses": {
|
||||||
"default": {
|
"200": {
|
||||||
"description": "No description available"
|
"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": [
|
"tags": [
|
||||||
@ -7429,8 +7525,25 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"responses": {
|
"responses": {
|
||||||
"default": {
|
"200": {
|
||||||
"description": "No description available"
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/TokenOnlyResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/APIErrorResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tags": [
|
"tags": [
|
||||||
@ -7726,8 +7839,28 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"responses": {
|
"responses": {
|
||||||
"default": {
|
"200": {
|
||||||
"description": "No description available"
|
"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": [
|
"parameters": [
|
||||||
@ -12327,7 +12460,7 @@
|
|||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/components/schemas/TokenResponse"
|
"$ref": "#/components/schemas/TokenOnlyResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -12366,7 +12499,7 @@
|
|||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/components/schemas/TokenResponse"
|
"$ref": "#/components/schemas/TokenOnlyResponse"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14723
assets/schemas.json
14723
assets/schemas.json
File diff suppressed because it is too large
Load Diff
@ -35,8 +35,8 @@ router.post(
|
|||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
204: {
|
||||||
body: "TokenResponse",
|
body: "TokenOnlyResponse",
|
||||||
},
|
},
|
||||||
400: {
|
400: {
|
||||||
body: "APIErrorResponse",
|
body: "APIErrorResponse",
|
||||||
|
@ -45,7 +45,7 @@ router.post(
|
|||||||
route({
|
route({
|
||||||
requestBody: "RegisterSchema",
|
requestBody: "RegisterSchema",
|
||||||
responses: {
|
responses: {
|
||||||
200: { body: "TokenResponse" },
|
200: { body: "TokenOnlyResponse" },
|
||||||
400: { body: "APIErrorOrCaptchaResponse" },
|
400: { body: "APIErrorOrCaptchaResponse" },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
@ -38,7 +38,7 @@ router.post(
|
|||||||
requestBody: "PasswordResetSchema",
|
requestBody: "PasswordResetSchema",
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
body: "TokenResponse",
|
body: "TokenOnlyResponse",
|
||||||
},
|
},
|
||||||
400: {
|
400: {
|
||||||
body: "APIErrorOrCaptchaResponse",
|
body: "APIErrorOrCaptchaResponse",
|
||||||
|
@ -28,17 +28,37 @@ import { Request, Response, Router } from "express";
|
|||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
// GET doesn't exist on discord.com
|
// GET doesn't exist on discord.com
|
||||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
router.get(
|
||||||
|
"/",
|
||||||
|
route({
|
||||||
|
responses: {
|
||||||
|
200: {},
|
||||||
|
404: {},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
async (req: Request, res: Response) => {
|
||||||
const user = await Member.findOneOrFail({
|
const user = await Member.findOneOrFail({
|
||||||
where: { id: req.user_id, guild_id: req.params.guild_id },
|
where: { id: req.user_id, guild_id: req.params.guild_id },
|
||||||
select: ["settings"],
|
select: ["settings"],
|
||||||
});
|
});
|
||||||
return res.json(user.settings);
|
return res.json(user.settings);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({ requestBody: "UserGuildSettingsSchema" }),
|
route({
|
||||||
|
requestBody: "UserGuildSettingsSchema",
|
||||||
|
responses: {
|
||||||
|
200: {},
|
||||||
|
400: {
|
||||||
|
body: "APIErrorResponse",
|
||||||
|
},
|
||||||
|
404: {
|
||||||
|
body: "APIErrorResponse",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const body = req.body as UserGuildSettingsSchema;
|
const body = req.body as UserGuildSettingsSchema;
|
||||||
|
|
||||||
|
@ -31,7 +31,17 @@ const router = Router();
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({ requestBody: "TotpDisableSchema" }),
|
route({
|
||||||
|
requestBody: "TotpDisableSchema",
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
body: "TokenOnlyResponse",
|
||||||
|
},
|
||||||
|
400: {
|
||||||
|
body: "APIErrorResponse",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const body = req.body as TotpDisableSchema;
|
const body = req.body as TotpDisableSchema;
|
||||||
|
|
||||||
|
@ -32,7 +32,20 @@ const router = Router();
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({ requestBody: "TotpEnableSchema" }),
|
route({
|
||||||
|
requestBody: "TotpEnableSchema",
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
body: "TokenWithBackupCodesResponse",
|
||||||
|
},
|
||||||
|
400: {
|
||||||
|
body: "APIErrorResponse",
|
||||||
|
},
|
||||||
|
404: {
|
||||||
|
body: "APIErrorResponse",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const body = req.body as TotpEnableSchema;
|
const body = req.body as TotpEnableSchema;
|
||||||
|
|
||||||
|
@ -21,7 +21,14 @@ import { SecurityKey, User } from "@spacebar/util";
|
|||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.delete("/", route({}), async (req: Request, res: Response) => {
|
router.delete(
|
||||||
|
"/",
|
||||||
|
route({
|
||||||
|
responses: {
|
||||||
|
204: {},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
async (req: Request, res: Response) => {
|
||||||
const { key_id } = req.params;
|
const { key_id } = req.params;
|
||||||
|
|
||||||
await SecurityKey.delete({
|
await SecurityKey.delete({
|
||||||
@ -29,13 +36,16 @@ router.delete("/", route({}), async (req: Request, res: Response) => {
|
|||||||
user_id: req.user_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
|
// disable webauthn if there are no keys left
|
||||||
if (keys === 0)
|
if (keys === 0)
|
||||||
await User.update({ id: req.user_id }, { webauthn_enabled: false });
|
await User.update({ id: req.user_id }, { webauthn_enabled: false });
|
||||||
|
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -73,7 +73,17 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({ requestBody: "WebAuthnPostSchema" }),
|
route({
|
||||||
|
requestBody: "WebAuthnPostSchema",
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
body: "WebAuthnCreateResponse",
|
||||||
|
},
|
||||||
|
400: {
|
||||||
|
body: "APIErrorResponse",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
if (!WebAuthn.fido2) {
|
if (!WebAuthn.fido2) {
|
||||||
// TODO: I did this for typescript and I can't use !
|
// TODO: I did this for typescript and I can't use !
|
||||||
|
@ -1,6 +1,15 @@
|
|||||||
import { UserSettings } from "../../entities";
|
import { BackupCode, UserSettings } from "../../entities";
|
||||||
|
|
||||||
export interface TokenResponse {
|
export interface TokenResponse {
|
||||||
token: string;
|
token: string;
|
||||||
settings: UserSettings;
|
settings: UserSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TokenOnlyResponse {
|
||||||
|
token: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TokenWithBackupCodesResponse {
|
||||||
|
token: string;
|
||||||
|
backup_codes: BackupCode[];
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { DmChannelDTO } from "../../dtos";
|
import { DmChannelDTO } from "../../dtos";
|
||||||
import { Guild, PrivateUser, PublicUser, User } from "../../entities";
|
import { BackupCode, Guild, PrivateUser, PublicUser } from "../../entities";
|
||||||
|
|
||||||
export type PublicUserResponse = PublicUser;
|
export type PublicUserResponse = PublicUser;
|
||||||
export type PrivateUserResponse = PrivateUser;
|
export type PrivateUserResponse = PrivateUser;
|
||||||
@ -12,11 +12,4 @@ export type UserGuildsResponse = Guild[];
|
|||||||
|
|
||||||
export type UserChannelsResponse = DmChannelDTO[];
|
export type UserChannelsResponse = DmChannelDTO[];
|
||||||
|
|
||||||
export interface UserBackupCodesResponse {
|
export type UserBackupCodesResponse = BackupCode[];
|
||||||
expired: unknown;
|
|
||||||
user: User;
|
|
||||||
code: string;
|
|
||||||
consumed: boolean;
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
[];
|
|
||||||
|
4
src/util/schemas/responses/WebAuthnCreateResponse.ts
Normal file
4
src/util/schemas/responses/WebAuthnCreateResponse.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export interface WebAuthnCreateResponse {
|
||||||
|
name: string;
|
||||||
|
id: string;
|
||||||
|
}
|
@ -44,4 +44,5 @@ export * from "./UserProfileResponse";
|
|||||||
export * from "./UserRelationshipsResponse";
|
export * from "./UserRelationshipsResponse";
|
||||||
export * from "./UserRelationsResponse";
|
export * from "./UserRelationsResponse";
|
||||||
export * from "./UserResponse";
|
export * from "./UserResponse";
|
||||||
|
export * from "./WebAuthnCreateResponse";
|
||||||
export * from "./WebhookCreateResponse";
|
export * from "./WebhookCreateResponse";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user