Fix linting
This commit is contained in:
parent
553ba9db9a
commit
bb5189c9ed
35 changed files with 157 additions and 866 deletions
17
web/app.js
17
web/app.js
|
@ -2,11 +2,10 @@ import path from 'path';
|
|||
import Router from 'koa-router';
|
||||
import CSRF from 'koa-csrf';
|
||||
import views from 'koa-views';
|
||||
import stats from '../lib/koa-statsd';
|
||||
import StatsD from 'statsy';
|
||||
import errors from 'koa-error';
|
||||
|
||||
import * as redis from '../lib/redis';
|
||||
import stats from '../lib/koa-statsd';
|
||||
import * as index from './routes/index';
|
||||
import * as file from './routes/file';
|
||||
import * as user from './routes/user';
|
||||
|
@ -26,8 +25,6 @@ router.use(async (ctx, next) => {
|
|||
await next();
|
||||
});
|
||||
|
||||
//router.use(redis.sessionStore());
|
||||
|
||||
router.use(async (ctx, next) => {
|
||||
ctx.state = {
|
||||
session: ctx.session,
|
||||
|
@ -71,15 +68,15 @@ router.get('/:id', file.landing);
|
|||
router.get('/file/:id/:name', file.get);
|
||||
router.get('/file/:size/:id/:name', file.get);
|
||||
router.get('/files/:id/:name', file.get);
|
||||
router.get('/download/:id/:name', function* downloadRedirect(id) {
|
||||
this.redirect(`/${id}`);
|
||||
router.get('/download/:id/:name', async (ctx, id) => {
|
||||
ctx.redirect(`/${id}`);
|
||||
});
|
||||
|
||||
router.get('/updaters/mac', function* macUpdater() {
|
||||
this.redirect('/updaters/mac.xml');
|
||||
router.get('/updaters/mac', async (ctx) => {
|
||||
ctx.redirect('/updaters/mac.xml');
|
||||
});
|
||||
router.get('/updaters/mac/changelog', function* macChangelog() {
|
||||
yield this.render('mac-update-changelog');
|
||||
router.get('/updaters/mac/changelog', async (ctx) => {
|
||||
await ctx.render('mac-update-changelog');
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
|
|
@ -41,7 +41,7 @@ export async function authenticate(email, password) {
|
|||
activated: true,
|
||||
},
|
||||
});
|
||||
debug(user);
|
||||
|
||||
const login = await models.login.create({
|
||||
ip: remoteIp,
|
||||
successful: false,
|
||||
|
@ -52,7 +52,6 @@ export async function authenticate(email, password) {
|
|||
debug('Password verified');
|
||||
login.successful = true;
|
||||
await login.save();
|
||||
debug(user);
|
||||
return user;
|
||||
}
|
||||
debug('Password invalid');
|
||||
|
@ -182,18 +181,18 @@ Visit ${process.env.WEB_BASE_URL}/forgot/${reset.id} to set a new one.
|
|||
|
||||
export async function fromToken(token) {
|
||||
const userId = await this.redis.get(token);
|
||||
return await models.user.findById(userId);
|
||||
return models.user.findById(userId);
|
||||
}
|
||||
|
||||
|
||||
export async function fromCookie(rememberId) {
|
||||
const userId = await models.remember.findById(rememberId);
|
||||
return await models.user.findById(userId);
|
||||
return models.user.findById(userId);
|
||||
}
|
||||
|
||||
|
||||
export async function validateResetToken(resetId) {
|
||||
return await models.reset.findById(resetId);
|
||||
return models.reset.findById(resetId);
|
||||
}
|
||||
|
||||
|
||||
|
@ -206,7 +205,6 @@ export async function updatePassword(userId, password) {
|
|||
|
||||
|
||||
export async function activateUser(code) {
|
||||
debug(code);
|
||||
const activation = await models.activation.findOne({
|
||||
where: {
|
||||
id: code,
|
||||
|
|
|
@ -20,7 +20,7 @@ function userAgentCheck(userAgent) {
|
|||
}
|
||||
|
||||
function referrerCheck(referrer) {
|
||||
return referrer && referrerRegexes.some((regex) => referrer.match(regex));
|
||||
return referrer && referrerRegexes.some(regex => referrer.match(regex));
|
||||
}
|
||||
|
||||
function hotlinkCheck(file, userAgent, referrer) {
|
||||
|
@ -52,7 +52,7 @@ export async function get(ctx) {
|
|||
}
|
||||
|
||||
if (file.malware) {
|
||||
const alert = ctx.request.query.alert;
|
||||
const { alert } = ctx.request.query;
|
||||
if (!alert || !alert.match(/i want to download malware/i)) {
|
||||
ctx.redirect(`/${file.id}`);
|
||||
return;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import uuid from 'node-uuid';
|
||||
import auth from '../lib/auth';
|
||||
import { fromToken, fromCookie, setupSession } from '../lib/auth';
|
||||
|
||||
export async function main(ctx) {
|
||||
if (ctx.session.user) {
|
||||
|
@ -11,18 +11,16 @@ export async function main(ctx) {
|
|||
await ctx.redis.set(token, ctx.session.user.id, 'EX', 604800);
|
||||
ctx.session.user.token = token;
|
||||
await ctx.render('index', { user: ctx.session.user });
|
||||
} else if (ctx.query['app-token']) {
|
||||
const user = await fromToken(ctx, ctx.query['app-token']);
|
||||
await setupSession(ctx, user);
|
||||
ctx.redirect('/');
|
||||
} else if (ctx.cookies.r) {
|
||||
const user = await fromCookie(ctx, ctx.cookies.r);
|
||||
await setupSession(ctx, user);
|
||||
ctx.redirect('/');
|
||||
} else {
|
||||
if (ctx.query['app-token']) {
|
||||
const user = await auth.fromToken(ctx, ctx.query['app-token']);
|
||||
await auth.setupSession(ctx, user);
|
||||
ctx.redirect('/');
|
||||
} else if (ctx.cookies.r) {
|
||||
const user = await auth.fromCookie(ctx, ctx.cookies.r);
|
||||
await auth.setupSession(ctx, user);
|
||||
ctx.redirect('/');
|
||||
} else {
|
||||
await ctx.render('marketing');
|
||||
}
|
||||
await ctx.render('marketing');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import debugname from 'debug';
|
||||
import {
|
||||
authenticate, setupSession, signup as signupUser, activateUser, sendResetToken,
|
||||
validateResetToken, updatePassword,
|
||||
} from '../lib/auth';
|
||||
|
||||
import models from '../../models';
|
||||
import debugname from 'debug';
|
||||
|
||||
const debug = debugname('hostr-web:user');
|
||||
|
||||
export async function signin(ctx) {
|
||||
|
@ -44,17 +46,20 @@ export async function signup(ctx) {
|
|||
await ctx.render('signup', { error: 'Emails do not match.', csrf: ctx.csrf });
|
||||
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 });
|
||||
await ctx.render('signup', {
|
||||
error: 'You must agree to the terms of service.',
|
||||
csrf: ctx.csrf,
|
||||
});
|
||||
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 });
|
||||
await ctx.render('signup', {
|
||||
error: 'Password must be at least 7 characters long.',
|
||||
csrf: ctx.csrf,
|
||||
});
|
||||
return;
|
||||
}
|
||||
const ip = ctx.headers['x-forwarded-for'] || ctx.ip;
|
||||
const email = ctx.request.body.email;
|
||||
const password = ctx.request.body.password;
|
||||
const { email, password } = ctx.request.body;
|
||||
try {
|
||||
await signupUser.call(ctx, email, password, ip);
|
||||
} catch (e) {
|
||||
|
@ -66,12 +71,11 @@ export async function signup(ctx) {
|
|||
message: 'Thanks for signing up, we\'ve sent you an email to activate your account.',
|
||||
csrf: '',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
export async function forgot(ctx) {
|
||||
const token = ctx.params.token;
|
||||
const { token } = ctx.params;
|
||||
|
||||
if (ctx.request.body.password) {
|
||||
if (ctx.request.body.password.length < 7) {
|
||||
|
@ -87,7 +91,7 @@ export async function forgot(ctx) {
|
|||
if (user) {
|
||||
await updatePassword(user.userId, ctx.request.body.password);
|
||||
const reset = await models.reset.findById(token);
|
||||
//reset.destroy();
|
||||
reset.destroy();
|
||||
await setupSession.call(ctx, user);
|
||||
ctx.statsd.incr('auth.reset.success', 1);
|
||||
ctx.redirect('/');
|
||||
|
@ -104,11 +108,10 @@ export async function forgot(ctx) {
|
|||
return;
|
||||
}
|
||||
await ctx.render('forgot', { csrf: ctx.csrf, token });
|
||||
return;
|
||||
} else if (ctx.request.body.email) {
|
||||
ctx.assertCSRF(ctx.request.body);
|
||||
try {
|
||||
const email = ctx.request.body.email;
|
||||
const { email } = ctx.request.body;
|
||||
await sendResetToken.call(ctx, email);
|
||||
ctx.statsd.incr('auth.reset.request', 1);
|
||||
await ctx.render('forgot', {
|
||||
|
@ -136,7 +139,7 @@ export async function logout(ctx) {
|
|||
|
||||
|
||||
export async function activate(ctx) {
|
||||
const code = ctx.params.code;
|
||||
const { code } = ctx.params;
|
||||
if (await activateUser.call(ctx, code)) {
|
||||
ctx.statsd.incr('auth.activation', 1);
|
||||
ctx.redirect('/');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue