Skip to content

Commit 17a12cd

Browse files
committed
Making the code try to lookup by email, as they are the same and update the username accordingly
1 parent 6d1373d commit 17a12cd

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

eFormAPI/eFormAPI.Web/Services/UserService.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,24 @@ public async Task<EformUser> GetByIdAsync(int id)
5353

5454
public async Task<EformUser> GetByUsernameAsync(string username)
5555
{
56-
return await dbContext.Users.FirstOrDefaultAsync(x => x.UserName == username);
56+
var user = await dbContext.Users.FirstOrDefaultAsync(x => x.UserName == username);
57+
if (user == null)
58+
{
59+
user = await dbContext.Users.FirstOrDefaultAsync(x => x.Email == username);
60+
if (user != null)
61+
{
62+
user.UserName = username;
63+
await userManager.UpdateAsync(user);
64+
return user;
65+
}
66+
67+
throw new Exception("User not found!");
68+
}
69+
70+
return user;
5771
}
5872

73+
5974
public int UserId
6075
{
6176
get

0 commit comments

Comments
 (0)