removed icon server and finished profile page
This commit is contained in:
parent
dbe323c77e
commit
763d0c38cc
26 changed files with 881 additions and 325 deletions
|
|
@ -8,6 +8,140 @@
|
|||
"schemas": {}
|
||||
},
|
||||
"paths": {
|
||||
"/api/auth/changePassword": {
|
||||
"post": {
|
||||
"operationId": "changePassword",
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"new_password"
|
||||
],
|
||||
"properties": {
|
||||
"new_password": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Default Response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"kind",
|
||||
"msg"
|
||||
],
|
||||
"properties": {
|
||||
"kind": {
|
||||
"enum": [
|
||||
"success"
|
||||
]
|
||||
},
|
||||
"msg": {
|
||||
"enum": [
|
||||
"changePassword.success"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Default Response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"kind",
|
||||
"msg"
|
||||
],
|
||||
"properties": {
|
||||
"kind": {
|
||||
"enum": [
|
||||
"failed"
|
||||
]
|
||||
},
|
||||
"msg": {
|
||||
"enum": [
|
||||
"changePassword.failed.toolong",
|
||||
"changePassword.failed.tooshort",
|
||||
"changePassword.failed.invalid"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Default Response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"kind",
|
||||
"msg"
|
||||
],
|
||||
"properties": {
|
||||
"kind": {
|
||||
"enum": [
|
||||
"notLoggedIn"
|
||||
]
|
||||
},
|
||||
"msg": {
|
||||
"enum": [
|
||||
"auth.noCookie",
|
||||
"auth.invalidKind",
|
||||
"auth.noUser",
|
||||
"auth.invalid"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Default Response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"kind",
|
||||
"msg"
|
||||
],
|
||||
"properties": {
|
||||
"kind": {
|
||||
"enum": [
|
||||
"failed"
|
||||
]
|
||||
},
|
||||
"msg": {
|
||||
"enum": [
|
||||
"changePassword.failed.generic"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/auth/disableOtp": {
|
||||
"put": {
|
||||
"operationId": "disableOtp",
|
||||
|
|
|
|||
44
src/auth/src/routes/changePassword.ts
Normal file
44
src/auth/src/routes/changePassword.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { FastifyPluginAsync } from 'fastify';
|
||||
|
||||
import { Static, Type } from 'typebox';
|
||||
import { typeResponse, MakeStaticResponse } from '@shared/utils';
|
||||
|
||||
const ChangePasswordReq = Type.Object({
|
||||
new_password: Type.String(),
|
||||
});
|
||||
|
||||
type ChangePasswordReq = Static<typeof ChangePasswordReq>;
|
||||
|
||||
const ChangePasswordRes = {
|
||||
'500': typeResponse('failed',
|
||||
'changePassword.failed.generic'),
|
||||
'400': typeResponse('failed', [
|
||||
'changePassword.failed.toolong',
|
||||
'changePassword.failed.tooshort',
|
||||
'changePassword.failed.invalid',
|
||||
]),
|
||||
'200': typeResponse('success', 'changePassword.success'),
|
||||
};
|
||||
|
||||
type ChangePasswordRes = MakeStaticResponse<typeof ChangePasswordRes>;
|
||||
|
||||
const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
|
||||
void _opts;
|
||||
fastify.post<{ Body: ChangePasswordReq }>(
|
||||
'/api/auth/changePassword',
|
||||
{ schema: { body: ChangePasswordReq, response: ChangePasswordRes, operationId: 'changePassword' }, config: { requireAuth: true } },
|
||||
async function(req, res) {
|
||||
const password = req.body.new_password;
|
||||
|
||||
if (password.length < 8) { return res.makeResponse(400, 'failed', 'changePassword.failed.tooshort'); }
|
||||
if (password.length > 64) { return res.makeResponse(400, 'failed', 'changePassword.failed.toolong'); }
|
||||
// password is good too !
|
||||
|
||||
await this.db.setUserPassword(req.authUser!.id, password);
|
||||
|
||||
return res.makeResponse(200, 'success', 'changePassword.success');
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
export default route;
|
||||
Loading…
Add table
Add a link
Reference in a new issue