- const password = TokenGen.generate(12); //arbitrary number, 12 seems enough...
- AssessmentEntity.getQuestions(aid, (err,questions) => {
- AssessmentEntity.startSession(aid, number, password, (err2,ret) => {
- cb(err, {
- questions: questions,
- password: password,
+ AssessmentEntity.getPaperByNumber(aid, number, (err,paper) => {
+ if (!!err)
+ return cb(err,null);
+ if (!paper && !!password)
+ return cb({errmsg: "Cannot start a new exam before finishing current"},null);
+ if (!!paper)
+ {
+ if (!password)
+ return cb({errmsg: "Missing password"});
+ if (paper.password != password)
+ return cb({errmsg: "Wrong password"});
+ }
+ AssessmentEntity.getQuestions(aid, (err,questions) => {
+ if (!!err)
+ return cb(err,null);
+ if (!!paper)
+ return cb(null,{paper:paper,questions:questions});
+ const pwd = TokenGen.generate(12); //arbitrary number, 12 seems enough...
+ AssessmentEntity.startSession(aid, number, pwd, (err2,ret) => {
+ cb(err2, {
+ questions: questions,
+ password: pwd,
+ });