Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit ba08d21

Browse files
committed
Removed comments, removed genericExpressMethod
1 parent c828b3a commit ba08d21

File tree

5 files changed

+20
-41
lines changed

5 files changed

+20
-41
lines changed

src/config/passport.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ import passport from "passport";
22
import passportLocal from "passport-local";
33
import passportFacebook from "passport-facebook";
44
import _ from "lodash";
5-
6-
// import { User, UserType } from '../models/User';
75
import { User, UserDocument } from "../models/User";
8-
import {genericExpressMethod} from "express-request-with-user";
9-
6+
import { Request, Response, NextFunction } from "express";
107
const LocalStrategy = passportLocal.Strategy;
118
const FacebookStrategy = passportFacebook.Strategy;
129

@@ -120,7 +117,7 @@ passport.use(new FacebookStrategy({
120117
/**
121118
* Login Required middleware.
122119
*/
123-
export const isAuthenticated: genericExpressMethod = (req, res, next) => {
120+
export const isAuthenticated = (req: Request, res: Response, next: NextFunction) => {
124121
if (req.isAuthenticated()) {
125122
return next();
126123
}
@@ -130,10 +127,9 @@ export const isAuthenticated: genericExpressMethod = (req, res, next) => {
130127
/**
131128
* Authorization Required middleware.
132129
*/
133-
export const isAuthorized: genericExpressMethod = (req, res, next) => {
130+
export const isAuthorized = (req: Request, res: Response, next: NextFunction) => {
134131
const provider = req.path.split("/").slice(-1)[0];
135132

136-
// const user = req.user as UserDocument;
137133
if (_.find(req.user.tokens, { kind: provider })) {
138134
next();
139135
} else {

src/controllers/api.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import graph from "fbgraph";
2-
import { Response, Request } from "express";
3-
import {genericExpressMethod} from "express-request-with-user";
2+
import { Response, Request, NextFunction } from "express";
43

54

65
/**
@@ -17,8 +16,7 @@ export const getApi = (req: Request, res: Response) => {
1716
* GET /api/facebook
1817
* Facebook API example.
1918
*/
20-
export const getFacebook: genericExpressMethod = (req, res, next) => {
21-
// const user = req.user /*as UserDocument*/;
19+
export const getFacebook = (req: Request, res: Response, next: NextFunction) => {
2220
const token = req.user.tokens.find(token => token.kind === "facebook");
2321
graph.setAccessToken(token.accessToken);
2422
graph.get(`${req.user.facebook}?fields=id,name,email,first_name,last_name,gender,link,locale,timezone`, (err: Error, results: graph.FacebookUser) => {

src/controllers/user.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import async from "async";
22
import crypto from "crypto";
33
import nodemailer from "nodemailer";
44
import passport from "passport";
5-
import {AuthToken, User, UserDocument} from "../models/User";
6-
import {Request, Response} from "express";
7-
import {IVerifyOptions} from "passport-local";
8-
import {WriteError} from "mongodb";
9-
import {check, sanitize, validationResult} from "express-validator";
5+
import { User, UserDocument, AuthToken } from "../models/User";
6+
import { Request, Response, NextFunction } from "express";
7+
import { IVerifyOptions } from "passport-local";
8+
import { WriteError } from "mongodb";
9+
import { check, sanitize, validationResult } from "express-validator";
1010
import "../config/passport";
11-
import {genericExpressMethod} from "express-request-with-user";
1211

1312
/**
1413
* GET /login
@@ -27,8 +26,7 @@ export const getLogin = (req: Request, res: Response) => {
2726
* POST /login
2827
* Sign in using email and password.
2928
*/
30-
31-
export const postLogin: genericExpressMethod = (req, res, next) => {
29+
export const postLogin = (req: Request, res: Response, next: NextFunction) => {
3230
check("email", "Email is not valid").isEmail();
3331
check("password", "Password cannot be blank").isLength({min: 1});
3432
// eslint-disable-next-line @typescript-eslint/camelcase
@@ -81,7 +79,7 @@ export const getSignup = (req: Request, res: Response) => {
8179
* POST /signup
8280
* Create a new local account.
8381
*/
84-
export const postSignup: genericExpressMethod = (req, res, next) => {
82+
export const postSignup = (req: Request, res: Response, next: NextFunction) => {
8583
check("email", "Email is not valid").isEmail();
8684
check("password", "Password must be at least 4 characters long").isLength({ min: 4 });
8785
check("confirmPassword", "Passwords do not match").equals(req.body.password);
@@ -132,7 +130,7 @@ export const getAccount = (req: Request, res: Response) => {
132130
* POST /account/profile
133131
* Update profile information.
134132
*/
135-
export const postUpdateProfile: genericExpressMethod = (req, res, next) => {
133+
export const postUpdateProfile = (req: Request, res: Response, next: NextFunction) => {
136134
check("email", "Please enter a valid email address.").isEmail();
137135
// eslint-disable-next-line @typescript-eslint/camelcase
138136
sanitize("email").normalizeEmail({ gmail_remove_dots: false });
@@ -144,7 +142,6 @@ export const postUpdateProfile: genericExpressMethod = (req, res, next) => {
144142
return res.redirect("/account");
145143
}
146144

147-
// const user = req.user as UserDocument;
148145
User.findById(req.user.id, (err, user) => {
149146
if (err) { return next(err); }
150147
user.email = req.body.email || "";
@@ -170,7 +167,7 @@ export const postUpdateProfile: genericExpressMethod = (req, res, next) => {
170167
* POST /account/password
171168
* Update current password.
172169
*/
173-
export const postUpdatePassword: genericExpressMethod = (req, res, next) => {
170+
export const postUpdatePassword = (req: Request, res: Response, next: NextFunction) => {
174171
check("password", "Password must be at least 4 characters long").isLength({ min: 4 });
175172
check("confirmPassword", "Passwords do not match").equals(req.body.password);
176173

@@ -181,7 +178,6 @@ export const postUpdatePassword: genericExpressMethod = (req, res, next) => {
181178
return res.redirect("/account");
182179
}
183180

184-
// const user = req.user as UserDocument;
185181
User.findById(req.user.id, (err, user) => {
186182
if (err) { return next(err); }
187183
user.password = req.body.password;
@@ -197,8 +193,7 @@ export const postUpdatePassword: genericExpressMethod = (req, res, next) => {
197193
* POST /account/delete
198194
* Delete user account.
199195
*/
200-
export const postDeleteAccount: genericExpressMethod = (req, res, next) => {
201-
// const user = req.user as UserDocument;
196+
export const postDeleteAccount = (req: Request, res: Response, next: NextFunction) => {
202197
User.remove({ _id: req.user.id }, (err) => {
203198
if (err) { return next(err); }
204199
req.logout();
@@ -211,12 +206,10 @@ export const postDeleteAccount: genericExpressMethod = (req, res, next) => {
211206
* GET /account/unlink/:provider
212207
* Unlink OAuth provider.
213208
*/
214-
export const getOauthUnlink: genericExpressMethod = (req, res, next) => {
209+
export const getOauthUnlink = (req: Request, res: Response, next: NextFunction) => {
215210
const provider = req.params.provider;
216-
// const user = req.user as UserDocument;
217211
User.findById(req.user.id, (err, user) => {
218212
if (err) { return next(err); }
219-
// user[provider] = undefined;
220213
user.tokens = user.tokens.filter((token: AuthToken) => token.kind !== provider);
221214
user.save((err: WriteError) => {
222215
if (err) { return next(err); }
@@ -230,7 +223,7 @@ export const getOauthUnlink: genericExpressMethod = (req, res, next) => {
230223
* GET /reset/:token
231224
* Reset Password page.
232225
*/
233-
export const getReset: genericExpressMethod = (req, res, next) => {
226+
export const getReset = (req: Request, res: Response, next: NextFunction) => {
234227
if (req.isAuthenticated()) {
235228
return res.redirect("/");
236229
}
@@ -253,7 +246,7 @@ export const getReset: genericExpressMethod = (req, res, next) => {
253246
* POST /reset/:token
254247
* Process the reset password request.
255248
*/
256-
export const postReset: genericExpressMethod = (req, res, next) => {
249+
export const postReset = (req: Request, res: Response, next: NextFunction) => {
257250
check("password", "Password must be at least 4 characters long.").isLength({ min: 4 });
258251
check("confirm", "Passwords must match.").equals(req.body.password);
259252

@@ -328,7 +321,7 @@ export const getForgot = (req: Request, res: Response) => {
328321
* POST /forgot
329322
* Create a random token, then the send user an email with a reset link.
330323
*/
331-
export const postForgot: genericExpressMethod = (req, res, next) => {
324+
export const postForgot = (req: Request, res: Response, next: NextFunction) => {
332325
check("email", "Please enter a valid email address.").isEmail();
333326
// eslint-disable-next-line @typescript-eslint/camelcase
334327
sanitize("email").normalizeEmail({ gmail_remove_dots: false });

src/models/User.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export type UserDocument = mongoose.Document & {
66
email: string;
77
password: string;
88
passwordResetToken: AuthToken;
9-
// passwordResetToken: string;
109
passwordResetExpires: Date;
1110

1211
facebook: string;
@@ -22,8 +21,6 @@ export type UserDocument = mongoose.Document & {
2221

2322
comparePassword: comparePasswordFunction;
2423
gravatar: (size: number) => string;
25-
26-
// [provider: string]: any;
2724
};
2825

2926
type comparePasswordFunction = (candidatePassword: string, cb: (err: Error, isMatch: boolean) => void) => void;
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference types="express" />
2-
31
import {UserDocument} from "../models/User";
42
import {NextFunction, Request, Response} from "express";
53

@@ -8,7 +6,4 @@ declare module 'express' {
86
export interface Request {
97
user?: User;
108
}
11-
}
12-
13-
/** To avoid duplication */
14-
export type genericExpressMethod = (req: Request, res: Response, next: NextFunction) => void
9+
}

0 commit comments

Comments
 (0)