Skip to content

Commit 1113e7b

Browse files
committed
Bug fix - correcting wrong handling of login when multiple database records are found.
1 parent 6adb0c2 commit 1113e7b

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

api/CESMII.ProfileDesigner.Api/Controllers/AuthController.cs

+26-17
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public IActionResult QueryCurrentOrganization()
105105
var listMatchEmailAddress = _dalUser.Where(x => x.EmailAddress.ToLower().Equals(userAAD.Email.ToLower()) && x.ObjectIdAAD == null, null).Data;
106106
if (listMatchEmailAddress.Count == 0)
107107
{
108-
// Here for (1) manually created users, or (2) users from marketplace self-service sign-up.
108+
// Here for (1) manually created users, or (2) users from profile designer or marketplace self-service sign-up.
109109
um = new UserModel()
110110
{
111111
ObjectIdAAD = userAAD.ObjectIdAAD,
@@ -144,32 +144,41 @@ public IActionResult QueryCurrentOrganization()
144144
{
145145
// When more than 1 record, it means they have signed up (and then left) more than
146146
// once. This is okay, but we pick the most recent one.
147-
// listMatchEmailAddress.Sort((em1, em2) => DateTime?.Compare(em1.LastLogin, em2.LastLogin));
147+
// listMatchEmailAddress.Sort((em1, em2) => DateTime?.Compare(em1.Created, em2.Created));
148148
listMatchEmailAddress.Sort((em1, em2) =>
149149
{
150150
DateTime dt1 = new DateTime(em1.Created.Value.Ticks);
151151
DateTime dt2 = new DateTime(em2.Created.Value.Ticks);
152152
return DateTime.Compare(dt1, dt2);
153153
});
154154

155+
// We must have at least 2 records or this line gives an exception
155156
int iItem = listMatchEmailAddress.Count - 1;
157+
158+
// We use the most recent records that we have for this user.
156159
um = listMatchEmailAddress[iItem];
157-
if (um.ObjectIdAAD == null)
158-
{
159-
um.ObjectIdAAD = userAAD.ObjectIdAAD;
160-
um.Email = userAAD.Email;
161-
um.DisplayName = userAAD.DisplayName;
162-
um.LastLogin = DateTime.UtcNow;
160+
um.ObjectIdAAD = userAAD.ObjectIdAAD;
161+
um.Email = userAAD.Email;
162+
um.DisplayName = userAAD.DisplayName;
163+
um.LastLogin = DateTime.UtcNow;
164+
165+
bUpdateUser = true; // Synch UserModel changes
166+
bCheckOrganization = true; // Check the user's organization.
167+
168+
// Note: If we want to automate the removal of duplicate records and logging of it,
169+
// we would do that here with code like the following:
170+
171+
////////for (int iDeleteMe = 0; iDeleteMe < listMatchEmailAddress.Count - 1; iDeleteMe++)
172+
////////{
173+
//////// if (listMatchEmailAddress[iDeleteMe].ID != null)
174+
//////// {
175+
//////// string strWarning = $"InitLocalUser|| About to delete record {iDeleteMe} of {listMatchEmailAddress.Count} from public.user. Id: {listMatchEmailAddress[iDeleteMe].ID.Value} Email: {listMatchEmailAddress[iDeleteMe].Email}";
176+
//////// _logger.LogWarning(strWarning);
177+
178+
//////// await _dalUser.DeleteAsync(listMatchEmailAddress[iDeleteMe].ID.Value, base.DalUserToken);
179+
//////// }
180+
////////}
163181

164-
bUpdateUser = true; // Synch UserModel changes
165-
bCheckOrganization = true; // Check the user's organization.
166-
}
167-
else
168-
{
169-
bErrorCondition = true;
170-
strError = $"InitLocalUser||More than one Profile designer user record found with email {userAAD.Email}. {listMatchEmailAddress.Count} records found. Existing object id = {um.ObjectIdAAD}";
171-
_logger.LogWarning(strError);
172-
}
173182
}
174183
}
175184

common

0 commit comments

Comments
 (0)