diff --git a/src/Database/Models/ContactChangeModel.cs b/src/Database/Models/ContactChangeModel.cs index 453638024e0e1a56c1d3e0b2c0a376b1d8e49aea..29a5cf0bafbf7deca0cb052aed4ae50f25cff4b3 100644 --- a/src/Database/Models/ContactChangeModel.cs +++ b/src/Database/Models/ContactChangeModel.cs @@ -24,15 +24,21 @@ namespace Coscine.Database.Models IEnumerable<ContactChange> emailData = GetAllWhere((contactChange) => contactChange.UserId == userId); // Return True if entries for a user exist inside the database table ContactChange. Else return False. if (emailData.Count() > 0) + { return true; + } else + { return false; + } } public ContactChangeObject NewEmailChangeRequest(Guid userId, string email) { if (UserHasEmailsToConfirm(userId)) + { DeleteAllDbEntries(userId); // <--- REMOVE THIS LINE IF YOU WANT TO KEEP HISTORY OF EMAIL CHANGES. + } ContactChangeObject contactChangeObject = AddDbEntry(userId, email); // Sending a confirmation email after an addition to the database is handled by the Controller. return contactChangeObject; @@ -43,7 +49,9 @@ namespace Coscine.Database.Models List<ContactChangeObject> contactChangeObjects = new List<ContactChangeObject>(); IEnumerable<ContactChange> emailData = GetAllWhere((contactChange) => contactChange.UserId == userId); foreach (var entry in emailData) + { contactChangeObjects.Add(ToObject(entry)); + } return contactChangeObjects; } @@ -72,20 +80,17 @@ namespace Coscine.Database.Models } else { - // EXPIRED throw new Exception("EXPIRED: Token " + token.ToString() + " has expired."); } } else { - // INVALID (null EditDate) throw new ArgumentNullException("INVALID: Value EditDate is NULL for Token " + token.ToString() + "."); } } else { - // INVALID (token-user combination not in Database) throw new MissingFieldException("INVALID: The Token " + token.ToString() + " is not valid. No entry inside the Database."); } } @@ -101,7 +106,9 @@ namespace Coscine.Database.Models // Token EXPIRED when expirationDateTime = -1 (Expiration is BEFORE Now) // Token VALID when expirationDateTime = 0 OR = 1 (Expiration IS Now or AFTER Now) if (compareDateTime < 0) + { Delete(entry); + } } } @@ -109,7 +116,9 @@ namespace Coscine.Database.Models { IEnumerable<ContactChange> emailData = GetAllWhere((contactChange) => contactChange.UserId == userId); foreach (var entry in emailData) + { Delete(entry); + } } private ContactChangeObject AddDbEntry(Guid userId, string email) diff --git a/src/Scaffolding/DataModel/Model.cs b/src/Scaffolding/DataModel/Model.cs index bdec87e1a54da96e0ea6d974f6a39dee45e1fd5e..bf9902d01fdf7d19b65983cddb390d5f23bc3f60 100644 --- a/src/Scaffolding/DataModel/Model.cs +++ b/src/Scaffolding/DataModel/Model.cs @@ -58,8 +58,6 @@ namespace Coscine.Database.DataModel { if (!optionsBuilder.IsConfigured) { -#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings. - optionsBuilder.UseSqlServer("Data Source=d-db-d02\\mssql14;Integrated Security=False;User ID=coscineDev;Password=Dev#123;Database=Coscine_hp-admin "); } }