Small changes cleanup for release

This commit is contained in:
Kim 2023-09-15 16:59:59 +02:00
parent a33c78ffe9
commit 40535cf0f1
4 changed files with 22 additions and 22 deletions

View File

@ -466,12 +466,12 @@ public class Controller : ControllerBase
if (user is null) if (user is null)
return Unauthorized(); return Unauthorized();
//todo dont hardcode url
return Db.DeleteUserPassword(user) return Db.DeleteUserPassword(user)
? RedirectToRoute("https://monitor.innov.energy") ? RedirectToRoute("https://monitor.innov.energy")
: Unauthorized(); : Unauthorized();
} }
} }

View File

@ -88,9 +88,9 @@ public static class SessionMethods
&& user.HasAccessToParentOf(installation) && user.HasAccessToParentOf(installation)
&& Db.Create(installation) // TODO: these two in a transaction && Db.Create(installation) // TODO: these two in a transaction
&& installation.SetOrderNumbers() && installation.SetOrderNumbers()
&& Db.Create(new InstallationAccess { UserId = user.Id, InstallationId = installation.Id }); && Db.Create(new InstallationAccess { UserId = user.Id, InstallationId = installation.Id })
//&& await installation.CreateBucket() && await installation.CreateBucket()
//&& await installation.RenewS3Credentials(); // generation of access _after_ generation of && await installation.RenewS3Credentials(); // generation of access _after_ generation of
// bucket to prevent "zombie" access-rights. // bucket to prevent "zombie" access-rights.
// This might fuck us over if the creation of access rights fails, // This might fuck us over if the creation of access rights fails,
// as bucket-names are unique and bound to the installation id... -K // as bucket-names are unique and bound to the installation id... -K
@ -144,8 +144,8 @@ public static class SessionMethods
&& installation is not null && installation is not null
&& user.HasWriteAccess && user.HasWriteAccess
&& user.HasAccessTo(installation) && user.HasAccessTo(installation)
&& Db.Delete(installation); && Db.Delete(installation)
//&& await installation.DeleteBucket(); && await installation.DeleteBucket();
} }
public static Boolean Create(this Session? session, User newUser) public static Boolean Create(this Session? session, User newUser)

View File

@ -1,7 +1,6 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using InnovEnergy.App.Backend.DataTypes; using InnovEnergy.App.Backend.DataTypes;
using InnovEnergy.Lib.Mailer; using InnovEnergy.Lib.Mailer;
using MimeKit;
using JsonSerializer = System.Text.Json.JsonSerializer; using JsonSerializer = System.Text.Json.JsonSerializer;
namespace InnovEnergy.App.Backend.Email; namespace InnovEnergy.App.Backend.Email;
@ -13,15 +12,15 @@ public static class Email
var config = JsonSerializer.Deserialize<SmtpConfig>(File.OpenRead("./Resources/smtpConfig.json"))!; var config = JsonSerializer.Deserialize<SmtpConfig>(File.OpenRead("./Resources/smtpConfig.json"))!;
var mailer = new Mailer(); var mailer = new Mailer();
Mailer.From("InnovEnergy", "noreply@innov.energy"); mailer.From("InnovEnergy", "noreply@innov.energy");
Mailer.To(emailRecipientUser.Name, emailRecipientUser.Email); mailer.To(emailRecipientUser.Name, emailRecipientUser.Email);
Mailer.Subject("Create a new password for your Innovenergy-Account"); mailer.Subject("Create a new password for your Innovenergy-Account");
Mailer.Body("Dear " + emailRecipientUser.Name + mailer.Body("Dear " + emailRecipientUser.Name +
"\n Please create a new password for your Innovenergy-account." + "\n Please create a new password for your Innovenergy-account." +
"\n To do this just login at https://HEEEEELP"); "\n To do this just login at https://HEEEEELP");
return Mailer.SendEmailUsingSmtpConfig(config); return mailer.SendEmailUsingSmtpConfig(config);
} }
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")] [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
@ -31,20 +30,21 @@ public static class Email
//todo am I right? //todo am I right?
const String resetLink = "https://monitor.innov.energy/api/ResetPassword"; const String resetLink = "https://monitor.innov.energy/api/ResetPassword";
var mailer = new Mailer();
try try
{ {
Mailer.From("InnovEnergy", "noreply@innov.energy"); mailer.From("InnovEnergy", "noreply@innov.energy");
Mailer.To(emailRecipientUser.Name, emailRecipientUser.Email); mailer.To(emailRecipientUser.Name, emailRecipientUser.Email);
Mailer.Subject("Reset the password of your Innovenergy-Account"); mailer.Subject("Reset the password of your Innovenergy-Account");
Mailer.Body("Dear " + emailRecipientUser.Name mailer.Body("Dear " + emailRecipientUser.Name
+ "\n To reset your password open this link:" + "\n To reset your password open this link:"
+ resetLink + "?token=" + resetLink + "?token="
+ token); + token);
return Mailer.SendEmailUsingSmtpConfig(config); return mailer.SendEmailUsingSmtpConfig(config);
} }
catch (Exception) catch (Exception)
{ {

View File

@ -8,25 +8,25 @@ public class Mailer
{ {
private static MimeMessage Email = new(); private static MimeMessage Email = new();
public static MimeMessage To(String name, String emailAddress) public MimeMessage To(String name, String emailAddress)
{ {
Email.To.Add(new MailboxAddress(name, emailAddress)); Email.To.Add(new MailboxAddress(name, emailAddress));
return Email; return Email;
} }
public static MimeMessage From(String name, String emailAddress) public MimeMessage From(String name, String emailAddress)
{ {
Email.From.Add(new MailboxAddress(name, emailAddress)); Email.From.Add(new MailboxAddress(name, emailAddress));
return Email; return Email;
} }
public static MimeMessage Subject(String subjectText) public MimeMessage Subject(String subjectText)
{ {
Email.Subject = subjectText; Email.Subject = subjectText;
return Email; return Email;
} }
public static MimeMessage Body(String bodyText) public MimeMessage Body(String bodyText)
{ {
Email.Body = new TextPart(MimeKit.Text.TextFormat.Plain) Email.Body = new TextPart(MimeKit.Text.TextFormat.Plain)
{ {
@ -35,7 +35,7 @@ public class Mailer
return Email; return Email;
} }
public static Boolean SendEmailUsingSmtpConfig(SmtpConfig config) public Boolean SendEmailUsingSmtpConfig(SmtpConfig config)
{ {
try{ try{
using var smtp = new SmtpClient(); using var smtp = new SmtpClient();