diff --git a/Chatter/Chatter.csproj b/Chatter/Chatter.csproj
index 9645ce5..c696be1 100644
--- a/Chatter/Chatter.csproj
+++ b/Chatter/Chatter.csproj
@@ -7,10 +7,11 @@
+
-
+
diff --git a/Chatter/Logic/Actions/ListActionManager.cs b/Chatter/Logic/Actions/ListActionManager.cs
index c31f031..39537fd 100644
--- a/Chatter/Logic/Actions/ListActionManager.cs
+++ b/Chatter/Logic/Actions/ListActionManager.cs
@@ -4,19 +4,22 @@ using Cuipod;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Net;
namespace Chatter.Logic.Actions
{
- public static class ListActionManager
+ public class ListActionManager
{
- public static Action> GetListAction() =>
- (request, response, logger) => {
- var service = new MessageService();
+ public readonly IMessageService _messageService;
- IEnumerable messages = service.GetMessages();
+ public ListActionManager(IMessageService messageService)
+ {
+ _messageService = messageService;
+ }
+
+ public Action> GetListAction() =>
+ (request, response, logger) => {
+ IEnumerable messages = _messageService.GetMessages();
response.RenderPlainTextLine("# Chatter");
response.RenderPlainTextLine("");
@@ -47,7 +50,7 @@ namespace Chatter.Logic.Actions
//todo: pagination here?
};
- public static Action> PostAction() =>
+ public Action> PostAction() =>
(request, response, logger) => {
if (string.IsNullOrEmpty(request.Parameters))
{
@@ -56,17 +59,23 @@ namespace Chatter.Logic.Actions
}
else
{
+
// redirect to show/ route with input parameters
var model = new PostModel()
{
- Text = request.Parameters
+ Text = WebUtility.UrlDecode(request.Parameters)
};
- var service = new MessageService();
- service.AddMessage(model);
+ _messageService.AddMessage(model);
response.SetRedirectURL(request.BaseURL + "/list");
response.Status = StatusCode.RedirectTemp;
}
};
+
+ public Action> LoginAction() =>
+ (request, response, logger) => {
+ response.RenderPlainTextLine("Cert required");
+ response.Status = StatusCode.ClientCertRequired;
+ };
}
}
diff --git a/Chatter/Program.cs b/Chatter/Program.cs
index 3017fc8..00e4c22 100644
--- a/Chatter/Program.cs
+++ b/Chatter/Program.cs
@@ -1,6 +1,10 @@
-using Chatter.Logic.Actions;
+using Chatter.Connector;
+using Chatter.Logic.Actions;
+using Chatter.Repository;
+using Chatter.Service;
using Cuipod;
using Microsoft.Extensions.CommandLineUtils;
+using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Security.Cryptography.X509Certificates;
@@ -45,6 +49,17 @@ namespace Chatter
}
}
+ private static ServiceProvider GetServiceProvider()
+ {
+ var serviceCollection = new ServiceCollection();
+ serviceCollection.AddSingleton();
+ serviceCollection.AddScoped();
+ serviceCollection.AddScoped();
+ serviceCollection.AddScoped();
+
+ return serviceCollection.BuildServiceProvider();
+ }
+
private static int AppMain(string directoryToServe, X509Certificate2 certificate)
{
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
@@ -57,6 +72,8 @@ namespace Chatter
.SetMinimumLevel(LogLevel.Debug)
);
+ using var serviceProvider = GetServiceProvider();
+
ILogger logger = loggerFactory.CreateLogger();
App app = new App(
@@ -70,8 +87,9 @@ namespace Chatter
response.RenderFileContent("index.gmi");
});
- app.OnRequest("/list", ListActionManager.GetListAction());
- app.OnRequest("/post", ListActionManager.PostAction());
+ app.OnRequest("/list", serviceProvider.GetService().GetListAction());
+ app.OnRequest("/post", serviceProvider.GetService().PostAction());
+ app.OnRequest("/login", serviceProvider.GetService().LoginAction());
app.Run();
diff --git a/Chatter/Repository/MessageRepository.cs b/Chatter/Repository/MessageRepository.cs
index 96d8b59..a10a955 100644
--- a/Chatter/Repository/MessageRepository.cs
+++ b/Chatter/Repository/MessageRepository.cs
@@ -20,24 +20,19 @@ namespace Chatter.Repository
{
private readonly IDbConnector _connector;
- public MessageRepository()
+ public MessageRepository(IDbConnector connector)
{
+ _connector = connector;
}
public void AddMessage(MessageDto msg)
{
- using (var connector = new SqLiteConnector())
- {
- connector.AddMessage(msg);
- }
+ _connector.AddMessage(msg);
}
public IEnumerable GetMessages()
{
- using (var connector = new SqLiteConnector())
- {
- return connector.GetMessages();
- }
+ return _connector.GetMessages();
}
}
}
diff --git a/Chatter/Service/MessageService.cs b/Chatter/Service/MessageService.cs
index 3f5ba62..0ec6233 100644
--- a/Chatter/Service/MessageService.cs
+++ b/Chatter/Service/MessageService.cs
@@ -20,9 +20,9 @@ namespace Chatter.Service
{
public readonly IMessageRepository _repository;
- public MessageService()
+ public MessageService(IMessageRepository repository)
{
- _repository = new MessageRepository();
+ _repository = repository;
}
public IEnumerable GetMessages()
diff --git a/Chatter/static/index.gmi b/Chatter/static/index.gmi
index 7c4e3e7..f599a86 100644
--- a/Chatter/static/index.gmi
+++ b/Chatter/static/index.gmi
@@ -1,9 +1,7 @@
# Chatter gemini app
-This is chatter gemini app. An application can be used for chat with several different users. The idea of the project is to have the least amount of data stored permanently.
-## Requirements:
-* redis -- messages
-* nosql database -- permanent userdata
+This is chatter gemini app. An application can be used for chat with several different users. The idea of the project is to have the least amount of data stored permanently. This project uses sqlite in-memory database to store messages which means every time you reload it you lose all data.
+
=> /list Message list
=> /post Post message
\ No newline at end of file
diff --git a/Cuipod.sln b/Cuipod.sln
index 8aad270..9552188 100644
--- a/Cuipod.sln
+++ b/Cuipod.sln
@@ -5,9 +5,7 @@ VisualStudioVersion = 17.0.31919.166
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cuipod", "Cuipod\Cuipod.csproj", "{2B6AD5A5-F10B-4FC3-BF12-5DD26FAF3796}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CuipodExample", "CuipodExample\CuipodExample.csproj", "{BD343B0B-29EB-4498-8CD2-D9483B6BDA98}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chatter", "Chatter\Chatter.csproj", "{20C8B6F9-63FB-458D-921E-5DFD6EBE4435}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chatter", "Chatter\Chatter.csproj", "{20C8B6F9-63FB-458D-921E-5DFD6EBE4435}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -19,10 +17,6 @@ Global
{2B6AD5A5-F10B-4FC3-BF12-5DD26FAF3796}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B6AD5A5-F10B-4FC3-BF12-5DD26FAF3796}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B6AD5A5-F10B-4FC3-BF12-5DD26FAF3796}.Release|Any CPU.Build.0 = Release|Any CPU
- {BD343B0B-29EB-4498-8CD2-D9483B6BDA98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {BD343B0B-29EB-4498-8CD2-D9483B6BDA98}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {BD343B0B-29EB-4498-8CD2-D9483B6BDA98}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {BD343B0B-29EB-4498-8CD2-D9483B6BDA98}.Release|Any CPU.Build.0 = Release|Any CPU
{20C8B6F9-63FB-458D-921E-5DFD6EBE4435}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20C8B6F9-63FB-458D-921E-5DFD6EBE4435}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20C8B6F9-63FB-458D-921E-5DFD6EBE4435}.Release|Any CPU.ActiveCfg = Release|Any CPU
diff --git a/Cuipod/App.cs b/Cuipod/App.cs
index 8bf6395..80eb674 100644
--- a/Cuipod/App.cs
+++ b/Cuipod/App.cs
@@ -100,7 +100,22 @@ namespace Cuipod
private Response ProcessRequest(SslStream sslStream)
{
sslStream.ReadTimeout = 5000;
- sslStream.AuthenticateAsServer(_serverCertificate, false, SslProtocols.Tls12 | SslProtocols.Tls13, false);
+ sslStream.AuthenticateAsServer(new SslServerAuthenticationOptions()
+ {
+ ServerCertificate = _serverCertificate,
+ EnabledSslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13,
+ ClientCertificateRequired = false,
+ CertificateRevocationCheckMode = X509RevocationMode.NoCheck
+ });
+ //sslStream.AuthenticateAsServer(_serverCertificate, false, , false);
+ //var clientCertificate = sslStream.RemoteCertificate;
+ //var clientCertificateHash = Convert.ToBase64String(clientCertificate.GetCertHash());
+
+ //var username = clientCertificate.Issuer;
+ //if (sslStream.IsMutuallyAuthenticated)
+ //{
+
+ //}
// Read a message from the client.
string rawRequest = ReadRequest(sslStream);