Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion API.IntegrationTests/API.IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<!-- Git stuff -->
<Target Name="SetHash" AfterTargets="InitializeSourceControlInformation">
<ItemGroup>
<AssemblyAttribute Include="OpenShock.Common.Utils.GitHashAttribute">
<AssemblyAttribute Include="OpenShock.Internal.Common.Utils.GitHashAttribute">
<_Parameter1>$(SourceRevisionId)</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion API.IntegrationTests/Docker/InMemoryDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Testcontainers.PostgreSql;
using TUnit.Core.Interfaces;

using OpenShock.Internal.Common.Utils;

namespace OpenShock.API.IntegrationTests.Docker;

public sealed class InMemoryDatabase : IAsyncInitializer, IAsyncDisposable
Expand All @@ -19,7 +21,7 @@ public PostgreSqlContainer Container
.WithName($"tunit-postgresql-{Guid.CreateVersion7()}")
.WithDatabase("openshock")
.WithUsername("openshock")
.WithPassword(CryptoUtils.RandomAlphaNumericString(32))
.WithPassword(CryptoUtils.RandomString(32))
.Build();

return _container;
Expand Down
6 changes: 4 additions & 2 deletions API.IntegrationTests/Helpers/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using OpenShock.Common.Services.Session;
using OpenShock.Common.Utils;

using OpenShock.Internal.Common.Utils;

namespace OpenShock.API.IntegrationTests.Helpers;

public static class TestHelper
Expand Down Expand Up @@ -126,7 +128,7 @@ public static async Task<Guid> CreateUserInDb(
var db = scope.ServiceProvider.GetRequiredService<OpenShockContext>();

var deviceId = Guid.CreateVersion7();
var token = CryptoUtils.RandomAlphaNumericString(256);
var token = CryptoUtils.RandomString(256);
db.Devices.Add(new Device
{
Id = deviceId,
Expand All @@ -151,7 +153,7 @@ public static async Task<Guid> CreateUserInDb(
await using var scope = factory.Services.CreateAsyncScope();
var db = scope.ServiceProvider.GetRequiredService<OpenShockContext>();

var rawToken = CryptoUtils.RandomAlphaNumericString(AuthConstants.ApiTokenLength);
var rawToken = CryptoUtils.RandomString(AuthConstants.ApiTokenLength);
var tokenId = Guid.CreateVersion7();
db.ApiTokens.Add(new ApiToken
{
Expand Down
4 changes: 3 additions & 1 deletion API.IntegrationTests/Tests/LcgAssignmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using OpenShock.Common.Utils;
using Redis.OM.Contracts;

using OpenShock.Internal.Common.Utils;

namespace OpenShock.API.IntegrationTests.Tests;

public sealed class LcgAssignmentTests
Expand All @@ -32,7 +34,7 @@ public async Task Setup()
// Set up variables
_userId = Guid.CreateVersion7();
_hubId = Guid.CreateVersion7();
_hubToken = CryptoUtils.RandomAlphaNumericString(256);
_hubToken = CryptoUtils.RandomString(256);

// Create mock data
db.Users.Add(new User
Expand Down
2 changes: 1 addition & 1 deletion API/API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<!-- Git stuff -->
<Target Name="SetHash" AfterTargets="InitializeSourceControlInformation">
<ItemGroup>
<AssemblyAttribute Include="OpenShock.Common.Utils.GitHashAttribute">
<AssemblyAttribute Include="OpenShock.Internal.Common.Utils.GitHashAttribute">
<_Parameter1>$(SourceRevisionId)</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions API/Controller/Account/Activate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using OpenShock.Common.Errors;
using OpenShock.Common.Problems;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Account;

public sealed partial class AccountController
Expand Down
4 changes: 4 additions & 0 deletions API/Controller/Account/Authenticated/ChangeEmail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
using OpenShock.Common.Problems;
using OpenShock.Common.Utils;

using OpenShock.Internal.Common.Utils;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Account.Authenticated;

public sealed partial class AuthenticatedAccountController
Expand Down
4 changes: 4 additions & 0 deletions API/Controller/Account/Authenticated/ChangePassword.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
using OpenShock.Common.Problems;
using OpenShock.Common.Utils;

using OpenShock.Internal.Common.Utils;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Account.Authenticated;

public sealed partial class AuthenticatedAccountController
Expand Down
2 changes: 2 additions & 0 deletions API/Controller/Account/Authenticated/ChangeUsername.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using OpenShock.Common.Problems;
using System.Net.Mime;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Account.Authenticated;

public sealed partial class AuthenticatedAccountController
Expand Down
2 changes: 2 additions & 0 deletions API/Controller/Account/Authenticated/Deactivate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using OpenShock.Common.Errors;
using OpenShock.Common.Problems;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Account.Authenticated;

public sealed partial class AuthenticatedAccountController
Expand Down
2 changes: 2 additions & 0 deletions API/Controller/Account/Login.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Microsoft.AspNetCore.Mvc;
using OpenShock.Common.Errors;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Account;

public sealed partial class AccountController
Expand Down
2 changes: 2 additions & 0 deletions API/Controller/Account/LoginV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using OpenShock.API.Models.Response;
using OpenShock.API.Services.Turnstile;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Account;

public sealed partial class AccountController
Expand Down
2 changes: 2 additions & 0 deletions API/Controller/Account/PasswordResetCheckValid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using OpenShock.Common.Problems;
using OpenShock.Common.Models;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Account;

public sealed partial class AccountController
Expand Down
2 changes: 2 additions & 0 deletions API/Controller/Account/PasswordResetComplete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using OpenShock.Common.Problems;
using OpenShock.Common.Models;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Account;

public sealed partial class AccountController
Expand Down
2 changes: 2 additions & 0 deletions API/Controller/Account/PasswordResetInitiateV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using OpenShock.Common.Errors;
using OpenShock.Common.Problems;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Account;

public sealed partial class AccountController
Expand Down
2 changes: 2 additions & 0 deletions API/Controller/Account/Signup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Microsoft.AspNetCore.Mvc;
using OpenShock.Common.Errors;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Account;

public sealed partial class AccountController
Expand Down
2 changes: 2 additions & 0 deletions API/Controller/Account/SignupV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using OpenShock.Common.Options;
using OpenShock.Common.Problems;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Account;

public sealed partial class AccountController
Expand Down
2 changes: 2 additions & 0 deletions API/Controller/Account/VerifyEmail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using OpenShock.Common.Errors;
using OpenShock.Common.Problems;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Account;

public sealed partial class AccountController
Expand Down
2 changes: 1 addition & 1 deletion API/Controller/Account/_Turnstile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using Microsoft.AspNetCore.Mvc;
using OpenShock.API.Errors;
using OpenShock.API.Services.Turnstile;
using OpenShock.Common.Problems;
using OpenShock.Common.Utils;
using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Account;

Expand Down
2 changes: 2 additions & 0 deletions API/Controller/Admin/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using OpenShock.Common.Services.Configuration;
using System.Net.Mime;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Admin;

public sealed partial class AdminController
Expand Down
6 changes: 4 additions & 2 deletions API/Controller/Admin/GetUsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
using OpenShock.Common.Extensions;
using OpenShock.Common.Models;
using OpenShock.Common.OpenShockDb;
using OpenShock.Common.Query;
using OpenShock.Internal.DynamicLinq.Query;
using System.ComponentModel.DataAnnotations;
using System.Net.Mime;
using Z.EntityFramework.Plus;

using OpenShock.Internal.DynamicLinq.Extensions;

namespace OpenShock.API.Controller.Admin;

public sealed partial class AdminController
Expand Down Expand Up @@ -38,7 +40,7 @@ public async Task<IActionResult> GetUsers(

if (!string.IsNullOrEmpty(orderbyQuery))
{
query = query.ApplyOrderBy(orderbyQuery);
query = OpenShock.Internal.DynamicLinq.Extensions.IQueryableExtensions.ApplyOrderBy(query, orderbyQuery);
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions API/Controller/Device/AssignLCG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using OpenShock.Common.Utils;
using OpenShock.Common.Models;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Device;

public sealed partial class DeviceController
Expand Down
2 changes: 2 additions & 0 deletions API/Controller/Device/AssignLCGV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using OpenShock.Common.Problems;
using OpenShock.Common.Utils;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Device;

public sealed partial class DeviceController
Expand Down
19 changes: 15 additions & 4 deletions API/Controller/Device/Pair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using OpenShock.Common.Problems;
using OpenShock.Common.Models;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Device;

public sealed partial class DeviceController
Expand Down Expand Up @@ -52,9 +54,18 @@ private async Task<IActionResult> PairInternal(string pairCode)
if (pair is null) return Problem(PairError.PairCodeNotFound);
await devicePairs.DeleteAsync(pair);

var deviceToken = await _db.Devices.Where(x => x.Id == pair.Id).Select(x => x.Token).FirstOrDefaultAsync();
if (deviceToken is null) throw new Exception("Device not found for pair code");
var device = await _db.Devices.Where(x => x.Id == pair.Id).Select(x => new { x.Token, x.OwnerId }).FirstOrDefaultAsync();
if (device is null) throw new Exception("Device not found for pair code");

try
{
await _deviceUpdateService.UpdateDevice(device.OwnerId, pair.Id, DeviceUpdateType.Paired);
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Failed to emit paired update for device {DeviceId}", pair.Id);
}

return LegacyDataOk(deviceToken);
return LegacyDataOk(device.Token);
}
}
}
5 changes: 4 additions & 1 deletion API/Controller/Device/_ApiController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenShock.API.Services.DeviceUpdate;
using OpenShock.Common;
using OpenShock.Common.Authentication;
using OpenShock.Common.OpenShockDb;
Expand All @@ -21,12 +22,14 @@ public sealed partial class DeviceController : OpenShockControllerBase
{
private readonly OpenShockContext _db;
private readonly IRedisConnectionProvider _redis;
private readonly IDeviceUpdateService _deviceUpdateService;
private readonly ILogger<DeviceController> _logger;

public DeviceController(OpenShockContext db, IRedisConnectionProvider redis, ILogger<DeviceController> logger)
public DeviceController(OpenShockContext db, IRedisConnectionProvider redis, IDeviceUpdateService deviceUpdateService, ILogger<DeviceController> logger)
{
_db = db;
_redis = redis;
_deviceUpdateService = deviceUpdateService;
_logger = logger;
}
}
2 changes: 2 additions & 0 deletions API/Controller/Devices/DeviceOtaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using OpenShock.Common.Problems;
using OpenShock.Common.Services.Ota;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Devices;

[ApiController]
Expand Down
10 changes: 8 additions & 2 deletions API/Controller/Devices/DevicesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
using OpenShock.API.Services.DeviceUpdate;
using Redis.OM;

using OpenShock.Internal.Common.Utils;

using OpenShock.Internal.Common.Constants;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Devices;

public sealed partial class DevicesController
Expand Down Expand Up @@ -112,7 +118,7 @@ public async Task<IActionResult> RegenerateDeviceToken([FromRoute] Guid deviceId
var device = await _db.Devices.FirstOrDefaultAsync(x => x.OwnerId == CurrentUser.Id && x.Id == deviceId);
if (device is null) return Problem(HubError.HubNotFound);

device.Token = CryptoUtils.RandomAlphaNumericString(256);
device.Token = CryptoUtils.RandomString(256);

var affected = await _db.SaveChangesAsync();
if (affected <= 0) throw new Exception("Failed to save regenerated token");
Expand Down Expand Up @@ -179,7 +185,7 @@ public async Task<IActionResult> CreateDeviceV2([FromBody] HubCreateRequest body
Id = Guid.CreateVersion7(),
OwnerId = CurrentUser.Id,
Name = body.Name,
Token = CryptoUtils.RandomAlphaNumericString(256)
Token = CryptoUtils.RandomString(256)
};
_db.Devices.Add(device);
await _db.SaveChangesAsync();
Expand Down
2 changes: 2 additions & 0 deletions API/Controller/Devices/GetShockers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using OpenShock.Common.Problems;
using OpenShock.Common.Models;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Devices;

public sealed partial class DevicesController
Expand Down
2 changes: 2 additions & 0 deletions API/Controller/Public/PublicShareController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using OpenShock.Common.Models;
using OpenShock.Common.Problems;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Public;

public sealed partial class PublicController
Expand Down
2 changes: 2 additions & 0 deletions API/Controller/Sessions/DeleteSessions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using OpenShock.Common.Problems;
using System.Net.Mime;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Sessions;

public sealed partial class SessionsController
Expand Down
2 changes: 2 additions & 0 deletions API/Controller/Shares/DeleteShareCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using OpenShock.Common.Models;
using OpenShock.Common.Problems;

using OpenShock.Internal.Common.Problems;

namespace OpenShock.API.Controller.Shares;

public sealed partial class SharesController
Expand Down
Loading