Skip to content

Commit

Permalink
Sign cookies & fix users
Browse files Browse the repository at this point in the history
  • Loading branch information
diced committed Feb 12, 2021
1 parent bc9fa4e commit 3bf154c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/lib/controllers/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ export class UserController {
this.logger.verbose(`set cookie for ${user.username} (${user.id})`);
reply.setCookie('zipline', createBaseCookie(user.id), {
path: '/',
maxAge: 1036800000
maxAge: 1036800000,
signed: true
});

this.logger.info(`${user.username} (${user.id}) logged in`);
Expand All @@ -193,7 +194,6 @@ export class UserController {

@POST('/reset-token')
async resetToken(req: FastifyRequest, reply: FastifyReply) {
if (!req.cookies.zipline) return sendError(reply, 'Not logged in.');

const user = await this.users.findOne({
where: {
Expand Down Expand Up @@ -224,6 +224,10 @@ export class UserController {
}>,
reply: FastifyReply
) {
const firstSetup = await getFirst(this.instance.orm);

if (!firstSetup && !req.cookies.zipline) return sendError(reply, 'Not logged in.');

if (!req.body.username) return sendError(reply, 'Missing username.');
if (!req.body.password) return sendError(reply, 'Missing uassword.');

Expand All @@ -247,7 +251,6 @@ export class UserController {
user
});

const firstSetup = await getFirst(this.instance.orm);
if (firstSetup) await this.instance.orm.getRepository(Zipline).update(
{
id: 'zipline'
Expand Down

0 comments on commit 3bf154c

Please sign in to comment.