Added subscription ui for user
This commit is contained in:
@@ -5,10 +5,12 @@ namespace Moonlight.App.Services.Interop;
|
||||
public class AlertService
|
||||
{
|
||||
private readonly SweetAlertService SweetAlertService;
|
||||
private readonly SmartTranslateService SmartTranslateService;
|
||||
|
||||
public AlertService(SweetAlertService service)
|
||||
public AlertService(SweetAlertService service, SmartTranslateService smartTranslateService)
|
||||
{
|
||||
SweetAlertService = service;
|
||||
SmartTranslateService = smartTranslateService;
|
||||
}
|
||||
|
||||
public async Task Info(string title, string desciption)
|
||||
@@ -21,6 +23,11 @@ public class AlertService
|
||||
});
|
||||
}
|
||||
|
||||
public async Task Info(string desciption)
|
||||
{
|
||||
await Info("", desciption);
|
||||
}
|
||||
|
||||
public async Task Success(string title, string desciption)
|
||||
{
|
||||
await SweetAlertService.FireAsync(new SweetAlertOptions()
|
||||
@@ -31,6 +38,11 @@ public class AlertService
|
||||
});
|
||||
}
|
||||
|
||||
public async Task Success(string desciption)
|
||||
{
|
||||
await Success("", desciption);
|
||||
}
|
||||
|
||||
public async Task Warning(string title, string desciption)
|
||||
{
|
||||
await SweetAlertService.FireAsync(new SweetAlertOptions()
|
||||
@@ -41,6 +53,11 @@ public class AlertService
|
||||
});
|
||||
}
|
||||
|
||||
public async Task Warning(string desciption)
|
||||
{
|
||||
await Warning("", desciption);
|
||||
}
|
||||
|
||||
public async Task Error(string title, string desciption)
|
||||
{
|
||||
await SweetAlertService.FireAsync(new SweetAlertOptions()
|
||||
@@ -51,6 +68,11 @@ public class AlertService
|
||||
});
|
||||
}
|
||||
|
||||
public async Task Error(string desciption)
|
||||
{
|
||||
await Error("", desciption);
|
||||
}
|
||||
|
||||
public async Task<bool> YesNo(string title, string desciption, string yesText, string noText)
|
||||
{
|
||||
var result = await SweetAlertService.FireAsync(new SweetAlertOptions()
|
||||
@@ -79,4 +101,27 @@ public class AlertService
|
||||
|
||||
return result.Value;
|
||||
}
|
||||
|
||||
public async Task<bool> ConfirmMath()
|
||||
{
|
||||
var r = new Random();
|
||||
var i1 = r.Next(5, 15);
|
||||
var i2 = r.Next(5, 15);
|
||||
|
||||
var input = await Text(
|
||||
SmartTranslateService.Translate("Confirm"),
|
||||
SmartTranslateService.Translate($"{i1} + {i2} ="),
|
||||
""
|
||||
);
|
||||
|
||||
if (int.TryParse(input, out int i))
|
||||
{
|
||||
if (i == i1 + i2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -15,4 +15,9 @@ public class ClipboardService
|
||||
{
|
||||
await JsRuntime.InvokeVoidAsync("copyTextToClipboard", data);
|
||||
}
|
||||
public async Task Copy(string data)
|
||||
{
|
||||
await JsRuntime.InvokeVoidAsync("copyTextToClipboard", data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -78,55 +78,45 @@ public class SubscriptionService
|
||||
await OneTimeJwtService.Revoke(code);
|
||||
}
|
||||
|
||||
public async Task Cancel()
|
||||
{
|
||||
if (await GetCurrent() != null)
|
||||
{
|
||||
var user = await GetCurrentUser();
|
||||
|
||||
user.CurrentSubscription = null;
|
||||
|
||||
UserRepository.Update(user);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<SubscriptionLimit> GetLimit(string identifier)
|
||||
{
|
||||
var configSection = ConfigService.GetSection("Moonlight").GetSection("Subscriptions");
|
||||
|
||||
var defaultLimits = configSection.GetValue<SubscriptionLimit[]>("DefaultLimits");
|
||||
|
||||
var subscription = await GetCurrent();
|
||||
|
||||
if (subscription == null)
|
||||
{
|
||||
if (defaultLimits != null)
|
||||
{
|
||||
var foundDefault = defaultLimits.FirstOrDefault(x => x.Identifier == identifier);
|
||||
|
||||
if (foundDefault != null)
|
||||
return foundDefault;
|
||||
}
|
||||
|
||||
return new()
|
||||
{
|
||||
Identifier = identifier,
|
||||
Amount = 0
|
||||
};
|
||||
}
|
||||
else
|
||||
|
||||
var subscriptionLimits =
|
||||
JsonConvert.DeserializeObject<SubscriptionLimit[]>(subscription.LimitsJson)
|
||||
?? Array.Empty<SubscriptionLimit>();
|
||||
|
||||
var foundLimit = subscriptionLimits.FirstOrDefault(x => x.Identifier == identifier);
|
||||
|
||||
if (foundLimit != null)
|
||||
return foundLimit;
|
||||
|
||||
return new()
|
||||
{
|
||||
var subscriptionLimits =
|
||||
JsonConvert.DeserializeObject<SubscriptionLimit[]>(subscription.LimitsJson)
|
||||
?? Array.Empty<SubscriptionLimit>();
|
||||
|
||||
var foundLimit = subscriptionLimits.FirstOrDefault(x => x.Identifier == identifier);
|
||||
|
||||
if (foundLimit != null)
|
||||
return foundLimit;
|
||||
|
||||
if (defaultLimits != null)
|
||||
{
|
||||
var foundDefault = defaultLimits.FirstOrDefault(x => x.Identifier == identifier);
|
||||
|
||||
if (foundDefault != null)
|
||||
return foundDefault;
|
||||
}
|
||||
|
||||
return new()
|
||||
{
|
||||
Identifier = identifier,
|
||||
Amount = 0
|
||||
};
|
||||
}
|
||||
Identifier = identifier,
|
||||
Amount = 0
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<User?> GetCurrentUser()
|
||||
|
||||
Reference in New Issue
Block a user