From a6a2dbd4b3ceab0b10833dd40e6449b0a79be6ec Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 24 Mar 2026 14:30:01 +0100 Subject: [PATCH] =?UTF-8?q?Handling=20mit=20Support=20PIN=20verbessert=20-?= =?UTF-8?q?=207=20Tage=20statt=203=20Tage=20Zeit=20bis=20zur=20Aktivierung?= =?UTF-8?q?.=20Dann=2024h=20bis=20sie=20verf=C3=A4llt=20-=20Trim=20um=20Le?= =?UTF-8?q?erzeichen=20zu=20entfernen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ***** aus Support Mail mit PIN ersetzt --- .../ServiceImplementations/MailServiceImp.cs | 46 +++++++++++-------- .../ServiceImplementations/UserServiceImp.cs | 32 +++++++++---- 2 files changed, 51 insertions(+), 27 deletions(-) diff --git a/Service/ServiceImplementations/MailServiceImp.cs b/Service/ServiceImplementations/MailServiceImp.cs index 27381b513..03a9aae5b 100644 --- a/Service/ServiceImplementations/MailServiceImp.cs +++ b/Service/ServiceImplementations/MailServiceImp.cs @@ -94,31 +94,41 @@ namespace BeWo.Service.ServiceImplementations public bool SendEMailWithSender(string senderName, string senderEMail, string subject, string body) { - if (subject == "FEHLERMELDUNG" && body.Contains("Kontaktdaten:")) + if (subject == "FEHLERMELDUNG") { - int start = body.IndexOf("Kontaktdaten:") + "Kontaktdaten:".Length; - - int stop = body.IndexOf("\n", start); - - if (stop > start) + if (body.Contains("Kontaktdaten:")) { - String address = body.Substring(start, stop - start).Trim(); + int start = body.IndexOf("Kontaktdaten:") + "Kontaktdaten:".Length; - if (address.Contains("@")) + int stop = body.IndexOf("\n", start); + + if (stop > start) { - try - { - var addr = new System.Net.Mail.MailAddress(address); - senderEMail = addr.Address; - } - catch - { - //Ignore - } + String address = body.Substring(start, stop - start).Trim(); - + if (address.Contains("@")) + { + try + { + var addr = new System.Net.Mail.MailAddress(address); + senderEMail = addr.Address; + } + catch + { + //Ignore + } + } } + } + + if (body.Contains("PIN: *****")) + { + var pin = UserServiceImp.GeneratePIN(5); + if (!String.IsNullOrEmpty(pin)) + { + body = body.Replace("PIN: *****", "PIN: " + pin); + } } } diff --git a/Service/ServiceImplementations/UserServiceImp.cs b/Service/ServiceImplementations/UserServiceImp.cs index 95de4aaa3..92e50c72c 100644 --- a/Service/ServiceImplementations/UserServiceImp.cs +++ b/Service/ServiceImplementations/UserServiceImp.cs @@ -413,7 +413,7 @@ namespace BeWo.Service.ServiceImplementations { try { - if (checkTenant && !TenantExists()) + if (checkTenant && !TenantExists()) { return UserValidationResult.TenantUnknown; //return Membership.ValidateUser(pUserName, pPassword); @@ -429,11 +429,6 @@ namespace BeWo.Service.ServiceImplementations } String pin = pPIN; - if (!String.IsNullOrEmpty(pin)) - { - - } - ApplicationUser bsUser = DAOFactory.UserDAO.GetBSUser(pUserName, pPassword); if (bsUser != null && pUserName != "BSAdmin") @@ -465,7 +460,7 @@ namespace BeWo.Service.ServiceImplementations if (!String.IsNullOrEmpty(pPIN) && pPIN.IndexOf('_') >= 0) { - pin = pPIN.Substring(0, pPIN.IndexOf('_')); + pin = pPIN.Substring(0, pPIN.IndexOf('_')).Trim(); computerName = pPIN.Substring(pPIN.IndexOf('_') + 1); } var pins = DAOFactory.GenericDAO.GetAll(); @@ -479,7 +474,7 @@ namespace BeWo.Service.ServiceImplementations else { supportPIN = y[0]; - if (supportPIN.ExpirationDate < DateTime.Now) + if ((supportPIN.ExpirationDate < DateTime.Now) || (supportPIN.UsingDate.HasValue && supportPIN.UsingDate.Value.AddDays(1) < DateTime.Now)) { //if (supportPIN.IsUsed.HasValue && supportPIN.IsUsed.Value) // result = UserValidationResult.PinAlreadyUsed; @@ -844,7 +839,7 @@ namespace BeWo.Service.ServiceImplementations { try { - //pSupportPin.ExpirationDate = DateTime.Now.AddDays(3); + pSupportPin.ExpirationDate = DateTime.Now.AddDays(7); var lSupportPin = MapperFactory.SupportPinDC_SupportPin.MapToNewEntity(pSupportPin); DAOFactory.GenericDAO.Insert(lSupportPin); @@ -859,6 +854,25 @@ namespace BeWo.Service.ServiceImplementations } } + public static string GeneratePIN(int maxSize = 5) + { + var random = new Random(); + string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + + var pinStr = new string(Enumerable.Repeat(chars, maxSize).Select(s => s[random.Next(s.Length)]).ToArray()); + var pin = new SupportPin + { + Pin = pinStr, + IsUsed = false, + CreationDate = DateTime.Now + }; + pin.ExpirationDate = pin.CreationDate.Value.AddDays(7); + + DAOFactory.GenericDAO.Insert(pin); + + return pinStr; + } + public List GetAllSupportPins() { try