added registration on welcome page

This commit is contained in:
Athou
2013-04-06 21:38:18 +02:00
parent 9544b6194e
commit 3691dcd98f
16 changed files with 278 additions and 43 deletions

View File

@@ -19,7 +19,7 @@ public class UserService extends GenericDAO<User> {
@Inject
PasswordEncryptionService encryptionService;
private User findByName(String name) {
public User findByName(String name) {
TypedQuery<User> query = em.createNamedQuery("User.byName", User.class);
query.setParameter("name", name.toLowerCase());
@@ -46,12 +46,18 @@ public class UserService extends GenericDAO<User> {
}
public User register(String name, String password, Collection<Role> roles) {
return register(name, password, null, roles);
}
public User register(String name, String password, String email,
Collection<Role> roles) {
if (findByName(name) != null) {
return null;
}
User user = new User();
byte[] salt = encryptionService.generateSalt();
user.setName(name);
user.setEmail(email);
user.setSalt(salt);
user.setPassword(encryptionService.getEncryptedPassword(password, salt));
user.getRoles().add(new UserRole(user, Role.USER));