Проведен аудит. Добавлено переключение треков
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PlaylistShared.Api.Entities;
|
||||
@@ -31,11 +31,7 @@ public class YandexAccountController : ControllerBase
|
||||
var user = await _userManager.FindByIdAsync(userId.ToString());
|
||||
if (user == null) return Unauthorized();
|
||||
|
||||
user.YandexAccessToken = _yandexService.Service.EncryptToken(request.Token);
|
||||
// Не храним refresh-токен, так как пользователь вводит только access-токен
|
||||
user.YandexTokenExpiryUtc = DateTime.UtcNow.AddMonths(1); // условно, т.к. срок жизни токена неизвестен
|
||||
await _userManager.UpdateAsync(user);
|
||||
|
||||
await SaveYandexTokenAsync(user, request.Token);
|
||||
return Ok(ApiResponse<object>.Ok(new { message = "Токен сохранён" }));
|
||||
}
|
||||
|
||||
@@ -65,7 +61,6 @@ public class YandexAccountController : ControllerBase
|
||||
if (user == null) return Unauthorized();
|
||||
|
||||
var qr = await _yandexService.GetQrOrGenerate(user);
|
||||
|
||||
return Ok(ApiResponse<YandexAuthQr>.Ok(qr));
|
||||
}
|
||||
|
||||
@@ -81,10 +76,16 @@ public class YandexAccountController : ControllerBase
|
||||
|
||||
if (checkResult.Status == Shared.Enums.YandexAuthQrStatus.Authorized)
|
||||
{
|
||||
await SetToken(new() { Token = _yandexService.Service.Client.AuthStorage.Token });
|
||||
|
||||
await SaveYandexTokenAsync(user, _yandexService.Service.Client.AuthStorage.Token);
|
||||
}
|
||||
|
||||
return Ok(ApiResponse<YandexAuthQrCheck>.Ok(checkResult));
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveYandexTokenAsync(ApplicationUser user, string token)
|
||||
{
|
||||
user.YandexAccessToken = _yandexService.Service.EncryptToken(token);
|
||||
user.YandexTokenExpiryUtc = DateTime.UtcNow.AddMonths(1);
|
||||
await _userManager.UpdateAsync(user);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user