Skip to content

Commit 6dfbd59

Browse files
committed
added validation for account merge
1 parent 0fe0b12 commit 6dfbd59

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

Confab/Exceptions/Exceptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ public class UserCommentRateLimitException : Exception { }
3232
public class EditHistoryDisabledException : Exception { }
3333
public class AnonymousCommentingDisabledException : Exception { }
3434
public class CaptchaVerificationFailedException : Exception { }
35+
public class InvalidAnonUserForMergeException : Exception { }
3536
}

Confab/Program.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,14 @@
449449
return Results.BadRequest(new LoginResponse());
450450
}
451451

452+
if (ex is InvalidAnonUserForMergeException)
453+
{
454+
return Results.BadRequest(new LoginResponse
455+
{
456+
Outcome = LoginOutcome.VerificationCodeGenericFailure
457+
});
458+
}
459+
452460
app.Logger.LogError(ex.ToString());
453461
return Results.StatusCode(500);
454462
}

Confab/Services/UserService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,10 @@ public async Task<LoginResponse> Login(UserLogin userLogin, HttpContext httpCont
248248
} catch (MissingAuthorizationException) {} //if no JWT, don't assign anonUser
249249

250250
if (user == null) //if user doesn't exist, can't login
251-
{
252251
throw new UserNotFoundException();
253-
}
252+
253+
if (anonUser != null && (anonUser.IsAnon == false || user == anonUser)) // validate anon user
254+
throw new InvalidAnonUserForMergeException();
254255

255256
await VerifyUserLoginEnabled(user, dbCtx);
256257

0 commit comments

Comments
 (0)