aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2024-04-19 12:11:16 -0400
committerbobzel <zzzman@gmail.com>2024-04-19 12:11:16 -0400
commitec859c33f69d586f287aecdceeca38c4e77cb0ab (patch)
treed8f5e0e3165c5d2ae54104597972b5955d8e295a /src
parent89e5b4e224d77c7a029ec7d9c9027095665508ac (diff)
lint errors
Diffstat (limited to 'src')
-rw-r--r--src/Utils.ts6
-rw-r--r--src/client/views/MainView.tsx3
-rw-r--r--src/server/authentication/AuthenticationManager.ts109
3 files changed, 61 insertions, 57 deletions
diff --git a/src/Utils.ts b/src/Utils.ts
index 0455fd19a..c87ef052c 100644
--- a/src/Utils.ts
+++ b/src/Utils.ts
@@ -43,15 +43,15 @@ export namespace Utils {
export function TraceConsoleLog() {
['log', 'warn'].forEach(method => {
const old = (console as any)[method];
- (console as any)[method] = function () {
+ (console as any)[method] = function (...args: any[]) {
let stack = new Error('').stack?.split(/\n/);
// Chrome includes a single "Error" line, FF doesn't.
if (stack && stack[0].indexOf('Error') === 0) {
stack = stack.slice(1);
}
const message = (stack?.[1] || 'Stack undefined!').trim();
- const args = ([] as any[]).slice.apply(arguments).concat([message]);
- return old.apply(console, args);
+ const newArgs = args.slice().concat([message]);
+ return old.apply(console, newArgs);
};
});
}
diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx
index 13945cacf..b0156846f 100644
--- a/src/client/views/MainView.tsx
+++ b/src/client/views/MainView.tsx
@@ -8,7 +8,7 @@ import { observer } from 'mobx-react';
import * as React from 'react';
import '../../../node_modules/browndash-components/dist/styles/global.min.css';
import { ClientUtils, lightOrDark, returnEmptyDoclist, returnEmptyFilter, returnFalse, returnTrue, returnZero, setupMoveUpEvents } from '../../ClientUtils';
-import { emptyFunction } from '../../Utils';
+import { Utils, emptyFunction } from '../../Utils';
import { Doc, DocListCast, Opt } from '../../fields/Doc';
import { DocData } from '../../fields/DocSymbols';
import { DocCast, StrCast } from '../../fields/Types';
@@ -163,6 +163,7 @@ export class MainView extends ObservableReactComponent<{}> {
mainDocViewHeight = () => this._dashUIHeight - this.headerBarDocHeight();
componentDidMount() {
+ // Utils.TraceConsoleLog();
reaction(
// when a multi-selection occurs, remove focus from all active elements to allow keyboad input to go only to global key manager to act upon selection
() => SelectionManager.Views.slice(),
diff --git a/src/server/authentication/AuthenticationManager.ts b/src/server/authentication/AuthenticationManager.ts
index b5d1dba28..0cc1553c0 100644
--- a/src/server/authentication/AuthenticationManager.ts
+++ b/src/server/authentication/AuthenticationManager.ts
@@ -1,21 +1,21 @@
-import { default as User, DashUserModel, initializeGuest } from './DashUserModel';
-import { Request, Response, NextFunction } from 'express';
-import * as passport from 'passport';
-import { IVerifyOptions } from 'passport-local';
-import './Passport';
import * as async from 'async';
-import * as nodemailer from 'nodemailer';
import * as c from 'crypto';
-import { emptyFunction, Utils } from '../../ClientUtils';
-import { MailOptions } from 'nodemailer/lib/stream-transport';
+import { NextFunction, Request, Response } from 'express';
import { check, validationResult } from 'express-validator';
+import * as nodemailer from 'nodemailer';
+import { MailOptions } from 'nodemailer/lib/stream-transport';
+import * as passport from 'passport';
+import { Utils } from '../../Utils';
+import User, { DashUserModel, initializeGuest } from './DashUserModel';
+import './Passport';
+// import { IVerifyOptions } from 'passport-local';
/**
* GET /signup
* Directs user to the signup page
* modeled by signup.pug in views
*/
-export let getSignup = (req: Request, res: Response) => {
+export const getSignup = (req: Request, res: Response) => {
if (req.user) {
return res.redirect('/home');
}
@@ -23,13 +23,23 @@ export let getSignup = (req: Request, res: Response) => {
title: 'Sign Up',
user: req.user,
});
+ return undefined;
+};
+
+const tryRedirectToTarget = (req: Request, res: Response) => {
+ const target = (req.session as any)?.target;
+ if (req.session && target) {
+ res.redirect(target);
+ } else {
+ res.redirect('/home');
+ }
};
/**
* POST /signup
* Create a new local account.
*/
-export let postSignup = (req: Request, res: Response, next: NextFunction) => {
+export const postSignup = (req: Request, res: Response, next: NextFunction) => {
const email = req.body.email as String;
check('email', 'Email is not valid').isEmail().run(req);
check('password', 'Password must be at least 4 characters long').isLength({ min: 4 }).run(req);
@@ -42,7 +52,7 @@ export let postSignup = (req: Request, res: Response, next: NextFunction) => {
return res.redirect('/signup');
}
- const password = req.body.password;
+ const { password } = req.body;
const model = {
email,
@@ -65,35 +75,29 @@ export let postSignup = (req: Request, res: Response, next: NextFunction) => {
req.logIn(user, err => {
if (err) return next(err);
tryRedirectToTarget(req, res);
+ return undefined;
});
})
.catch((err: any) => next(err));
+ return undefined;
})
.catch((err: any) => next(err));
+ return undefined;
};
-
-const tryRedirectToTarget = (req: Request, res: Response) => {
- const target = (req.session as any)?.target;
- if (req.session && target) {
- res.redirect(target);
- } else {
- res.redirect('/home');
- }
-};
-
/**
* GET /login
* Login page.
*/
-export let getLogin = (req: Request, res: Response) => {
+export const getLogin = (req: Request, res: Response) => {
if (req.user) {
- //req.session.target = undefined;
+ // req.session.target = undefined;
return res.redirect('/home');
}
res.render('login.pug', {
title: 'Log In',
user: req.user,
});
+ return undefined;
};
/**
@@ -101,7 +105,7 @@ export let getLogin = (req: Request, res: Response) => {
* Sign in using email and password.
* On failure, redirect to signup page
*/
-export let postLogin = (req: Request, res: Response, next: NextFunction) => {
+export const postLogin = (req: Request, res: Response, next: NextFunction) => {
if (req.body.email === '') {
User.findOne({ email: 'guest' })
.then((user: any) => !user && initializeGuest())
@@ -119,23 +123,21 @@ export let postLogin = (req: Request, res: Response, next: NextFunction) => {
return res.redirect('/signup');
}
- const callback = (err: Error, user: DashUserModel, _info: IVerifyOptions) => {
+ const callback = (err: Error, user: DashUserModel /* , _info: IVerifyOptions */) => {
if (err) {
next(err);
- return;
- }
- if (!user) {
+ } else if (!user) {
return res.redirect('/signup');
- }
- req.logIn(user, err => {
- if (err) {
- next(err);
- return;
- }
- tryRedirectToTarget(req, res);
- });
+ } else
+ req.logIn(user, loginErr => {
+ if (loginErr) {
+ next(loginErr);
+ } else tryRedirectToTarget(req, res);
+ });
+ return undefined;
};
setTimeout(() => passport.authenticate('local', callback)(req, res, next), 500);
+ return undefined;
};
/**
@@ -143,31 +145,29 @@ export let postLogin = (req: Request, res: Response, next: NextFunction) => {
* Invokes the logout function on the request
* and destroys the user's current session.
*/
-export let getLogout = (req: Request, res: Response) => {
+export const getLogout = (req: Request, res: Response) => {
req.logout(err => {
if (err) console.log(err);
else res.redirect('/login');
});
};
-export let getForgot = function (req: Request, res: Response) {
+export const getForgot = function (req: Request, res: Response) {
res.render('forgot.pug', {
title: 'Recover Password',
user: req.user,
});
};
-export let postForgot = function (req: Request, res: Response, next: NextFunction) {
- const email = req.body.email;
+export const postForgot = function (req: Request, res: Response, next: NextFunction) {
+ const { email } = req.body;
async.waterfall(
[
function (done: any) {
- c.randomBytes(20, function (err: any, buffer: Buffer) {
+ c.randomBytes(20, (err: any, buffer: Buffer) => {
if (err) {
done(null);
- return;
- }
- done(null, buffer.toString('hex'));
+ } else done(null, buffer.toString('hex'));
});
},
function (token: string, done: any) {
@@ -204,20 +204,21 @@ export let postForgot = function (req: Request, res: Response, next: NextFunctio
'\n\n' +
'If you did not request this, please ignore this email and your password will remain unchanged.\n',
} as MailOptions;
- smtpTransport.sendMail(mailOptions, function (err: Error | null) {
+ smtpTransport.sendMail(mailOptions, (err: Error | null) => {
// req.flash('info', 'An e-mail has been sent to ' + user.email + ' with further instructions.');
done(null, err, 'done');
});
},
],
- function (err) {
+ err => {
if (err) return next(err);
res.redirect('/forgotPassword');
+ return undefined;
}
);
};
-export let getReset = function (req: Request, res: Response) {
+export const getReset = function (req: Request, res: Response) {
User.findOne({ passwordResetToken: req.params.token, passwordResetExpires: { $gt: Date.now() } })
.then((user: any) => {
if (!user) return res.redirect('/forgotPassword');
@@ -225,11 +226,12 @@ export let getReset = function (req: Request, res: Response) {
title: 'Reset Password',
user: req.user,
});
+ return undefined;
})
- .catch((err: any) => res.redirect('/forgotPassword'));
+ .catch(() => res.redirect('/forgotPassword'));
};
-export let postReset = function (req: Request, res: Response) {
+export const postReset = function (req: Request, res: Response) {
async.waterfall(
[
function (done: any) {
@@ -251,10 +253,11 @@ export let postReset = function (req: Request, res: Response) {
() => (req as any).logIn(user),
(err: any) => err
)
- .catch((err: any) => res.redirect('/login'));
+ .catch(() => res.redirect('/login'));
done(null, user);
+ return undefined;
})
- .catch((err: any) => res.redirect('back'));
+ .catch(() => res.redirect('back'));
},
function (user: DashUserModel, done: any) {
const smtpTransport = nodemailer.createTransport({
@@ -268,13 +271,13 @@ export let postReset = function (req: Request, res: Response) {
to: user.email,
from: 'browndashptc@gmail.com',
subject: 'Your password has been changed',
- text: 'Hello,\n\n' + 'This is a confirmation that the password for your account ' + user.email + ' has just been changed.\n',
+ text: 'Hello,\n\nThis is a confirmation that the password for your account ' + user.email + ' has just been changed.\n',
} as MailOptions;
smtpTransport.sendMail(mailOptions, err => done(null, err));
},
],
- function (err) {
+ () => {
res.redirect('/login');
}
);