Skip to content

Commit

Permalink
Merge pull request #15 from isa-group/feature/#10-CodeCreation
Browse files Browse the repository at this point in the history
No code repeated
  • Loading branch information
davbrican authored Jul 2, 2021
2 parents a31db50 + da827ff commit 181173e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
2 changes: 0 additions & 2 deletions consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,6 @@ async function notifyParticipants(sessionName, io) {
}
}

participantNumber = 0;

for(i=0;i<roomCount;i++){
let peer1 = femaleList[i];
let peer2 = maleList[i];
Expand Down
35 changes: 17 additions & 18 deletions routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,27 @@ router.post("/login", (req, res) => {
);
});


async function findOneUser(newCode,repeated) {
await User.findOne({ code: newCode, environment: process.env.NODE_ENV },
(err, user) => {
if (user!=null) {
newCode = Math.floor(Math.random() * 1000000 + 1);
} else {
repeated = false;
}
});
return [newCode, repeated];
};
router.post("/signup", async (req, res) => {
const code = Math.floor(Math.random() * 1000000 + 1);
/*
//code = 350526; Example of an already created user code
try {
const userFound = await User.findOne({
code: code,
environment: process.env.NODE_ENV,
}).then(async(response) => {
console.log(response);
});
while (userFound!=null) {
code = Math.floor(Math.random() * 1000000 + 1);
}
} catch (error) {
;
resultFindUser = await findOneUser(Math.floor(Math.random() * 1000000 + 1), true);
while (resultFindUser[1]) {
resultFindUser = await findOneUser(resultFindUser[0], true);
}
*/

const newCode = resultFindUser[0];
const newUser = new User(req.body);
newUser.code = code;
newUser.code = newCode;

const session = await Session.findOne({
name: req.body.subject,
Expand Down

0 comments on commit 181173e

Please sign in to comment.