mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
initial commit
This commit is contained in:
30
src/main/java/com/commafeed/backend/dao/UserService.java
Normal file
30
src/main/java/com/commafeed/backend/dao/UserService.java
Normal file
@@ -0,0 +1,30 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user