login by name or email

This commit is contained in:
Athou
2014-08-12 19:55:57 +02:00
parent 3c935a0b67
commit 34d7cb949d
2 changed files with 7 additions and 4 deletions

View File

@@ -31,12 +31,15 @@ public class UserService {
private final PasswordEncryptionService encryptionService;
private final CommaFeedConfiguration config;
public Optional<User> login(String name, String password) {
if (name == null || password == null) {
public Optional<User> login(String nameOrEmail, String password) {
if (nameOrEmail == null || password == null) {
return Optional.absent();
}
User user = userDAO.findByName(name);
User user = userDAO.findByName(nameOrEmail);
if (user == null) {
user = userDAO.findByEmail(nameOrEmail);
}
if (user != null && !user.isDisabled()) {
boolean authenticated = encryptionService.authenticate(password, user.getPassword(), user.getSalt());
if (authenticated) {