mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
31 lines
805 B
Java
31 lines
805 B
Java
|
|
package com.commafeed.backend.dao;
|
||
|
|
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
import javax.inject.Inject;
|
||
|
|
|
||
|
|
import com.commafeed.backend.security.PasswordEncryptionService;
|
||
|
|
import com.commafeed.frontend.utils.ModelFactory.MF;
|
||
|
|
import com.commafeed.model.User;
|
||
|
|
import com.google.common.collect.Iterables;
|
||
|
|
|
||
|
|
public class UserService extends GenericDAO<User, Long> {
|
||
|
|
|
||
|
|
@Inject
|
||
|
|
PasswordEncryptionService encryptionService;
|
||
|
|
|
||
|
|
public User login(String name, String password) {
|
||
|
|
List<User> users = findByField(MF.i(MF.p(User.class).getName()), name);
|
||
|
|
User user = Iterables.getFirst(users, null);
|
||
|
|
if (user != null) {
|
||
|
|
boolean authenticated = encryptionService.authenticate(password,
|
||
|
|
user.getPassword(), user.getSalt());
|
||
|
|
if (authenticated) {
|
||
|
|
return user;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|