🐛 Trying to fix check in locking
This commit is contained in:
parent
68399dd371
commit
c562f52538
@ -362,14 +362,21 @@ public class AccountController(
|
|||||||
if (!isAvailable)
|
if (!isAvailable)
|
||||||
return BadRequest("Check-in is not available for today.");
|
return BadRequest("Check-in is not available for today.");
|
||||||
|
|
||||||
var needsCaptcha = await events.CheckInDailyDoAskCaptcha(currentUser);
|
try
|
||||||
return needsCaptcha switch
|
|
||||||
{
|
{
|
||||||
true when string.IsNullOrWhiteSpace(captchaToken) => StatusCode(423,
|
var needsCaptcha = await events.CheckInDailyDoAskCaptcha(currentUser);
|
||||||
"Captcha is required for this check-in."),
|
return needsCaptcha switch
|
||||||
true when !await auth.ValidateCaptcha(captchaToken!) => BadRequest("Invalid captcha token."),
|
{
|
||||||
_ => await events.CheckInDaily(currentUser)
|
true when string.IsNullOrWhiteSpace(captchaToken) => StatusCode(423,
|
||||||
};
|
"Captcha is required for this check-in."),
|
||||||
|
true when !await auth.ValidateCaptcha(captchaToken!) => BadRequest("Invalid captcha token."),
|
||||||
|
_ => await events.CheckInDaily(currentUser)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (InvalidOperationException ex)
|
||||||
|
{
|
||||||
|
return BadRequest(ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("me/calendar")]
|
[HttpGet("me/calendar")]
|
||||||
|
@ -142,7 +142,8 @@ public class AccountEventService(
|
|||||||
public async Task<CheckInResult> CheckInDaily(Account user)
|
public async Task<CheckInResult> CheckInDaily(Account user)
|
||||||
{
|
{
|
||||||
var lockKey = $"{CheckInLockKey}{user.Id}";
|
var lockKey = $"{CheckInLockKey}{user.Id}";
|
||||||
var lk = await cache.AcquireLockAsync(lockKey, TimeSpan.FromMinutes(10), TimeSpan.Zero);
|
|
||||||
|
await using var lk = await cache.AcquireLockAsync(lockKey, TimeSpan.FromMinutes(10), TimeSpan.Zero);
|
||||||
if (lk is null) throw new InvalidOperationException("Check-in was in progress.");
|
if (lk is null) throw new InvalidOperationException("Check-in was in progress.");
|
||||||
|
|
||||||
var cultureInfo = new CultureInfo(user.Language, false);
|
var cultureInfo = new CultureInfo(user.Language, false);
|
||||||
@ -212,7 +213,7 @@ public class AccountEventService(
|
|||||||
ActivityVisibility.Friends
|
ActivityVisibility.Friends
|
||||||
);
|
);
|
||||||
|
|
||||||
await lk.ReleaseAsync();
|
// The lock will be automatically released by the await using statement
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user