aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Security/AuthenticationRepository.cs
diff options
context:
space:
mode:
authorJoshua M. Boniface <joshua@boniface.me>2021-08-18 02:46:59 -0400
committerGitHub <noreply@github.com>2021-08-18 02:46:59 -0400
commit72d3f7020ad80ce1a53eeae8c5d57abeb22a4679 (patch)
treedd43e663838cdc7d99a4af565523df58ae23c856 /Emby.Server.Implementations/Security/AuthenticationRepository.cs
parent7aef0fce444e6d8e06386553ec7ea1401a01bbb1 (diff)
parente5cbafdb6b47377052e0d638908ef96e30a997d6 (diff)
Merge branch 'master' into patch-2
Diffstat (limited to 'Emby.Server.Implementations/Security/AuthenticationRepository.cs')
-rw-r--r--Emby.Server.Implementations/Security/AuthenticationRepository.cs68
1 files changed, 37 insertions, 31 deletions
diff --git a/Emby.Server.Implementations/Security/AuthenticationRepository.cs b/Emby.Server.Implementations/Security/AuthenticationRepository.cs
index 4dfadc703..e8eac315b 100644
--- a/Emby.Server.Implementations/Security/AuthenticationRepository.cs
+++ b/Emby.Server.Implementations/Security/AuthenticationRepository.cs
@@ -1,3 +1,5 @@
+#nullable disable
+
#pragma warning disable CS1591
using System;
@@ -54,7 +56,8 @@ namespace Emby.Server.Implementations.Security
{
if (tableNewlyCreated && TableExists(connection, "AccessTokens"))
{
- connection.RunInTransaction(db =>
+ connection.RunInTransaction(
+ db =>
{
var existingColumnNames = GetColumnNames(db, "AccessTokens");
@@ -88,7 +91,8 @@ namespace Emby.Server.Implementations.Security
using (var connection = GetConnection())
{
- connection.RunInTransaction(db =>
+ connection.RunInTransaction(
+ db =>
{
using (var statement = db.PrepareStatement("insert into Tokens (AccessToken, DeviceId, AppName, AppVersion, DeviceName, UserId, UserName, IsActive, DateCreated, DateLastActivity) values (@AccessToken, @DeviceId, @AppName, @AppVersion, @DeviceName, @UserId, @UserName, @IsActive, @DateCreated, @DateLastActivity)"))
{
@@ -119,7 +123,8 @@ namespace Emby.Server.Implementations.Security
using (var connection = GetConnection())
{
- connection.RunInTransaction(db =>
+ connection.RunInTransaction(
+ db =>
{
using (var statement = db.PrepareStatement("Update Tokens set AccessToken=@AccessToken, DeviceId=@DeviceId, AppName=@AppName, AppVersion=@AppVersion, DeviceName=@DeviceName, UserId=@UserId, UserName=@UserName, DateCreated=@DateCreated, DateLastActivity=@DateLastActivity where Id=@Id"))
{
@@ -151,7 +156,8 @@ namespace Emby.Server.Implementations.Security
using (var connection = GetConnection())
{
- connection.RunInTransaction(db =>
+ connection.RunInTransaction(
+ db =>
{
using (var statement = db.PrepareStatement("Delete from Tokens where Id=@Id"))
{
@@ -257,8 +263,7 @@ namespace Emby.Server.Implementations.Security
connection.RunInTransaction(
db =>
{
- var statements = PrepareAll(db, statementTexts)
- .ToList();
+ var statements = PrepareAll(db, statementTexts);
using (var statement = statements[0])
{
@@ -282,11 +287,11 @@ namespace Emby.Server.Implementations.Security
ReadTransactionMode);
}
- result.Items = list.ToArray();
+ result.Items = list;
return result;
}
- private static AuthenticationInfo Get(IReadOnlyList<IResultSetValue> reader)
+ private static AuthenticationInfo Get(IReadOnlyList<ResultSetValue> reader)
{
var info = new AuthenticationInfo
{
@@ -294,50 +299,49 @@ namespace Emby.Server.Implementations.Security
AccessToken = reader[1].ToString()
};
- if (reader[2].SQLiteType != SQLiteType.Null)
+ if (reader.TryGetString(2, out var deviceId))
{
- info.DeviceId = reader[2].ToString();
+ info.DeviceId = deviceId;
}
- if (reader[3].SQLiteType != SQLiteType.Null)
+ if (reader.TryGetString(3, out var appName))
{
- info.AppName = reader[3].ToString();
+ info.AppName = appName;
}
- if (reader[4].SQLiteType != SQLiteType.Null)
+ if (reader.TryGetString(4, out var appVersion))
{
- info.AppVersion = reader[4].ToString();
+ info.AppVersion = appVersion;
}
- if (reader[5].SQLiteType != SQLiteType.Null)
+ if (reader.TryGetString(6, out var userId))
{
- info.DeviceName = reader[5].ToString();
+ info.UserId = new Guid(userId);
}
- if (reader[6].SQLiteType != SQLiteType.Null)
+ if (reader.TryGetString(7, out var userName))
{
- info.UserId = new Guid(reader[6].ToString());
- }
-
- if (reader[7].SQLiteType != SQLiteType.Null)
- {
- info.UserName = reader[7].ToString();
+ info.UserName = userName;
}
info.DateCreated = reader[8].ReadDateTime();
- if (reader[9].SQLiteType != SQLiteType.Null)
+ if (reader.TryReadDateTime(9, out var dateLastActivity))
{
- info.DateLastActivity = reader[9].ReadDateTime();
+ info.DateLastActivity = dateLastActivity;
}
else
{
info.DateLastActivity = info.DateCreated;
}
- if (reader[10].SQLiteType != SQLiteType.Null)
+ if (reader.TryGetString(10, out var customName))
{
- info.DeviceName = reader[10].ToString();
+ info.DeviceName = customName;
+ }
+ else if (reader.TryGetString(5, out var deviceName))
+ {
+ info.DeviceName = deviceName;
}
return info;
@@ -347,7 +351,8 @@ namespace Emby.Server.Implementations.Security
{
using (var connection = GetConnection(true))
{
- return connection.RunInTransaction(db =>
+ return connection.RunInTransaction(
+ db =>
{
using (var statement = base.PrepareStatement(db, "select CustomName from Devices where Id=@DeviceId"))
{
@@ -357,9 +362,9 @@ namespace Emby.Server.Implementations.Security
foreach (var row in statement.ExecuteQuery())
{
- if (row[0].SQLiteType != SQLiteType.Null)
+ if (row.TryGetString(0, out var customName))
{
- result.CustomName = row[0].ToString();
+ result.CustomName = customName;
}
}
@@ -378,7 +383,8 @@ namespace Emby.Server.Implementations.Security
using (var connection = GetConnection())
{
- connection.RunInTransaction(db =>
+ connection.RunInTransaction(
+ db =>
{
using (var statement = db.PrepareStatement("replace into devices (Id, CustomName, Capabilities) VALUES (@Id, @CustomName, (Select Capabilities from Devices where Id=@Id))"))
{