🐛 Fix update basic info didn't apply
This commit is contained in:
parent
b5226a72f2
commit
3d197b667a
@ -63,7 +63,7 @@ public class AccountController(
|
|||||||
[MaxLength(128)]
|
[MaxLength(128)]
|
||||||
public string Password { get; set; } = string.Empty;
|
public string Password { get; set; } = string.Empty;
|
||||||
|
|
||||||
[MaxLength(128)] public string Language { get; set; } = "en";
|
[MaxLength(128)] [RegularExpression("^[a-z]{2,3}$")] public string Language { get; set; } = "en-us";
|
||||||
|
|
||||||
[Required] public string CaptchaToken { get; set; } = string.Empty;
|
[Required] public string CaptchaToken { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
@ -140,22 +140,23 @@ public class AccountController(
|
|||||||
public class BasicInfoRequest
|
public class BasicInfoRequest
|
||||||
{
|
{
|
||||||
[MaxLength(256)] public string? Nick { get; set; }
|
[MaxLength(256)] public string? Nick { get; set; }
|
||||||
[MaxLength(32)] public string? Language { get; set; }
|
[MaxLength(32)] [RegularExpression("^[a-z]{2,3}$")] public string? Language { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[HttpPatch("me")]
|
[HttpPatch("me")]
|
||||||
public async Task<ActionResult<Account>> UpdateBasicInfo([FromBody] BasicInfoRequest request)
|
public async Task<ActionResult<Account>> UpdateBasicInfo([FromBody] BasicInfoRequest request)
|
||||||
{
|
{
|
||||||
if (HttpContext.Items["CurrentUser"] is not Account account) return Unauthorized();
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
|
||||||
|
|
||||||
|
var account = await db.Accounts.FirstAsync(a => a.Id == currentUser.Id);
|
||||||
|
|
||||||
if (request.Nick is not null) account.Nick = request.Nick;
|
if (request.Nick is not null) account.Nick = request.Nick;
|
||||||
if (request.Language is not null) account.Language = request.Language;
|
if (request.Language is not null) account.Language = request.Language;
|
||||||
|
|
||||||
await accounts.PurgeAccountCache(account);
|
|
||||||
|
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
return account;
|
await accounts.PurgeAccountCache(currentUser);
|
||||||
|
return currentUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ProfileRequest
|
public class ProfileRequest
|
||||||
|
@ -60,4 +60,23 @@ public class NotificationController(AppDatabase db, NotificationService nty) : C
|
|||||||
|
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpDelete("subscription")]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<ActionResult<int>> UnsubscribeFromPushNotification()
|
||||||
|
{
|
||||||
|
HttpContext.Items.TryGetValue("CurrentSession", out var currentSessionValue);
|
||||||
|
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
|
||||||
|
var currentUser = currentUserValue as Account;
|
||||||
|
if (currentUser == null) return Unauthorized();
|
||||||
|
var currentSession = currentSessionValue as Session;
|
||||||
|
if (currentSession == null) return Unauthorized();
|
||||||
|
|
||||||
|
var affectedRows = await db.NotificationPushSubscriptions
|
||||||
|
.Where(s =>
|
||||||
|
s.AccountId == currentUser.Id &&
|
||||||
|
s.DeviceId == currentSession.Challenge.DeviceId
|
||||||
|
).ExecuteDeleteAsync();
|
||||||
|
return Ok(affectedRows);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user