fix auth-routes related eslint errors
This commit is contained in:
parent
cb5f4b6ef4
commit
6e6ce4571f
|
@ -202,6 +202,6 @@ class MailProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const mailProvider = new MailProvider();
|
const mailProvider = new MailProvider();
|
||||||
|
|
||||||
export default mailProvider;
|
export default mailProvider;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* request password change
|
* request password change
|
||||||
|
* @flow
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import type { Request, Response } from 'express';
|
import type { Request, Response } from 'express';
|
||||||
import Sequelize from 'sequelize';
|
|
||||||
import mailProvider from '../../../core/mail';
|
import mailProvider from '../../../core/mail';
|
||||||
|
|
||||||
import { validatePassword, validateEMail } from '../../../utils/validation';
|
import { validatePassword, validateEMail } from '../../../utils/validation';
|
||||||
|
@ -41,8 +41,8 @@ export default async (req: Request, res: Response) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const current_password = user.regUser.password;
|
const currentPassword = user.regUser.password;
|
||||||
if (!compareToHash(password, current_password)) {
|
if (!compareToHash(password, currentPassword)) {
|
||||||
res.status(400);
|
res.status(400);
|
||||||
res.json({
|
res.json({
|
||||||
errors: ['Incorrect password!'],
|
errors: ['Incorrect password!'],
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* request password change
|
* request password change
|
||||||
|
* @flow
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,7 +10,7 @@ import { RegUser } from '../../../data/models';
|
||||||
import { validateName } from '../../../utils/validation';
|
import { validateName } from '../../../utils/validation';
|
||||||
|
|
||||||
async function validate(oldname, name) {
|
async function validate(oldname, name) {
|
||||||
if (oldname == name) return 'You already have that name.';
|
if (oldname === name) return 'You already have that name.';
|
||||||
|
|
||||||
const nameerror = validateName(name);
|
const nameerror = validateName(name);
|
||||||
if (nameerror) return nameerror;
|
if (nameerror) return nameerror;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* request password change
|
* request password change
|
||||||
|
* @flow
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,18 +9,18 @@ import type { Request, Response } from 'express';
|
||||||
import { validatePassword } from '../../../utils/validation';
|
import { validatePassword } from '../../../utils/validation';
|
||||||
import { compareToHash } from '../../../utils/hash';
|
import { compareToHash } from '../../../utils/hash';
|
||||||
|
|
||||||
function validate(new_password, password) {
|
function validate(newPassword) {
|
||||||
const errors = [];
|
const errors = [];
|
||||||
|
|
||||||
const newpassworderror = validatePassword(new_password);
|
const newpassworderror = validatePassword(newPassword);
|
||||||
if (newpassworderror) errors.push(newpassworderror);
|
if (newpassworderror) errors.push(newpassworderror);
|
||||||
|
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async (req: Request, res: Response) => {
|
export default async (req: Request, res: Response) => {
|
||||||
const { new_password, password } = req.body;
|
const { new_password: newPassword, password } = req.body;
|
||||||
const errors = validate(new_password, password);
|
const errors = validate(newPassword);
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
res.status(400);
|
res.status(400);
|
||||||
res.json({
|
res.json({
|
||||||
|
@ -37,8 +38,8 @@ export default async (req: Request, res: Response) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const current_password = user.regUser.password;
|
const currentPassword = user.regUser.password;
|
||||||
if (current_password && !compareToHash(password, current_password)) {
|
if (currentPassword && !compareToHash(password, currentPassword)) {
|
||||||
res.status(400);
|
res.status(400);
|
||||||
res.json({
|
res.json({
|
||||||
errors: ['Incorrect password!'],
|
errors: ['Incorrect password!'],
|
||||||
|
@ -46,7 +47,7 @@ export default async (req: Request, res: Response) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await user.regUser.update({ password: new_password });
|
await user.regUser.update({ password: newPassword });
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* request password change
|
* request password change
|
||||||
|
* @flow
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,7 +20,7 @@ function validate(password) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async (req: Request, res: Response) => {
|
export default async (req: Request, res: Response) => {
|
||||||
const { new_password, password } = req.body;
|
const { password } = req.body;
|
||||||
const errors = await validate(password);
|
const errors = await validate(password);
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
res.status(400);
|
res.status(400);
|
||||||
|
@ -39,8 +40,8 @@ export default async (req: Request, res: Response) => {
|
||||||
}
|
}
|
||||||
const { id } = user;
|
const { id } = user;
|
||||||
|
|
||||||
const current_password = user.regUser.password;
|
const currentPassword = user.regUser.password;
|
||||||
if (!current_password || !compareToHash(password, current_password)) {
|
if (!currentPassword || !compareToHash(password, currentPassword)) {
|
||||||
res.status(400);
|
res.status(400);
|
||||||
res.json({
|
res.json({
|
||||||
errors: ['Incorrect password!'],
|
errors: ['Incorrect password!'],
|
||||||
|
|
|
@ -4,18 +4,23 @@
|
||||||
|
|
||||||
|
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import bodyParser from 'body-parser';
|
|
||||||
|
|
||||||
import logger from '../../../core/logger';
|
import logger from '../../../core/logger';
|
||||||
|
|
||||||
import register from './register';
|
import register from './register';
|
||||||
import verify from './verify';
|
import verify from './verify';
|
||||||
import logout from './logout';
|
import logout from './logout';
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
import resend_verify from './resend_verify';
|
import resend_verify from './resend_verify';
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
import change_passwd from './change_passwd';
|
import change_passwd from './change_passwd';
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
import delete_account from './delete_account';
|
import delete_account from './delete_account';
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
import change_name from './change_name';
|
import change_name from './change_name';
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
import change_mail from './change_mail';
|
import change_mail from './change_mail';
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
import restore_password from './restore_password';
|
import restore_password from './restore_password';
|
||||||
import mclink from './mclink';
|
import mclink from './mclink';
|
||||||
|
|
||||||
|
@ -97,8 +102,8 @@ export default (passport) => {
|
||||||
}
|
}
|
||||||
logger.info(`User ${user.id} logged in with mail/password.`);
|
logger.info(`User ${user.id} logged in with mail/password.`);
|
||||||
|
|
||||||
req.logIn(user, async (err) => {
|
req.logIn(user, async (e) => {
|
||||||
if (err) { res.json({ success: false, errors: ['Failed to establish session. Please try again later :('] }); return; }
|
if (e) { res.json({ success: false, errors: ['Failed to establish session. Please try again later :('] }); return; }
|
||||||
|
|
||||||
user.ip = req.user.ip;
|
user.ip = req.user.ip;
|
||||||
const me = await getMe(user);
|
const me = await getMe(user);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* logout
|
* logout
|
||||||
|
* @flow
|
||||||
*/
|
*/
|
||||||
import type { Request, Response } from 'express';
|
import type { Request, Response } from 'express';
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,11 @@ import Sequelize from 'sequelize';
|
||||||
import { RegUser } from '../../../data/models';
|
import { RegUser } from '../../../data/models';
|
||||||
import mailProvider from '../../../core/mail';
|
import mailProvider from '../../../core/mail';
|
||||||
import getMe from '../../../core/me';
|
import getMe from '../../../core/me';
|
||||||
import { validateEMail, validateName, validatePassword } from '../../../utils/validation';
|
import {
|
||||||
|
validateEMail,
|
||||||
|
validateName,
|
||||||
|
validatePassword,
|
||||||
|
} from '../../../utils/validation';
|
||||||
|
|
||||||
async function validate(email, name, password) {
|
async function validate(email, name, password) {
|
||||||
const errors = [];
|
const errors = [];
|
||||||
|
@ -56,8 +60,7 @@ export default async (req: Request, res: Response) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { noauthUser } = req;
|
const user = req.noauthUser;
|
||||||
const user = (noauthUser) || new User(id);
|
|
||||||
user.id = newuser.id;
|
user.id = newuser.id;
|
||||||
user.regUser = newuser;
|
user.regUser = newuser;
|
||||||
const me = await getMe(user);
|
const me = await getMe(user);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* request resend of verification mail
|
* request resend of verification mail
|
||||||
|
* @flow
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* request passowrd reset mail
|
* request passowrd reset mail
|
||||||
|
* @flow
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ export default async (req: Request, res: Response) => {
|
||||||
const index = getHtml('Mail verification', 'You are now verified :)');
|
const index = getHtml('Mail verification', 'You are now verified :)');
|
||||||
res.status(200).send(index);
|
res.status(200).send(index);
|
||||||
} else {
|
} else {
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
const index = getHtml('Mail verification', 'Your mail verification code is invalid or already expired :(, please request a new one.');
|
const index = getHtml('Mail verification', 'Your mail verification code is invalid or already expired :(, please request a new one.');
|
||||||
res.status(400).send(index);
|
res.status(400).send(index);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ export async function getIPFromRequest(req): ?string {
|
||||||
const conip = (connection ? connection.remoteAddress : socket.remoteAddress);
|
const conip = (connection ? connection.remoteAddress : socket.remoteAddress);
|
||||||
|
|
||||||
if (!headers['x-forwarded-for'] || !isTrustedProxy(conip)) {
|
if (!headers['x-forwarded-for'] || !isTrustedProxy(conip)) {
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
logger.warn(`Connection not going through nginx and cloudflare! IP: ${conip}`, headers);
|
logger.warn(`Connection not going through nginx and cloudflare! IP: ${conip}`, headers);
|
||||||
return conip;
|
return conip;
|
||||||
}
|
}
|
||||||
|
@ -43,6 +44,7 @@ export async function getIPFromRequest(req): ?string {
|
||||||
|
|
||||||
export function getIPv6Subnet(ip: string): string {
|
export function getIPv6Subnet(ip: string): string {
|
||||||
if (ip.includes(':')) {
|
if (ip.includes(':')) {
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
const ipv6sub = `${ip.split(':').slice(0, 4).join(':')}:0000:0000:0000:0000`;
|
const ipv6sub = `${ip.split(':').slice(0, 4).join(':')}:0000:0000:0000:0000`;
|
||||||
// logger.warn("IPv6 subnet: ", ipv6sub);
|
// logger.warn("IPv6 subnet: ", ipv6sub);
|
||||||
return ipv6sub;
|
return ipv6sub;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user