Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.

Commit 5fc6ce1

Browse files
authored
Merge pull request #84 from appirio-tech/dev
add email check
2 parents 105511b + f403c65 commit 5fc6ce1

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/main/java/com/appirio/tech/core/service/identity/dao/UserDAO.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ public abstract class UserDAO implements DaoBase<User>, Transactional<UserDAO> {
137137
)
138138
public abstract List<User> findUsersByEmail(@Bind("email") String email);
139139

140+
@SqlQuery("SELECT COUNT(e2.email_id) " +
141+
"FROM common_oltp.user AS u LEFT JOIN common_oltp.email AS e ON e.user_id = u.user_id " +
142+
"LEFT JOIN common_oltp.email AS e2 ON LOWER(e2.address) = LOWER(e.address) " +
143+
"WHERE u.user_id = :userId")
144+
public abstract int getEmailCount(@Bind("userId") long userId);
145+
140146
@RegisterMapperFactory(TCBeanMapperFactory.class)
141147
@SqlQuery(
142148
"SELECT mfa.id AS id, u.user_id AS userId, u.handle AS handle, u.first_name AS firstName, e.address AS email, mfa.mfa_enabled AS mfaEnabled, mfa.dice_enabled AS diceEnabled" +

src/main/java/com/appirio/tech/core/service/identity/resource/UserResource.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,11 @@ public ApiResponse updateUser2fa(
16431643
&& user2faInDb.getDiceEnabled() != null && user2faInDb.getDiceEnabled() == true)) {
16441644
throw new APIRuntimeException(SC_BAD_REQUEST, "You cannot disable mfa");
16451645
}
1646+
if (user2fa.getMfaEnabled() && user2faInDb.getId() == null) {
1647+
if (userDao.getEmailCount(userId) > 1) {
1648+
throw new APIRuntimeException(SC_BAD_REQUEST, "You have multiple accounts registered with same email. Please contact with support.");
1649+
}
1650+
}
16461651
if (user2fa.getMfaEnabled() == null) {
16471652
user2fa.setMfaEnabled(user2faInDb.getMfaEnabled() == null ? false : user2faInDb.getMfaEnabled());
16481653
}

0 commit comments

Comments
 (0)