Skip to content

Commit eeb2b79

Browse files
Fix sonar issues
1 parent 3bab448 commit eeb2b79

File tree

6 files changed

+348
-342
lines changed

6 files changed

+348
-342
lines changed

Engine/Infrastructure/CoreRouter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public async ValueTask PrepareAsync()
8989

9090
public ValueTask RenderAsync(TemplateModel model, Stream target) => Template.RenderAsync(model, target);
9191

92-
private string RenderAdditions(IModel model, PageAdditions? additions)
92+
private static string RenderAdditions(IModel model, PageAdditions? additions)
9393
{
9494
var builder = new StringBuilder();
9595

Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
using GenHTTP.Api.Content;
2-
using GenHTTP.Api.Content.Templating;
3-
using GenHTTP.Api.Protocol;
4-
5-
using GenHTTP.Modules.Authentication.Web.ViewModels;
6-
using GenHTTP.Modules.IO;
7-
using GenHTTP.Modules.Razor;
8-
9-
namespace GenHTTP.Modules.Authentication.Web.Controllers
10-
{
11-
12-
public class BaseController
13-
{
14-
15-
protected IHandlerBuilder RenderAccountEntry(string title, string buttonCaption, string? username = null, string? errorMessage = null, ResponseStatus? status = null)
16-
{
17-
var response = ModRazor.Page(Resource.FromAssembly("EnterAccount.cshtml"), (r, h) => new ViewModel<EnterAccountModel>(r, h, new(buttonCaption, username, errorMessage)))
18-
.AddStyle("{web-auth-resources}/style.css")
19-
.Title(title);
20-
21-
if (status != null)
22-
{
23-
response.Status(status.Value);
24-
}
25-
26-
return response;
27-
}
28-
29-
}
30-
31-
}
1+
using GenHTTP.Api.Content;
2+
using GenHTTP.Api.Content.Templating;
3+
using GenHTTP.Api.Protocol;
4+
5+
using GenHTTP.Modules.Authentication.Web.ViewModels;
6+
using GenHTTP.Modules.IO;
7+
using GenHTTP.Modules.Razor;
8+
9+
namespace GenHTTP.Modules.Authentication.Web.Controllers
10+
{
11+
12+
public class BaseController
13+
{
14+
15+
protected static IHandlerBuilder RenderAccountEntry(string title, string buttonCaption, string? username = null, string? errorMessage = null, ResponseStatus? status = null)
16+
{
17+
var response = ModRazor.Page(Resource.FromAssembly("EnterAccount.cshtml"), (r, h) => new ViewModel<EnterAccountModel>(r, h, new(buttonCaption, username, errorMessage)))
18+
.AddStyle("{web-auth-resources}/style.css")
19+
.Title(title);
20+
21+
if (status != null)
22+
{
23+
response.Status(status.Value);
24+
}
25+
26+
return response;
27+
}
28+
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
1-
using System.Threading.Tasks;
2-
3-
using GenHTTP.Api.Content;
4-
using GenHTTP.Api.Content.Authentication;
5-
using GenHTTP.Api.Protocol;
6-
7-
using GenHTTP.Modules.Authentication.Web.Controllers;
8-
using GenHTTP.Modules.Controllers;
9-
using GenHTTP.Modules.IO;
10-
11-
namespace GenHTTP.Modules.Authentication.Web.Integration
12-
{
13-
14-
public class SimpleIntegrationAdapter : IWebAuthIntegration
15-
{
16-
private bool _AllowAnonymous;
17-
18-
private string _SetupRoute, _LoginRoute, _ResourceRoute;
19-
20-
bool IWebAuthIntegration.AllowAnonymous { get => _AllowAnonymous; }
21-
22-
string IWebAuthIntegration.SetupRoute { get => _SetupRoute; }
23-
24-
string IWebAuthIntegration.LoginRoute { get => _LoginRoute; }
25-
26-
string IWebAuthIntegration.ResourceRoute { get => _ResourceRoute; }
27-
28-
public IHandlerBuilder SetupHandler { get; private set; }
29-
30-
public IHandlerBuilder LoginHandler { get; private set; }
31-
32-
public IHandlerBuilder ResourceHandler { get; private set; }
33-
34-
private ISimpleWebAuthIntegration SimpleIntegration { get; }
35-
36-
public SimpleIntegrationAdapter(ISimpleWebAuthIntegration simpleIntegration)
37-
{
38-
SimpleIntegration = simpleIntegration;
39-
40-
_AllowAnonymous = simpleIntegration.AllowAnonymous;
41-
42-
_SetupRoute = simpleIntegration.SetupRoute;
43-
_LoginRoute = simpleIntegration.LoginRoute;
44-
_ResourceRoute = simpleIntegration.ResourceRoute;
45-
46-
SetupHandler = Controller.From(new SetupController((r, u, p) => simpleIntegration.PerformSetup(r, u, p)));
47-
LoginHandler = Controller.From(new LoginController((r, u, p) => simpleIntegration.PerformLogin(r, u, p)));
48-
49-
ResourceHandler = Resources.From(ResourceTree.FromAssembly("Resources"));
50-
}
51-
52-
public ValueTask<bool> CheckSetupRequired(IRequest request) => SimpleIntegration.CheckSetupRequired(request);
53-
54-
public ValueTask<string> StartSessionAsync(IRequest request, IUser user) => SimpleIntegration.StartSessionAsync(request, user);
55-
56-
public ValueTask<IUser?> VerifyTokenAsync(string sessionToken) => SimpleIntegration.VerifyTokenAsync(sessionToken);
57-
58-
}
59-
60-
}
1+
using System.Threading.Tasks;
2+
3+
using GenHTTP.Api.Content;
4+
using GenHTTP.Api.Content.Authentication;
5+
using GenHTTP.Api.Protocol;
6+
7+
using GenHTTP.Modules.Authentication.Web.Controllers;
8+
using GenHTTP.Modules.Controllers;
9+
using GenHTTP.Modules.IO;
10+
11+
namespace GenHTTP.Modules.Authentication.Web.Integration
12+
{
13+
14+
public class SimpleIntegrationAdapter : IWebAuthIntegration
15+
{
16+
private readonly bool _AllowAnonymous;
17+
18+
private readonly string _SetupRoute, _LoginRoute, _ResourceRoute;
19+
20+
bool IWebAuthIntegration.AllowAnonymous { get => _AllowAnonymous; }
21+
22+
string IWebAuthIntegration.SetupRoute { get => _SetupRoute; }
23+
24+
string IWebAuthIntegration.LoginRoute { get => _LoginRoute; }
25+
26+
string IWebAuthIntegration.ResourceRoute { get => _ResourceRoute; }
27+
28+
public IHandlerBuilder SetupHandler { get; private set; }
29+
30+
public IHandlerBuilder LoginHandler { get; private set; }
31+
32+
public IHandlerBuilder ResourceHandler { get; private set; }
33+
34+
private ISimpleWebAuthIntegration SimpleIntegration { get; }
35+
36+
public SimpleIntegrationAdapter(ISimpleWebAuthIntegration simpleIntegration)
37+
{
38+
SimpleIntegration = simpleIntegration;
39+
40+
_AllowAnonymous = simpleIntegration.AllowAnonymous;
41+
42+
_SetupRoute = simpleIntegration.SetupRoute;
43+
_LoginRoute = simpleIntegration.LoginRoute;
44+
_ResourceRoute = simpleIntegration.ResourceRoute;
45+
46+
SetupHandler = Controller.From(new SetupController((r, u, p) => simpleIntegration.PerformSetup(r, u, p)));
47+
LoginHandler = Controller.From(new LoginController((r, u, p) => simpleIntegration.PerformLogin(r, u, p)));
48+
49+
ResourceHandler = Resources.From(ResourceTree.FromAssembly("Resources"));
50+
}
51+
52+
public ValueTask<bool> CheckSetupRequired(IRequest request) => SimpleIntegration.CheckSetupRequired(request);
53+
54+
public ValueTask<string> StartSessionAsync(IRequest request, IUser user) => SimpleIntegration.StartSessionAsync(request, user);
55+
56+
public ValueTask<IUser?> VerifyTokenAsync(string sessionToken) => SimpleIntegration.VerifyTokenAsync(sessionToken);
57+
58+
}
59+
60+
}

Modules/Pages/Combined/CombinedPageBuilder.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ public CombinedPageBuilder Title(string title)
6666
return this;
6767
}
6868

69+
public CombinedPageBuilder AddScript(ScriptReference reference)
70+
{
71+
_Additions.Scripts.Add(reference);
72+
return this;
73+
}
74+
75+
public CombinedPageBuilder AddStyle(StyleReference reference)
76+
{
77+
_Additions.Styles.Add(reference);
78+
return this;
79+
}
80+
6981
/// <summary>
7082
/// Adds a dynamically rendered part to the page.
7183
/// </summary>
@@ -106,18 +118,6 @@ public CombinedPageBuilder Add(PageFragment fragment)
106118
return this;
107119
}
108120

109-
public CombinedPageBuilder AddScript(ScriptReference reference)
110-
{
111-
_Additions.Scripts.Add(reference);
112-
return this;
113-
}
114-
115-
public CombinedPageBuilder AddStyle(StyleReference reference)
116-
{
117-
_Additions.Styles.Add(reference);
118-
return this;
119-
}
120-
121121
public CombinedPageBuilder Add(IConcernBuilder concern)
122122
{
123123
_Concerns.Add(concern);

Modules/Placeholders/Providers/PlaceholderRendererBuilder.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using GenHTTP.Api.Infrastructure;
55
using GenHTTP.Api.Content.Templating;
66
using GenHTTP.Api.Content.IO;
7-
using GenHTTP.Api.Protocol;
87

98
namespace GenHTTP.Modules.Placeholders.Providers
109
{
@@ -13,7 +12,7 @@ public sealed class PlaceholderRendererBuilder<T> : IBuilder<IRenderer<T>> where
1312
{
1413
private IResource? _TemplateProvider;
1514

16-
private Dictionary<string, Func<IModel, object?, object?>> _CustomRenderers = new();
15+
private readonly Dictionary<string, Func<IModel, object?, object?>> _CustomRenderers = new();
1716

1817
#region Functionality
1918

0 commit comments

Comments
 (0)