Skip to content

Commit

Permalink
Merge pull request #515 from sparcs-kaist/514-랜덤-이메일-업데이트
Browse files Browse the repository at this point in the history
#514 랜덤 이메일 업데이트
  • Loading branch information
kmc7468 authored May 21, 2024
2 parents ea0e957 + 28be0f0 commit ca94c72
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/services/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,36 @@ const joinus = async (req, userData) => {
};

const update = async (userData) => {
const updateInfo = { name: userData.name };
const updateInfo = {
name: userData.name,
email: userData.email,
"subinfo.kaist": userData.kaist,
};
await userModel.updateOne({ id: userData.id }, updateInfo);
logger.info(
`Update user info: ${userData.id} ${userData.name} ${userData.email} ${userData.kaist}`
);
};

const tryLogin = async (req, res, userData, redirectOrigin, redirectPath) => {
try {
const user = await userModel.findOne(
{ id: userData.id },
"_id name id withdraw ban"
"_id name email subinfo id withdraw ban"
);
if (!user) {
await joinus(req, userData);
return tryLogin(req, res, userData, redirectOrigin, redirectPath);
}
if (user.name != userData.name) {
if (
user.name !== userData.name ||
user.email !== userData.email ||
user.subinfo.kaist !== userData.kaist
) {
await update(userData);
logger.info(
`Past user info: ${user.id} ${user.name} ${user.email} ${user.subinfo.kaist}`
);
return tryLogin(req, res, userData, redirectOrigin, redirectPath);
}

Expand Down

0 comments on commit ca94c72

Please sign in to comment.