From d89c8872d20bdfe2037b9d022db531385c3974f1 Mon Sep 17 00:00:00 2001 From: Jonathan Cremin Date: Sun, 14 Jun 2020 22:29:04 +0100 Subject: [PATCH] Fix broken shit after dep updates --- api/lib/auth.js | 4 +- app.js | 1 + lib/uploader.js | 1 + package.json | 21 +- web/lib/auth.js | 5 +- web/routes/user.js | 23 +- web/views/apps.ejs | 2 +- web/views/forgot.ejs | 2 +- web/views/pricing.ejs | 2 +- web/views/privacy.ejs | 2 +- web/views/signin.ejs | 2 +- web/views/signup.ejs | 2 +- web/views/terms.ejs | 2 +- webpack.config.js | 2 +- yarn.lock | 1811 +++++++++++++++++++++++++---------------- 15 files changed, 1169 insertions(+), 713 deletions(-) diff --git a/api/lib/auth.js b/api/lib/auth.js index 01dbe61..266da94 100644 --- a/api/lib/auth.js +++ b/api/lib/auth.js @@ -12,7 +12,7 @@ export default async (ctx, next) => { let user = false; const remoteIp = ctx.req.headers['x-forwarded-for'] || ctx.req.connection.remoteAddress; const login = await models.login.create({ - ip: remoteIp, + ip: remoteIp.split(',')[0], successful: false, }); if (ctx.req.headers.authorization && ctx.req.headers.authorization[0] === ':') { @@ -30,7 +30,7 @@ export default async (ctx, next) => { ctx.assert(authUser, 401, badLoginMsg); const count = await models.login.count({ where: { - ip: remoteIp, + ip: remoteIp.split(',')[0], successful: false, createdAt: { $gt: new Date(Date.now() - 600000), diff --git a/app.js b/app.js index 9246d07..dd737e0 100644 --- a/app.js +++ b/app.js @@ -76,6 +76,7 @@ app.on('error', (err, ctx) => { Sentry.captureException(err); }); } + debug(err); }); if (!module.parent) { diff --git a/lib/uploader.js b/lib/uploader.js index e17a1ab..8d1da8f 100644 --- a/lib/uploader.js +++ b/lib/uploader.js @@ -26,6 +26,7 @@ export default class Uploader { this.expectedSize = context.request.headers['content-length']; this.tempGuid = context.request.headers['hostr-guid']; this.remoteIp = context.request.headers['x-forwarded-for'] || context.req.connection.remoteAddress; + this.remoteIp = this.remoteIp.split(',')[0]; this.md5sum = crypto.createHash('md5'); this.lastPercent = 0; diff --git a/package.json b/package.json index 4afa3ec..d2bd77f 100644 --- a/package.json +++ b/package.json @@ -44,19 +44,20 @@ "co": "~4.6.0", "co-redis": "^2.1.0", "co-views": "~2.1.0", - "copy-webpack-plugin": "^5.1.1", + "copy-webpack-plugin": "^6.0.2", "debug": "~4.1.1", "dropzone": "~5.7.0", "ejs": "^3.1.3", + "ejs-lint": "^1.1.0", "form-data": "^3.0.0", "http-errors": "^1.7.3", "image-size": "^0.8.3", - "jimp": "^0.9.3", + "jimp": "^0.13.0", "jquery": "^3.5.0", "kcors": "^2.2.2", "koa": "^2.11.0", "koa-bodyparser": "^4.3.0", - "koa-compress": "~3.0.0", + "koa-compress": "~4.0.1", "koa-csrf": "^3.0.8", "koa-error": "^3.2.0", "koa-favicon": "~2.1.0", @@ -64,8 +65,8 @@ "koa-helmet": "^5.2.0", "koa-logger": "~3.2.1", "koa-redis": "^4.0.1", - "koa-router": "^8.0.8", - "koa-session": "^5.13.1", + "koa-router": "^9.0.1", + "koa-session": "^6.0.0", "koa-static": "^5.0.0", "koa-views": "^6.2.1", "koa-websocket": "^6.0.0", @@ -74,12 +75,12 @@ "moment": "^2.24.0", "mz": "^2.7.0", "node-fetch": "^2.3.0", - "redis": "^3.0.2", - "sequelize": "^5.21.11", "node-sass": "^4.14.0", "node-uuid": "^1.4.8", "passwords": "^1.3.1", "pg": "^8.0.3", + "redis": "^3.0.2", + "sequelize": "^5.21.11", "smooth-scroll": "https://github.com/cferdinandi/smooth-scroll#5.3.7", "statsy": "~0.2.0", "stripe": "^8.61.0", @@ -90,12 +91,12 @@ "devDependencies": { "babel-eslint": "^10.1.0", "concurrently": "^5.1.0", - "eslint": "^5.13.0", - "eslint-config-airbnb": "^17.1.0", + "eslint": "^7.2.0", + "eslint-config-airbnb": "^18.1.0", "eslint-plugin-import": "^2.20.2", "mocha": "^8.0.0", "nodemon": "^2.0.2", "supertest": "^4.0.2", - "tmp": "0.1.0" + "tmp": "0.2.1" } } diff --git a/web/lib/auth.js b/web/lib/auth.js index d3d8ea3..45165b9 100644 --- a/web/lib/auth.js +++ b/web/lib/auth.js @@ -23,7 +23,7 @@ export async function authenticate(email, password) { } const count = await models.login.count({ where: { - ip: remoteIp, + ip: remoteIp.split(',')[0], successful: false, createdAt: { $gt: Math.ceil(Date.now()) - 600000, @@ -43,7 +43,7 @@ export async function authenticate(email, password) { }); const login = await models.login.create({ - ip: remoteIp, + ip: remoteIp.split(',')[0], successful: false, }); @@ -65,6 +65,7 @@ export async function authenticate(email, password) { export async function setupSession(user) { debug('Setting up session'); const token = uuid.v4(); + debug(user) await this.redis.set(token, user.id, 'EX', 604800); const sessionUser = { diff --git a/web/routes/user.js b/web/routes/user.js index 8359402..4a538e2 100644 --- a/web/routes/user.js +++ b/web/routes/user.js @@ -10,7 +10,7 @@ const debug = debugname('hostr-web:user'); export async function signin(ctx) { if (!ctx.request.body.email) { - await ctx.render('signin', { csrf: ctx.csrf }); + await ctx.render('signin', { csrf: ctx.csrf, async: true }); return; } @@ -18,14 +18,15 @@ export async function signin(ctx) { const user = await authenticate.call(ctx, ctx.request.body.email, ctx.request.body.password); - if (!user) { + if (!user || !user.id) { ctx.statsd.incr('auth.failure', 1); - await ctx.render('signin', { error: 'Invalid login details', csrf: ctx.csrf }); + await ctx.render('signin', { error: 'Invalid login details', csrf: ctx.csrf, async: true }); return; } else if (user.activationCode) { await ctx.render('signin', { error: 'Your account hasn\'t been activated yet. Check for an activation email.', csrf: ctx.csrf, + async: true, }); return; } @@ -37,23 +38,25 @@ export async function signin(ctx) { export async function signup(ctx) { if (!ctx.request.body.email) { - await ctx.render('signup', { csrf: ctx.csrf }); + await ctx.render('signup', { csrf: ctx.csrf, async: true }); return; } if (ctx.request.body.email !== ctx.request.body.confirm_email) { - await ctx.render('signup', { error: 'Emails do not match.', csrf: ctx.csrf }); + await ctx.render('signup', { error: 'Emails do not match.', csrf: ctx.csrf, async: true }); return; } else if (ctx.request.body.email && !ctx.request.body.terms) { await ctx.render('signup', { error: 'You must agree to the terms of service.', csrf: ctx.csrf, + async: true, }); return; } else if (ctx.request.body.password && ctx.request.body.password.length < 7) { await ctx.render('signup', { error: 'Password must be at least 7 characters long.', csrf: ctx.csrf, + async: true, }); return; } @@ -62,13 +65,14 @@ export async function signup(ctx) { try { await signupUser.call(ctx, email, password, ip); } catch (e) { - await ctx.render('signup', { error: e.message, csrf: ctx.csrf }); + await ctx.render('signup', { error: e.message, csrf: ctx.csrf, async: true }); return; } ctx.statsd.incr('auth.signup', 1); await ctx.render('signup', { message: 'Thanks for signing up, we\'ve sent you an email to activate your account.', csrf: ctx.csrf, + async: true, }); } @@ -82,6 +86,7 @@ export async function forgot(ctx) { error: 'Password needs to be at least 7 characters long.', csrf: ctx.csrf, token, + async: true, }); return; } @@ -103,10 +108,11 @@ export async function forgot(ctx) { error: 'Invalid password reset token. It might be expired, or has already been used.', csrf: ctx.csrf, token: null, + async: true, }); return; } - await ctx.render('forgot', { csrf: ctx.csrf, token }); + await ctx.render('forgot', { csrf: ctx.csrf, token, async: true }); } else if (ctx.request.body.email) { try { @@ -118,13 +124,14 @@ export async function forgot(ctx) { Be sure to check your spam folder if you it doesn't appear within a few minutes`, csrf: ctx.csrf, token: null, + async: true, }); return; } catch (error) { debug(error); } } else { - await ctx.render('forgot', { csrf: ctx.csrf, token: null }); + await ctx.render('forgot', { csrf: ctx.csrf, token: null, async: true }); } } diff --git a/web/views/apps.ejs b/web/views/apps.ejs index 6b8447f..4c0fd42 100644 --- a/web/views/apps.ejs +++ b/web/views/apps.ejs @@ -36,7 +36,7 @@ - <% include footer.ejs %> + <%- await include('footer') -%>