Skip to content

Commit

Permalink
Add: rejoin restriction after user withdrawal
Browse files Browse the repository at this point in the history
  • Loading branch information
kmc7468 committed Jan 22, 2025
1 parent d290945 commit aff0f86
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/modules/stores/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const userSchema = new Schema<User>({
ongoingRoom: [{ type: Schema.Types.ObjectId, ref: "Room" }], // 참여중인 진행중인 방 배열
doneRoom: [{ type: Schema.Types.ObjectId, ref: "Room" }], // 참여중인 완료된 방 배열
withdraw: { type: Boolean, default: false }, //탈퇴 여부
withdrawAt: { type: Date }, //탈퇴 시각
withdrewAt: { type: Date }, //탈퇴 시각
phoneNumber: { type: String }, // 전화번호 (2023FALL 이벤트부터 추가)
ban: { type: Boolean, default: false }, //계정 정지 여부
joinat: { type: Date, required: true }, //가입 시각
Expand Down
2 changes: 1 addition & 1 deletion src/schedules/deleteUserInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = async () => {
await userModel.updateMany(
{
withdraw: true,
withdrawAt: {
withdrewAt: {
$lte: new Date(Date.now() - 5 * 365 * 24 * 60 * 60 * 1000),
},
name: { $ne: "" },
Expand Down
28 changes: 26 additions & 2 deletions src/services/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ const transUserData = (userData) => {
};

const joinus = async (req, userData) => {
const oldUser = await userModel
.findOne(
{
id: userData.id,
withdraw: true,
},
"withdrewAt"
)
.sort({ withdrewAt: -1 })
.lean();
if (oldUser && oldUser.withdrewAt) {
// 탈퇴 후 7일이 지나지 않았을 경우, 가입을 거부합니다.
const diff = req.timestamp - oldUser.withdrewAt.getTime();
if (diff < 7 * 24 * 60 * 60 * 1000) {
return false;
}
}

const newUser = new userModel({
id: userData.id, // NOTE: SSO uid
name: userData.name,
Expand All @@ -51,6 +69,7 @@ const joinus = async (req, userData) => {
email: userData.email,
});
await newUser.save();
return true;
};

const update = async (userData) => {
Expand All @@ -72,8 +91,13 @@ const tryLogin = async (req, res, userData, redirectOrigin, redirectPath) => {
"_id name email subinfo id withdraw ban"
);
if (!user) {
await joinus(req, userData);
return tryLogin(req, res, userData, redirectOrigin, redirectPath);
if (await joinus(req, userData)) {
return tryLogin(req, res, userData, redirectOrigin, redirectPath);
} else {
const redirectUrl = new URL("/login/fail", redirectOrigin).href;
res.redirect(redirectUrl);
return;
}
}
if (
user.name !== userData.name ||
Expand Down
2 changes: 1 addition & 1 deletion src/services/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export const withdrawHandler: RequestHandler = async (req, res) => {

// 회원 탈퇴 처리 (Soft Delete)
user.withdraw = true;
user.withdrawAt = new Date(req.timestamp!);
user.withdrewAt = new Date(req.timestamp!);

await user.save();

Expand Down
2 changes: 1 addition & 1 deletion src/types/mongo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface User extends Document<Types.ObjectId> {
/** 계정 탈퇴 여부. */
withdraw: boolean;
/** 계정 탈퇴 시각. */
withdrawAt?: Date;
withdrewAt?: Date;
/** 사용자의 전화번호. 2023 가을 이벤트부터 추가됨. */
phoneNumber?: string;
/** 계정 정지 여부. */
Expand Down

0 comments on commit aff0f86

Please sign in to comment.