mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-01 04:34:50 -04:00
Fix external token edit detection
This commit is contained in:
parent
93decb02af
commit
6933aecfa4
@ -60,7 +60,7 @@ public class JwtToken(string accessToken, string refreshToken, TimeSpan expireIn
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("expire_in")]
|
[JsonProperty("expire_in")]
|
||||||
[JsonPropertyName("expire_in")]
|
[JsonPropertyName("expire_in")]
|
||||||
public TimeSpan ExpireIn { get; set; } = expireIn;
|
public TimeSpan ExpireIn => ExpireAt.Subtract(DateTime.UtcNow);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The exact date at which the access token will expire.
|
/// The exact date at which the access token will expire.
|
||||||
|
@ -43,18 +43,13 @@ public class UserRepository(
|
|||||||
IThumbnailsManager thumbs
|
IThumbnailsManager thumbs
|
||||||
) : LocalRepository<User>(database, thumbs)
|
) : LocalRepository<User>(database, thumbs)
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// The database handle
|
|
||||||
/// </summary>
|
|
||||||
private readonly DatabaseContext _database = database;
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task<ICollection<User>> Search(
|
public override async Task<ICollection<User>> Search(
|
||||||
string query,
|
string query,
|
||||||
Include<User>? include = default
|
Include<User>? include = default
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return await AddIncludes(_database.Users, include)
|
return await AddIncludes(database.Users, include)
|
||||||
.Where(x => EF.Functions.ILike(x.Username, $"%{query}%"))
|
.Where(x => EF.Functions.ILike(x.Username, $"%{query}%"))
|
||||||
.Take(20)
|
.Take(20)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
@ -64,7 +59,7 @@ public class UserRepository(
|
|||||||
public override async Task<User> Create(User obj)
|
public override async Task<User> Create(User obj)
|
||||||
{
|
{
|
||||||
// If no users exists, the new one will be an admin. Give it every permissions.
|
// If no users exists, the new one will be an admin. Give it every permissions.
|
||||||
if (!await _database.Users.AnyAsync())
|
if (!await database.Users.AnyAsync())
|
||||||
{
|
{
|
||||||
obj.Permissions = Enum.GetNames<Group>()
|
obj.Permissions = Enum.GetNames<Group>()
|
||||||
.Where(x => x != nameof(Group.None))
|
.Where(x => x != nameof(Group.None))
|
||||||
@ -74,8 +69,8 @@ public class UserRepository(
|
|||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
await base.Create(obj);
|
await base.Create(obj);
|
||||||
_database.Entry(obj).State = EntityState.Added;
|
database.Entry(obj).State = EntityState.Added;
|
||||||
await _database.SaveChangesAsync(() => Get(obj.Slug));
|
await database.SaveChangesAsync(() => Get(obj.Slug));
|
||||||
await IRepository<User>.OnResourceCreated(obj);
|
await IRepository<User>.OnResourceCreated(obj);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
@ -83,8 +78,8 @@ public class UserRepository(
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task Delete(User obj)
|
public override async Task Delete(User obj)
|
||||||
{
|
{
|
||||||
_database.Entry(obj).State = EntityState.Deleted;
|
database.Entry(obj).State = EntityState.Deleted;
|
||||||
await _database.SaveChangesAsync();
|
await database.SaveChangesAsync();
|
||||||
await base.Delete(obj);
|
await base.Delete(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,6 +109,8 @@ public class UserRepository(
|
|||||||
{
|
{
|
||||||
User user = await GetWithTracking(userId);
|
User user = await GetWithTracking(userId);
|
||||||
user.ExternalId[provider] = token;
|
user.ExternalId[provider] = token;
|
||||||
|
// without that, the change tracker does not find the modification. /shrug
|
||||||
|
database.Entry(user).Property(x => x.ExternalId).IsModified = true;
|
||||||
await database.SaveChangesAsync();
|
await database.SaveChangesAsync();
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
@ -122,6 +119,8 @@ public class UserRepository(
|
|||||||
{
|
{
|
||||||
User user = await GetWithTracking(userId);
|
User user = await GetWithTracking(userId);
|
||||||
user.ExternalId.Remove(provider);
|
user.ExternalId.Remove(provider);
|
||||||
|
// without that, the change tracker does not find the modification. /shrug
|
||||||
|
database.Entry(user).Property(x => x.ExternalId).IsModified = true;
|
||||||
await database.SaveChangesAsync();
|
await database.SaveChangesAsync();
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user