-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from parlemonde/feat/collaboration-v1
Add collaboration mode and some fixes
- Loading branch information
Showing
136 changed files
with
3,510 additions
and
527 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file added
BIN
+6.16 KB
.yarn/cache/@socket.io-component-emitter-npm-3.1.0-3f778351c2-db069d9542.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+930 KB
.yarn/cache/react-qr-reader-npm-3.0.0-beta-1-159e0ee97b-f85fc49025.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import type { JSONSchemaType } from 'ajv'; | ||
import type { Request, Response } from 'express'; | ||
import { getRepository } from 'typeorm'; | ||
|
||
// import { QuestionStatus } from '../../types/models/question.type'; | ||
import { Project } from '../entities/project'; | ||
import { Question } from '../entities/question'; | ||
import { User } from '../entities/user'; | ||
import { ajv, sendInvalidDataError } from '../lib/json-schema-validator'; | ||
import { AppError } from '../middlewares/handle-errors'; | ||
import { ANONYMOUS_USER } from '../utils/anonymous-user'; | ||
import { getStudentAccessToken } from './lib/tokens'; | ||
|
||
const APP_SECRET: string = process.env.APP_SECRET || ''; | ||
|
||
// --- LOGIN --- | ||
type LoginData = { | ||
projectId: number; | ||
sequencyId: number; | ||
teacherId: number; | ||
}; | ||
const LOGIN_SCHEMA: JSONSchemaType<LoginData> = { | ||
type: 'object', | ||
properties: { | ||
projectId: { type: 'number' }, | ||
sequencyId: { type: 'number' }, | ||
teacherId: { type: 'number' }, | ||
}, | ||
required: ['projectId', 'sequencyId', 'teacherId'], | ||
additionalProperties: false, | ||
}; | ||
const loginValidator = ajv.compile(LOGIN_SCHEMA); | ||
export async function loginStudent(req: Request, res: Response): Promise<void> { | ||
if (APP_SECRET.length === 0 || !req.isCsrfValid) { | ||
throw new AppError('forbidden'); | ||
} | ||
const data = req.body; | ||
if (!loginValidator(data)) { | ||
sendInvalidDataError(loginValidator); | ||
return; | ||
} | ||
|
||
const project = await getRepository(Project).findOne({ where: { id: data.projectId } }); | ||
const teacher = await getRepository(User).findOne({ where: { id: data.teacherId } }); | ||
const sequency = await getRepository(Question).findOne({ | ||
where: { id: data.sequencyId }, | ||
relations: ['project', 'project.user'], | ||
}); | ||
|
||
// Check if data are correct before connect student as anonymous | ||
if ( | ||
project === undefined || | ||
teacher === undefined || | ||
sequency === undefined || | ||
sequency.project === undefined || | ||
sequency.project.user === undefined || | ||
project.id !== sequency.project.id || | ||
teacher.id !== sequency.project.user.id || | ||
project.isCollaborationActive !== true | ||
) { | ||
throw new AppError('loginError', ['Unauthorized - Invalid QRCode.'], 0); | ||
} | ||
|
||
const { accessToken } = await getStudentAccessToken(project.id, sequency.id, teacher.id); | ||
res.cookie('access-token', accessToken, { | ||
maxAge: 4 * 60 * 60000, | ||
expires: new Date(Date.now() + 4 * 60 * 60000), | ||
httpOnly: true, | ||
secure: true, | ||
sameSite: 'strict', | ||
}); | ||
res.sendJSON({ | ||
accessToken, | ||
projectId: project.id, | ||
sequencyId: sequency.id, | ||
teacherId: teacher.id, | ||
user: ANONYMOUS_USER, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.