Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • add_route_assignments
  • ask-user-to-delete-exercises-on-duplicates
  • bedran_exercise-list
  • jw_sonar
  • jw_sonar_backup
  • main
  • update-dependencies
  • v6.0.0
  • 2.0.0
  • 2.1.0
  • 2.2.0
  • 3.0.0
  • 3.0.1
  • 3.1.0
  • 3.1.1
  • 3.1.2
  • 3.1.3
  • 3.2.0
  • 3.3.0
  • 3.4.0
  • 3.4.1
  • 3.4.2
  • 3.5.0
  • 3.5.1
  • 3.5.2
  • 3.5.3
  • 4.0.0
  • 4.1.0
  • 5.0.0
  • 5.0.1
  • 6.0.0-dev
  • v1.0.1
32 results

Target

Select target project
  • Dojo_Project_Nguyen/backend/dojobackendapi
  • dojo_project/projects/backend/dojobackendapi
2 results
Select Git revision
  • add_route_assignments
  • ask-user-to-delete-exercises-on-duplicates
  • bedran_exercise-list
  • jw_sonar
  • jw_sonar_backup
  • main
  • update-dependencies
  • v6.0.0
  • 2.0.0
  • 2.1.0
  • 2.2.0
  • 3.0.0
  • 3.0.1
  • 3.1.0
  • 3.1.1
  • 3.1.2
  • 3.1.3
  • 3.2.0
  • 3.3.0
  • 3.4.0
  • 3.4.1
  • 3.4.2
  • 3.5.0
  • 3.5.1
  • 3.5.2
  • 3.5.3
  • 4.0.0
  • 4.1.0
  • 5.0.0
  • 5.0.1
  • 6.0.0-dev
  • v1.0.1
32 results
Show changes
Commits on Source (2)
import { getReasonPhrase } from 'http-status-codes';
import * as jwt from 'jsonwebtoken';
import { JwtPayload } from 'jsonwebtoken';
import Config from '../config/Config';
import express from 'express';
import UserManager from '../managers/UserManager';
import DojoResponse from '../shared/types/Dojo/DojoResponse';
import { User } from '../types/DatabaseTypes';
import { getReasonPhrase, StatusCodes } from 'http-status-codes';
import * as jwt from 'jsonwebtoken';
import { JwtPayload } from 'jsonwebtoken';
import Config from '../config/Config';
import express from 'express';
import UserManager from '../managers/UserManager';
import DojoResponse from '../shared/types/Dojo/DojoResponse';
import { User } from '../types/DatabaseTypes';
class Session {
......@@ -22,7 +22,7 @@ class Session {
constructor() { }
async initSession(req: express.Request) {
async initSession(req: express.Request, res: express.Response) {
const authorization = req.headers.authorization;
if ( authorization ) {
if ( authorization.startsWith('Bearer ') ) {
......@@ -35,7 +35,9 @@ class Session {
this.profile = jwtData.profile;
this.profile = await UserManager.getById(this.profile.id!) ?? this.profile;
}
} catch ( err ) { }
} catch ( err ) {
res.sendStatus(StatusCodes.UNAUTHORIZED).end();
}
}
}
}
......
......@@ -18,22 +18,27 @@ class GitlabManager {
return `${ Config.gitlab.apiURL }${ route }`;
}
private async getGitlabUser(paramToSearch: string | number, paramName: string): Promise<GitlabUser | undefined> {
public async getUserById(id: number): Promise<GitlabUser | undefined> {
try {
const params: any = {};
params[paramName] = paramToSearch;
return (await axios.get<Array<GitlabUser>>(this.getApiUrl(GitlabRoute.USERS_GET), { params: params })).data[0];
const user = (await axios.get<GitlabUser>(`${ this.getApiUrl(GitlabRoute.USERS_GET) }/${ String(id) }`, { params: params })).data;
return user.id === id ? user : undefined;
} catch ( e ) { }
return undefined;
}
public async getUserById(id: number): Promise<GitlabUser | undefined> {
return await this.getGitlabUser(id, 'id');
}
public async getUserByUsername(username: string): Promise<GitlabUser | undefined> {
return await this.getGitlabUser(username, 'search');
try {
const params: any = {};
params['search'] = username;
const user = (await axios.get<Array<GitlabUser>>(this.getApiUrl(GitlabRoute.USERS_GET), { params: params })).data[0];
return user.username === username ? user : undefined;
} catch ( e ) { }
return undefined;
}
async getRepository(idOrNamespace: string): Promise<GitlabRepository> {
......
......@@ -6,7 +6,7 @@ class SessionMiddleware {
register(): (req: express.Request, res: express.Response, next: express.NextFunction) => void {
return async (req: express.Request, res: express.Response, next: express.NextFunction) => {
req.session = new Session();
await req.session.initSession(req);
await req.session.initSession(req, res);
return next();
};
......