aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/FileRouter.ts7
-rw-r--r--src/app.ts11
-rw-r--r--src/auth.ts27
-rw-r--r--src/db/model/User.ts15
4 files changed, 32 insertions, 28 deletions
diff --git a/src/FileRouter.ts b/src/FileRouter.ts
index 1c62621..8d13401 100644
--- a/src/FileRouter.ts
+++ b/src/FileRouter.ts
@@ -229,8 +229,8 @@ const getUsers: Middleware =
(u: User) => {
const info: UserFullInfo = u.fullInfo;
if (!req.user.hasPrivilege('admin')) {
- info.private_user_metadata = undefined;
- info.private_admin_metadata = undefined;
+ delete info.private_user_metadata;
+ delete info.private_admin_metadata;
}
return info;
}
@@ -567,5 +567,4 @@ export class FileRouter {
const fileRoutes: FileRouter = new FileRouter();
fileRoutes.init();
-const ex: Router = fileRoutes.router;
-export default ex;
+export default fileRoutes.router;
diff --git a/src/app.ts b/src/app.ts
index 83082a9..7776c02 100644
--- a/src/app.ts
+++ b/src/app.ts
@@ -36,7 +36,12 @@ class App {
// Configure Express middleware.
private middleware(): void {
- this.express.use(expressJwt({secret: 'Mr Secret'}).unless({path: ['/cs3099group-be-4/login', '/cs3099group-be-4/_supported_protocols_'] }));
+ this.express.use(expressJwt({secret: 'Mr Secret'})
+ .unless({path: [
+ '/cs3099group-be-4/login',
+ '/cs3099group-be-4/_supported_protocols_'
+ ] })
+ );
this.express.use(passport.initialize());
if (this.logEnabled) {
this.express.use(logger('combined'));
@@ -51,7 +56,7 @@ class App {
defRouter.get('/', (req: ex.Request, res: ex.Response): void => {
res.json({
message: 'Welcome to the CS3099 BE4 server!',
- important : 'Endpoints start from /cs3099group-be-4/'
+ important: 'Endpoints start from /cs3099group-be-4/'
});
});
this.express.use('/', defRouter);
@@ -60,7 +65,7 @@ class App {
}
private errorware(): void {
- //this.express.use(authRouter.unauthorisedErr);
+ // TODO: this.express.use(authRouter.unauthorisedErr);
this.express.use(errorHandler);
}
diff --git a/src/auth.ts b/src/auth.ts
index d5969c5..b40cddb 100644
--- a/src/auth.ts
+++ b/src/auth.ts
@@ -51,7 +51,9 @@ export class AuthRouter {
if (err) { throw err; }
if (!user) {
- next(new RequestError(400, 'invalid_grant', 'Incorrect authentication details'));
+ next(new RequestError(
+ 400, 'invalid_grant', 'Incorrect authentication details'
+ ));
}
}
);
@@ -73,25 +75,34 @@ export class AuthRouter {
}
// Handle error if user is unauthorised
- public unauthorisedErr(err: Error, req: Request, res: Response, next: NextFunction): void {
+ public unauthorisedErr(
+ err: Error, req: Request, res: Response, next: NextFunction
+ ): void {
if (err.name === 'UnauthorizedError') {
- next(new RequestError(401, 'not_authorised', 'user does not have correct authorisation to complete task'));
+ next(new RequestError(
+ 401, 'not_authorised',
+ 'user does not have correct authorisation for task'
+ ));
}
next();
}
- //middleware to check privileges - admin
- public isAdmin(req: Request, res: Response, next: NextFunction) {
+ // Middleware to check privileges - admin
+ public isAdmin(req: Request, res: Response, next: NextFunction): void {
if (!req.user.admin) {
- next(new RequestError(401, 'not_authorised', 'user is not authorised to perform task'));
+ next(new RequestError(
+ 401, 'not_authorised',
+ 'user is not authorised to perform task'
+ ));
+ return;
}
next();
}
// Configure local strategy to use with passport-js.
- private configStrategy() {
+ private configStrategy(): void {
// tslint:disable-next-line:typedef
- passport.use(new Strategy( async(username, password, done) => {
+ passport.use(new Strategy( async(username, password, done) => {
const user: User | null = await User.findOne({
where: {
username
diff --git a/src/db/model/User.ts b/src/db/model/User.ts
index 19a93f0..d290fd9 100644
--- a/src/db/model/User.ts
+++ b/src/db/model/User.ts
@@ -13,21 +13,10 @@ export default class User extends Model<User> {
public username!: string;
@Column
-<<<<<<< HEAD
- public password!: string;
-
- @ForeignKey(() => UserGroup)
- @Column
- public userGroupId!: number;
-
- @BelongsTo(() => UserGroup)
- public userGroup: UserGroup = new UserGroup();
-=======
private readonly passwordInternal!: string;
@BelongsToMany(() => UserGroup, () => UserHasPrivilege)
public userGroups?: UserGroup[];
->>>>>>> trh/gets
@BelongsToMany(() => Project, () => UserJoinsProject)
public projects?: Project[];
@@ -200,9 +189,9 @@ export interface UserFullInfo {
privileges: string[];
projects: ProjectInfo[];
public_user_metadata: Metadata;
- private_user_metadata?: Metadata;
+ private_user_metadata: Metadata;
public_admin_metadata: Metadata;
- private_admin_metadata?: Metadata;
+ private_admin_metadata: Metadata;
}
export interface UserProperty {}