Skip to content

Commit 0ad65a8

Browse files
Additional sonar warnings
1 parent eeb2b79 commit 0ad65a8

File tree

3 files changed

+106
-106
lines changed

3 files changed

+106
-106
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
1-
using System;
2-
using System.Threading.Tasks;
3-
4-
using GenHTTP.Api.Content;
5-
using GenHTTP.Api.Content.Authentication;
6-
using GenHTTP.Api.Protocol;
7-
8-
using GenHTTP.Modules.Basics;
9-
using GenHTTP.Modules.Controllers;
10-
11-
namespace GenHTTP.Modules.Authentication.Web.Controllers
12-
{
13-
14-
public class LoginController : BaseController
15-
{
16-
17-
private Func<IRequest, string, string, ValueTask<IUser?>> PerformLogin { get; }
18-
19-
public LoginController(Func<IRequest, string, string, ValueTask<IUser?>> performLogin)
20-
{
21-
PerformLogin = performLogin;
22-
}
23-
24-
public IHandlerBuilder Index()
25-
{
26-
// ToDo: already logged in
27-
return RenderLogin(status: ResponseStatus.Unauthorized);
28-
}
29-
30-
[ControllerAction(RequestMethod.POST)]
31-
public async Task<IHandlerBuilder> Index(string user, string password, IRequest request)
32-
{
33-
if (string.IsNullOrWhiteSpace(user) || string.IsNullOrWhiteSpace(password))
34-
{
35-
return RenderLogin(user, "Please enter username and password.", status: ResponseStatus.BadRequest);
36-
}
37-
38-
var authenticatedUser = await PerformLogin(request, user, password);
39-
40-
if (authenticatedUser != null)
41-
{
42-
request.SetUser(authenticatedUser);
43-
44-
return Redirect.To("{web-auth}/", true);
45-
}
46-
else
47-
{
48-
return RenderLogin(user, "Invalid username or password.", status: ResponseStatus.Forbidden);
49-
}
50-
}
51-
52-
private IHandlerBuilder RenderLogin(string? username = null, string? errorMessage = null, ResponseStatus? status = null)
53-
=> RenderAccountEntry("Login", "Login", username, errorMessage, status);
54-
55-
}
56-
57-
}
1+
using System;
2+
using System.Threading.Tasks;
3+
4+
using GenHTTP.Api.Content;
5+
using GenHTTP.Api.Content.Authentication;
6+
using GenHTTP.Api.Protocol;
7+
8+
using GenHTTP.Modules.Basics;
9+
using GenHTTP.Modules.Controllers;
10+
11+
namespace GenHTTP.Modules.Authentication.Web.Controllers
12+
{
13+
14+
public class LoginController
15+
{
16+
17+
private Func<IRequest, string, string, ValueTask<IUser?>> PerformLogin { get; }
18+
19+
public LoginController(Func<IRequest, string, string, ValueTask<IUser?>> performLogin)
20+
{
21+
PerformLogin = performLogin;
22+
}
23+
24+
public IHandlerBuilder Index()
25+
{
26+
// ToDo: already logged in
27+
return RenderLogin(status: ResponseStatus.Unauthorized);
28+
}
29+
30+
[ControllerAction(RequestMethod.POST)]
31+
public async Task<IHandlerBuilder> Index(string user, string password, IRequest request)
32+
{
33+
if (string.IsNullOrWhiteSpace(user) || string.IsNullOrWhiteSpace(password))
34+
{
35+
return RenderLogin(user, "Please enter username and password.", status: ResponseStatus.BadRequest);
36+
}
37+
38+
var authenticatedUser = await PerformLogin(request, user, password);
39+
40+
if (authenticatedUser != null)
41+
{
42+
request.SetUser(authenticatedUser);
43+
44+
return Redirect.To("{web-auth}/", true);
45+
}
46+
else
47+
{
48+
return RenderLogin(user, "Invalid username or password.", status: ResponseStatus.Forbidden);
49+
}
50+
}
51+
52+
private static IHandlerBuilder RenderLogin(string? username = null, string? errorMessage = null, ResponseStatus? status = null)
53+
=> View.RenderAccountEntry("Login", "Login", username, errorMessage, status);
54+
55+
}
56+
57+
}
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1-
using System;
2-
using System.Threading.Tasks;
3-
4-
using GenHTTP.Api.Content;
5-
using GenHTTP.Api.Protocol;
6-
7-
using GenHTTP.Modules.Basics;
8-
using GenHTTP.Modules.Controllers;
9-
10-
namespace GenHTTP.Modules.Authentication.Web.Controllers
11-
{
12-
13-
public sealed class SetupController : BaseController
14-
{
15-
16-
private Func<IRequest, string, string, ValueTask> PerformSetup { get; }
17-
18-
public SetupController(Func<IRequest, string, string, ValueTask> performSetup)
19-
{
20-
PerformSetup = performSetup;
21-
}
22-
23-
public IHandlerBuilder Index()
24-
{
25-
return RenderSetup();
26-
}
27-
28-
[ControllerAction(RequestMethod.POST)]
29-
public async Task<IHandlerBuilder> Index(string user, string password, IRequest request)
30-
{
31-
if (string.IsNullOrWhiteSpace(user) || string.IsNullOrWhiteSpace(password))
32-
{
33-
return RenderSetup(user, "Please enter username and password.", ResponseStatus.BadRequest);
34-
}
35-
36-
await PerformSetup(request, user, password);
37-
38-
return Redirect.To("{login}/", true);
39-
}
40-
41-
private IHandlerBuilder RenderSetup(string? username = null, string? errorMessage = null, ResponseStatus? status = null)
42-
=> RenderAccountEntry("Setup", "Create Account", username, errorMessage, status);
43-
44-
}
45-
46-
}
1+
using System;
2+
using System.Threading.Tasks;
3+
4+
using GenHTTP.Api.Content;
5+
using GenHTTP.Api.Protocol;
6+
7+
using GenHTTP.Modules.Basics;
8+
using GenHTTP.Modules.Controllers;
9+
10+
namespace GenHTTP.Modules.Authentication.Web.Controllers
11+
{
12+
13+
public sealed class SetupController
14+
{
15+
16+
private Func<IRequest, string, string, ValueTask> PerformSetup { get; }
17+
18+
public SetupController(Func<IRequest, string, string, ValueTask> performSetup)
19+
{
20+
PerformSetup = performSetup;
21+
}
22+
23+
public IHandlerBuilder Index()
24+
{
25+
return RenderSetup();
26+
}
27+
28+
[ControllerAction(RequestMethod.POST)]
29+
public async Task<IHandlerBuilder> Index(string user, string password, IRequest request)
30+
{
31+
if (string.IsNullOrWhiteSpace(user) || string.IsNullOrWhiteSpace(password))
32+
{
33+
return RenderSetup(user, "Please enter username and password.", ResponseStatus.BadRequest);
34+
}
35+
36+
await PerformSetup(request, user, password);
37+
38+
return Redirect.To("{login}/", true);
39+
}
40+
41+
private static IHandlerBuilder RenderSetup(string? username = null, string? errorMessage = null, ResponseStatus? status = null)
42+
=> View.RenderAccountEntry("Setup", "Create Account", username, errorMessage, status);
43+
44+
}
45+
46+
}

Modules/Authentication.Web/Controllers/BaseController.cs Modules/Authentication.Web/Controllers/View.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
namespace GenHTTP.Modules.Authentication.Web.Controllers
1010
{
11-
12-
public class BaseController
11+
12+
public static class View
1313
{
1414

15-
protected static IHandlerBuilder RenderAccountEntry(string title, string buttonCaption, string? username = null, string? errorMessage = null, ResponseStatus? status = null)
15+
public static IHandlerBuilder RenderAccountEntry(string title, string buttonCaption, string? username = null, string? errorMessage = null, ResponseStatus? status = null)
1616
{
1717
var response = ModRazor.Page(Resource.FromAssembly("EnterAccount.cshtml"), (r, h) => new ViewModel<EnterAccountModel>(r, h, new(buttonCaption, username, errorMessage)))
1818
.AddStyle("{web-auth-resources}/style.css")

0 commit comments

Comments
 (0)