adding hidden basic asp.net core backend (#30)

Base functionality:

    DB
    email sending
    user registration & login
    storing new characters and reading them back

Notes:

    Functionality is "hidden" with no links pointing to it.
    Most pages are scaffolded and not reviewed at all :(
    local Dev db setup is pushed to git
    NO local email setup :(
This commit is contained in:
2023-12-19 19:03:57 +01:00
committed by GitHub
parent 19b002ff24
commit 7bb7ab6f13
154 changed files with 39394 additions and 1325 deletions
@@ -0,0 +1,29 @@
using System.Net.Http.Headers;
using Kemkas.Web.Config;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.Extensions.Options;
namespace Kemkas.Web.Services.Identity;
public class MailgunEmailSender(IOptions<MailgunOptions> sendGridOptions, HttpClient httpClient) : IEmailSender
{
public async Task SendEmailAsync(string email, string subject, string htmlMessage)
{
var domain = sendGridOptions.Value.DomainName;
var uri = new Uri($"https://api.eu.mailgun.net/v3/{domain}/messages");
var request = new HttpRequestMessage(HttpMethod.Post, uri);
var authHeaderValue = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"api:{sendGridOptions.Value.ApiKey}"));
request.Headers.Authorization = new AuthenticationHeaderValue("Basic", authHeaderValue);
request.Content = new FormUrlEncodedContent(
[
new KeyValuePair<string,string>("from", $"no-reply@{domain}"),
new KeyValuePair<string,string>("to", email),
new KeyValuePair<string,string>("subject", subject),
new KeyValuePair<string,string>("html", htmlMessage),
]);
var response = await httpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
}
}