Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
Fixing unique user name login bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines committed Jun 26, 2018
1 parent 2e79cb5 commit a728a5f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions service/src/main/java/com/simplevote/db/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.simplevote.types.User;

import org.javalite.activejdbc.LazyList;
import org.javalite.activejdbc.Model;

import ch.qos.logback.classic.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -60,11 +62,21 @@ public static User signup(Long loggedInUserId, String userName, String password,
}

// Find the user, then create a login for them

LazyList<Tables.User> users;
if (email != null) {
users = Tables.User.find("name = ? or email = ?", userName, email);
} else {
users = Tables.User.find("name = ?", userName);
}

Tables.User uv;
if (email != null) {
uv = Tables.User.findFirst("name = ? or email = ?", userName, email);
if (users.size() > 1) {
throw new NoSuchElementException("Username/email already exists");
} else if (users.size() == 1) {
uv = users.get(0);
} else {
uv = Tables.User.findFirst("name = ?", userName);
uv = null;
}

if (uv == null) {
Expand Down

0 comments on commit a728a5f

Please sign in to comment.