Skip to content

Commit

Permalink
Add Initial Support for Revoke Tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
TheR00st3r committed Nov 13, 2024
1 parent 57628ba commit 89c3808
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Models/Ticket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class Participant : IStoreObject
public Seat Seat { get; set; }

[JsonPropertyName("revoked")]
public bool Revoked { get; set; }
public int Revoked { get; set; }
}

public class User
Expand Down
6 changes: 3 additions & 3 deletions Pages/Components/ParticipantSignInPlaceComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,21 @@ public bool IsPaid

public bool IsCoronaChecked
{
get => _SettingsService.RetrieveEnableTwoGVerification() ? SignInPlace != null && SignInPlace.CoronaCheck != default : true;
get => !_SettingsService.RetrieveEnableTwoGVerification() || SignInPlace != null && SignInPlace.CoronaCheck != default;
set => ActionWithSave(() => SignInPlace.CoronaCheck = value ? DateTimeOffset.Now : default);
}

public bool IsCoronaTestChecked
{
get => _SettingsService.RetrieveEnableCovidTest() ? SignInPlace != null && SignInPlace.CoronaTestCheck != default : true;
get => !_SettingsService.RetrieveEnableCovidTest() || SignInPlace != null && SignInPlace.CoronaTestCheck != default;
set => ActionWithSave(() => SignInPlace.CoronaTestCheck = value ? DateTimeOffset.Now : default);
}

public bool IsCoronaTestDisabled => SignInPlace.Participant == null || Progress < 100;

public bool IsTermsChecked
{
get => _SettingsService.RetrieveEnableTermsChecked() ? SignInPlace != null && SignInPlace.Terms != default : true;
get => !_SettingsService.RetrieveEnableTermsChecked() || SignInPlace != null && SignInPlace.Terms != default;
set => ActionWithSave(() => SignInPlace.Terms = value ? DateTimeOffset.Now : default);
}

Expand Down
13 changes: 7 additions & 6 deletions Pages/Management.razor.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Microsoft.JSInterop;
using EventulaEntranceClient.Services;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.AspNetCore.Components;
using EventulaEntranceClient.Services.Interfaces;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.JSInterop;
using System.Timers;

namespace EventulaEntranceClient.Pages;
Expand Down Expand Up @@ -36,7 +36,7 @@ public partial class Management
private EventulaApiService _EventulaApiService { get; set; }

[Inject]
private SettingsService _SettingsService{ get; set; }
private SettingsService _SettingsService { get; set; }


[Inject]
Expand All @@ -50,7 +50,7 @@ public partial class Management

private string _LastTicket = string.Empty;

public List<ParticipantSignInPlace> ParticipantSignInPlaces { get; set; }
public List<ParticipantSignInPlace> ParticipantSignInPlaces { get; set; }

public List<Participant> Participants { get; set; } = new List<Participant>();

Expand Down Expand Up @@ -190,8 +190,9 @@ public async Task ProcessImage(string imageString)
var ticketRequest = await _EventulaApiService.RequestTicket(qrCode).ConfigureAwait(false);
if (ticketRequest?.Participant != null)
{
if(ticketRequest.Participant.Revoked)
if (ticketRequest.Participant.Revoked != 0)
{
// Todo Add Participant but disallow them to sign in
await _JSRuntime.InvokeAsync<string>("PlayAudio", "revokedParticipantSound");
}
else
Expand Down
26 changes: 13 additions & 13 deletions Pages/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@



<form @onsubmit=Submit>
<form @onsubmit=Save>
<h1 class="mb-3 font-weight-normal text-center">Settings</h1>

<div class="form-group">
<label class="lg-font">Eventula token</label>
<input class="form-control shadow-none transparent-input mb-3 lg-font" @bind="@EventulaToken" placeholder="Token" />
<input class="form-control shadow-none transparent-input mb-3 lg-font" @bind="@_EventulaToken" placeholder="Token" />
</div>
<div class="form-group">
<label class="lg-font">Eventula api base address</label>
<input class="form-control shadow-none transparent-input mb-3 lg-font" @bind="@EventulaApiBaseAddress" placeholder="https://yoursite.com" />
<input class="form-control shadow-none transparent-input mb-3 lg-font" @bind="@_EventulaApiBaseAddress" placeholder="https://yoursite.com" />
</div>
<div class="form-group">
<label class="lg-font">Admin Pin (sha256)</label>
<input class="form-control shadow-none transparent-input mb-3 lg-font" @bind="@AdminPin" />
<input class="form-control shadow-none transparent-input mb-3 lg-font" @bind="@_AdminPin" />
</div>
<div class="form-group">
<label class="lg-font">User Pin (sha256)</label>
<input class="form-control shadow-none transparent-input mb-3 lg-font" @bind="@UserPin" />
<input class="form-control shadow-none transparent-input mb-3 lg-font" @bind="@_UserPin" />
</div>
<div class="form-group">
<label class="lg-font">Number of Sign in Places on the grid (default 12)</label>
<p><input type="number" @bind="@SignInPlaceCount" /></p>
<p><input type="number" @bind="@_SignInPlaceCount" /></p>
</div>

<div class="form-group">
<label class="lg-font">Custom background image address</label>
<input class="form-control shadow-none transparent-input mb-3 lg-font" @bind="@CustomBackgroundImage" placeholder="https://yoursite.com/logo.jpg" />
<input class="form-control shadow-none transparent-input mb-3 lg-font" @bind="@_CustomBackgroundImage" placeholder="https://yoursite.com/logo.jpg" />
</div>
<div class="form-group">
<label class="lg-font">Enable covid test</label>
<p><input type="checkbox" @bind="@EnableCovidTest" /></p>
<p><input type="checkbox" @bind="@_EnableCovidTest" /></p>
</div>
<div class="form-group">
<label class="lg-font">Test time in minutes (default 15)</label>
<p><input type="number" @bind="@TestTimeInMinutes" /></p>
<p><input type="number" @bind="@_TestTimeInMinutes" /></p>
</div>
<div class="form-group">
<label class="lg-font">Enable 2G verification button</label>
<p><input type="checkbox" @bind="@EnableTwoGVerification" /></p>
<p><input type="checkbox" @bind="@_EnableTwoGVerification" /></p>
</div>
<div class="form-group">
<label class="lg-font">Enable terms checked button</label>
<p><input type="checkbox" @bind="@EnableTermsChecked" /></p>
<p><input type="checkbox" @bind="@_EnableTermsChecked" /></p>
</div>


Expand All @@ -55,8 +55,8 @@

<hr class="mb-4">
<div class="form-group">
<button class="btn btn-outline-primary shadow-none lg-font mb-3" type="submit" disabled="@ActiveParticipants">
@if (!@ActiveParticipants)
<button class="btn btn-outline-primary shadow-none lg-font mb-3" type="submit" disabled="@_ActiveParticipants">
@if (!_ActiveParticipants)
{
<text>Save</text>
}
Expand Down
82 changes: 39 additions & 43 deletions Pages/Settings.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,91 +9,87 @@ public partial class Settings
#region

[Inject]
private ILogger<Settings> _Logger { get; set; }
[Inject]
private ProtectionService _ProtectionService { get; set; }
private ProtectionService ProtectionService { get; set; }

[Inject]
private NavigationManager _NavigationManager { get; set; }
private NavigationManager NavigationManager { get; set; }

[Inject]
private SettingsService _SettingsService { get; set; }
private SettingsService SettingsService { get; set; }

[Inject]
private IDataStore _DataStore { get; set; }
private IDataStore DataStore { get; set; }

#endregion

public bool ActiveParticipants;
public string EventulaToken;
public string EventulaApiBaseAddress;
public bool EnableCovidTest;
public bool EnableTwoGVerification;
public bool EnableTermsChecked;
public int TestTimeInMinutes;
public int SignInPlaceCount;
public string CustomBackgroundImage;
public string AdminPin;
public string UserPin;

private bool _ActiveParticipants;
private string _EventulaToken;
private string _EventulaApiBaseAddress;
private bool _EnableCovidTest;
private bool _EnableTwoGVerification;
private bool _EnableTermsChecked;
private int _TestTimeInMinutes;
private int _SignInPlaceCount;
private string _CustomBackgroundImage;
private string _AdminPin;
private string _UserPin;

protected void Save()
{
if (ActiveParticipants)
if (_ActiveParticipants)
{
throw new Exception("Saving the settings is disabled while active participants are in place");
}
if (_SettingsService.SaveSettings(EventulaToken, EventulaApiBaseAddress, EnableCovidTest, EnableTwoGVerification, EnableTermsChecked, TestTimeInMinutes, CustomBackgroundImage, SignInPlaceCount, AdminPin, UserPin))

if (SettingsService.SaveSettings(_EventulaToken, _EventulaApiBaseAddress, _EnableCovidTest, _EnableTwoGVerification, _EnableTermsChecked, _TestTimeInMinutes, _CustomBackgroundImage, _SignInPlaceCount, _AdminPin, _UserPin))
{
_NavigationManager.NavigateTo("");
NavigationManager.NavigateTo("");
}
else
{
throw new Exception("Error while saving settings");
}
}

protected void Submit()
{
Save();
}

public override async Task SetParametersAsync(ParameterView parameters)
{
var uri = _NavigationManager.ToAbsoluteUri(_NavigationManager.Uri);
var uri = NavigationManager.ToAbsoluteUri(NavigationManager.Uri);
if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("ac", out var accessCode))
{
if (!_ProtectionService.CheckAdminAccessCodeHash(accessCode))
if (!ProtectionService.CheckAdminAccessCodeHash(accessCode))
{
_NavigationManager.NavigateTo("");
NavigationManager.NavigateTo("");
}
}
else
{
_NavigationManager.NavigateTo("");
NavigationManager.NavigateTo(string.Empty);
}
await base.SetParametersAsync(parameters);
}

protected override void OnInitialized()
{
var filtered = _DataStore.Load<ParticipantSignInPlace>().Where(e => e.Participant != null).ToArray();
ActiveParticipants = filtered.Count() > 0 ? true : false ;
var filtered = DataStore.Load<ParticipantSignInPlace>().Where(e => e.Participant != null).ToArray();
_ActiveParticipants = filtered.Length > 0;
}

protected override void OnParametersSet()
{
EventulaToken = _SettingsService.RetrieveToken();
EventulaApiBaseAddress = _SettingsService.RetrieveEventulaApiBaseAddress();
EnableCovidTest = _SettingsService.RetrieveEnableCovidTest();
EnableTwoGVerification = _SettingsService.RetrieveEnableTwoGVerification();
EnableTermsChecked = _SettingsService.RetrieveEnableTermsChecked();
TestTimeInMinutes = _SettingsService.RetrieveTestTimeInMinutes();
CustomBackgroundImage = _SettingsService.RetrieveCustomBackgroundImage();
SignInPlaceCount = _SettingsService.RetrieveSignInPlaceCount();
AdminPin = _SettingsService.RetrieveAdminPin();
UserPin = _SettingsService.RetrieveUserPin();
_EventulaToken = SettingsService.RetrieveToken();
_EventulaApiBaseAddress = SettingsService.RetrieveEventulaApiBaseAddress();
_EnableCovidTest = SettingsService.RetrieveEnableCovidTest();
_EnableTwoGVerification = SettingsService.RetrieveEnableTwoGVerification();
_EnableTermsChecked = SettingsService.RetrieveEnableTermsChecked();
_TestTimeInMinutes = SettingsService.RetrieveTestTimeInMinutes();
_CustomBackgroundImage = SettingsService.RetrieveCustomBackgroundImage();
_SignInPlaceCount = SettingsService.RetrieveSignInPlaceCount();
_AdminPin = SettingsService.RetrieveAdminPin();
_UserPin = SettingsService.RetrieveUserPin();
}

protected void Cancel()
{
_NavigationManager.NavigateTo("");
NavigationManager.NavigateTo(string.Empty);
}
}
4 changes: 3 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@

builder.Services.AddHttpClient(nameof(EventulaApiService), (serviceProvider, client) =>
{
var settingsService = serviceProvider.GetService<SettingsService>();
using var scope = serviceProvider.CreateScope();
var settingsService = scope.ServiceProvider.GetService<SettingsService>();
client.BaseAddress = new Uri(settingsService.RetrieveEventulaApiBaseAddress());
}).ConfigurePrimaryHttpMessageHandler(sp =>
{
Expand Down
14 changes: 5 additions & 9 deletions Services/ZXingBarcodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@ public string BarcodeTextFromImage(byte[] image)
{
try
{
using (var ms = new MemoryStream(image))
using var ms = new MemoryStream(image);
using var img = (Image<Rgb24>)Image.Load(ms);
var result = _BarcodeReader.Decode(img);
if (result != null)
{
using (var img = (Image<Rgb24>)Image.Load(ms))
{
var result = _BarcodeReader.Decode(img);
if (result != null)
{
return result.Text;
}
}
return result.Text;
}
}
catch(Exception ex)
Expand Down

0 comments on commit 89c3808

Please sign in to comment.