Done some todo's and removed old TL tags

This commit is contained in:
Marcel Baumgartner
2023-11-16 00:48:06 +01:00
parent 7145890801
commit 3a53fa0a3c
11 changed files with 60 additions and 17 deletions

View File

@@ -32,6 +32,10 @@ public class ConfigV1
[JsonProperty("EnableEmailVerify")] [JsonProperty("EnableEmailVerify")]
[Description("This will users force to verify their email address if they havent already")] [Description("This will users force to verify their email address if they havent already")]
public bool EnableEmailVerify { get; set; } = false; public bool EnableEmailVerify { get; set; } = false;
[JsonProperty("EnableReverseProxyMode")]
[Description("Enable this option if you are using a reverse proxy to access moonlight. This will configure some parts of moonlight to act correctly like the ip detection")]
public bool EnableReverseProxyMode { get; set; } = false;
} }
public class DatabaseData public class DatabaseData
@@ -69,5 +73,9 @@ public class ConfigV1
[JsonProperty("Password")] public string Password { get; set; } = "s3cr3t"; [JsonProperty("Password")] public string Password { get; set; } = "s3cr3t";
[JsonProperty("UseSsl")] public bool UseSsl { get; set; } = true; [JsonProperty("UseSsl")] public bool UseSsl { get; set; } = true;
[JsonProperty("SenderName")]
[Description("This will be shown as the system emails sender name in apps like gmail")]
public string SenderName { get; set; } = "Moonlight System";
} }
} }

View File

@@ -116,8 +116,6 @@ public class PostService
if(await CheckTextForBadWords(content)) if(await CheckTextForBadWords(content))
throw new DisplayException("Bad word detected. Please follow the community rules"); throw new DisplayException("Bad word detected. Please follow the community rules");
//TODO: Swear word filter
var comment = new PostComment() var comment = new PostComment()
{ {
Author = user, Author = user,

View File

@@ -28,7 +28,7 @@ public class MailService
var message = new MimeMessage(); var message = new MimeMessage();
message.From.Add(new MailboxAddress( message.From.Add(new MailboxAddress(
"Moonlight System", //TODO: Replace with config option config.SenderName,
config.Email config.Email
)); ));

View File

@@ -11,16 +11,19 @@ public class StoreAdminService
{ {
private readonly Repository<Product> ProductRepository; private readonly Repository<Product> ProductRepository;
private readonly Repository<Category> CategoryRepository; private readonly Repository<Category> CategoryRepository;
private readonly Repository<Service> ServiceRepository;
private readonly ServiceService ServiceService; private readonly ServiceService ServiceService;
public StoreAdminService( public StoreAdminService(
Repository<Product> productRepository, Repository<Product> productRepository,
Repository<Category> categoryRepository, Repository<Category> categoryRepository,
ServiceService serviceService) ServiceService serviceService,
Repository<Service> serviceRepository)
{ {
ProductRepository = productRepository; ProductRepository = productRepository;
CategoryRepository = categoryRepository; CategoryRepository = categoryRepository;
ServiceService = serviceService; ServiceService = serviceService;
ServiceRepository = serviceRepository;
} }
public Task<Category> AddCategory(string name, string description, string slug) public Task<Category> AddCategory(string name, string description, string slug)
@@ -96,7 +99,8 @@ public class StoreAdminService
public Task DeleteProduct(Product product) public Task DeleteProduct(Product product)
{ {
//TODO: Implement checks if services with that product id exist if (ServiceRepository.Get().Any(x => x.Product.Id == product.Id))
throw new DisplayException("Product cannot be deleted as services related to this products exist. Delete the services first");
ProductRepository.Delete(product); ProductRepository.Delete(product);

View File

@@ -0,0 +1,34 @@
using Moonlight.App.Helpers;
namespace Moonlight.App.Services.Utils;
public class ConnectionService
{
private readonly IHttpContextAccessor ContextAccessor;
private readonly ConfigService ConfigService;
public ConnectionService(IHttpContextAccessor contextAccessor, ConfigService configService)
{
ContextAccessor = contextAccessor;
ConfigService = configService;
}
public Task<string> GetIpAddress()
{
if (ContextAccessor.HttpContext == null)
return Task.FromResult("N/A (Missing http context)");
var request = ContextAccessor.HttpContext.Request;
if (request.Headers.ContainsKey("X-Real-IP"))
{
if(ConfigService.Get().Security.EnableReverseProxyMode)
return Task.FromResult(request.Headers["X-Real-IP"].ToString());
Logger.Warn($"Detected an ip mask attempt by using a fake X-Real-IP header. Fake IP: {request.Headers["X-Real-IP"]}. Real IP: {ContextAccessor.HttpContext.Connection.RemoteIpAddress}");
return Task.FromResult(ContextAccessor.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "N/A (Remote IP missing)");
}
return Task.FromResult(ContextAccessor.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "N/A (Remote IP missing)");
}
}

View File

@@ -50,6 +50,7 @@ builder.Services.AddScoped(typeof(Repository<>));
// Services / Utils // Services / Utils
builder.Services.AddScoped<JwtService>(); builder.Services.AddScoped<JwtService>();
builder.Services.AddScoped<ConnectionService>();
// Services / Interop // Services / Interop
builder.Services.AddScoped<CookieService>(); builder.Services.AddScoped<CookieService>();

View File

@@ -18,7 +18,7 @@
<div class="alert alert-danger bg-danger text-white p-10 mb-3"> <div class="alert alert-danger bg-danger text-white p-10 mb-3">
@foreach (var msg in ErrorMessages) @foreach (var msg in ErrorMessages)
{ {
<TL>@(msg)</TL> @(msg)
<br/> <br/>
} }
</div> </div>

View File

@@ -8,7 +8,7 @@
@if (Crashed) @if (Crashed)
{ {
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development" || IdentityService.Permissions[Permission.AdminViewExceptions]) // TODO: Add check for admin perms to show exceptions to admins if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development" || IdentityService.Permissions[Permission.AdminViewExceptions])
{ {
if (Exception != null) if (Exception != null)
{ {

View File

@@ -3,6 +3,7 @@
@using Moonlight.App.Models.Enums @using Moonlight.App.Models.Enums
@using Moonlight.Shared.Components.Auth @using Moonlight.Shared.Components.Auth
@using Moonlight.App.Event @using Moonlight.App.Event
@using Moonlight.App.Services.Utils
@inherits LayoutComponentBase @inherits LayoutComponentBase
@implements IDisposable @implements IDisposable
@@ -12,7 +13,7 @@
@inject IdentityService IdentityService @inject IdentityService IdentityService
@inject SessionService SessionService @inject SessionService SessionService
@inject NavigationManager Navigation @inject NavigationManager Navigation
@inject IJSRuntime JsRuntime @inject ConnectionService ConnectionService
@{ @{
var url = new Uri(Navigation.Uri); var url = new Uri(Navigation.Uri);
@@ -140,7 +141,7 @@ else
MySession = new() MySession = new()
{ {
//Ip = ConnectionService.GetIp(), TODO: Implement Ip = await ConnectionService.GetIpAddress(),
Url = Navigation.Uri, Url = Navigation.Uri,
User = IdentityService.CurrentUserNullable User = IdentityService.CurrentUserNullable
}; };

View File

@@ -24,7 +24,7 @@
<div class="row align-items-center gx-0"> <div class="row align-items-center gx-0">
<div class="col"> <div class="col">
<h6 class="text-uppercase text-muted mb-2"> <h6 class="text-uppercase text-muted mb-2">
<TL>Total Tickets</TL> Total Tickets
</h6> </h6>
<span class="h2 mb-0"> <span class="h2 mb-0">
@(TotalTicketsCount) @(TotalTicketsCount)
@@ -45,7 +45,7 @@
<div class="row align-items-center gx-0"> <div class="row align-items-center gx-0">
<div class="col"> <div class="col">
<h6 class="text-uppercase text-muted mb-2"> <h6 class="text-uppercase text-muted mb-2">
<TL>Pending tickets</TL> Pending tickets
</h6> </h6>
<span class="h2 mb-0"> <span class="h2 mb-0">
@(PendingTicketsCount) @(PendingTicketsCount)
@@ -66,7 +66,7 @@
<div class="row align-items-center gx-0"> <div class="row align-items-center gx-0">
<div class="col"> <div class="col">
<h6 class="text-uppercase text-muted mb-2"> <h6 class="text-uppercase text-muted mb-2">
<TL>Closed tickets</TL> Closed tickets
</h6> </h6>
<span class="h2 mb-0"> <span class="h2 mb-0">
@(ClosedTicketsCount) @(ClosedTicketsCount)
@@ -87,7 +87,7 @@
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
<span class="card-title"> <span class="card-title">
<TL>Ticket overview</TL> Ticket overview
</span> </span>
<div class="card-toolbar"> <div class="card-toolbar">
<div class="btn-group"> <div class="btn-group">

View File

@@ -11,16 +11,13 @@
@inject IdentityService IdentityService @inject IdentityService IdentityService
@inject AlertService AlertService @inject AlertService AlertService
@inject NavigationManager Navigation @inject NavigationManager Navigation
@inject ServiceService ServiceService
@inject Repository<Product> ProductRepository @inject Repository<Product> ProductRepository
@inject Repository<Coupon> CouponRepository @inject Repository<Coupon> CouponRepository
<LazyLoader Load="Load"> <LazyLoader Load="Load">
@if (SelectedProduct == null) @if (SelectedProduct == null)
{ {
@* <NotFoundAlert />
TODO: Add 404 here
*@
} }
else else
{ {