From f84cd6167bb3c76a690bc8ea32c19a9e48c154d5 Mon Sep 17 00:00:00 2001 From: Jeas0001 Date: Mon, 5 May 2025 13:04:50 +0200 Subject: [PATCH] Only checks if the username or email is changed --- backend/API/BusinessLogic/UserLogic.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/backend/API/BusinessLogic/UserLogic.cs b/backend/API/BusinessLogic/UserLogic.cs index c0c2f92..2a93d55 100644 --- a/backend/API/BusinessLogic/UserLogic.cs +++ b/backend/API/BusinessLogic/UserLogic.cs @@ -94,6 +94,8 @@ namespace API.BusinessLogic public async Task EditProfile(UpdateUserDTO userDTO, int userId) { var profile = await _dbAccess.ReadUser(userId); + bool emailChanged = false; + bool userNameChanged = false; if (profile == null) { return new ConflictObjectResult(new { message = "User does not exist" }); } @@ -112,13 +114,22 @@ namespace API.BusinessLogic return new ConflictObjectResult(new { message = "Please enter an userName" }); } + if (userDTO.UserName != profile.UserName) + { + userNameChanged = true; + } - if (await _dbAccess.UserNameInUse(userDTO.UserName)) + if (userDTO.Email != profile.Email) + { + emailChanged = true; + } + + if (await _dbAccess.UserNameInUse(userDTO.UserName) && userNameChanged) { return new ConflictObjectResult(new { message = "Username is already in use." }); } - if (await _dbAccess.EmailInUse(userDTO.Email)) + if (await _dbAccess.EmailInUse(userDTO.Email) && emailChanged) { return new ConflictObjectResult(new { message = "Email is already in use." }); }