diff --git a/mdeforge/src/main/java/org/mdeforge/business/UserService.java b/mdeforge/src/main/java/org/mdeforge/business/UserService.java index a7aacd68..9449920c 100644 --- a/mdeforge/src/main/java/org/mdeforge/business/UserService.java +++ b/mdeforge/src/main/java/org/mdeforge/business/UserService.java @@ -32,4 +32,6 @@ public interface UserService { User findOneByUsername(String username) throws BusinessException; User findOneByEmail(String email) throws BusinessException; + + List findByUsernameContaining(String name); } \ No newline at end of file diff --git a/mdeforge/src/main/java/org/mdeforge/business/impl/UserServiceImpl.java b/mdeforge/src/main/java/org/mdeforge/business/impl/UserServiceImpl.java index 639c22b6..5643ba15 100644 --- a/mdeforge/src/main/java/org/mdeforge/business/impl/UserServiceImpl.java +++ b/mdeforge/src/main/java/org/mdeforge/business/impl/UserServiceImpl.java @@ -11,12 +11,19 @@ import org.mdeforge.integration.UserRepository; import org.mdeforge.integration.VerificationTokenRepository; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.mongodb.core.MongoOperations; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.SimpleMongoDbFactory; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; @Service public class UserServiceImpl implements UserService{ + @Autowired + protected SimpleMongoDbFactory mongoDbFactory; @Autowired private UserRepository userRepository; @Autowired @@ -36,7 +43,10 @@ public User create(User user) throws BusinessException { user.setPassword(new BCryptPasswordEncoder().encode(user.getPassword())); return userRepository.save(user); } - + @Override + public List findByUsernameContaining(String name) { + return userRepository.findByUsernameContaining(name); + } @Override diff --git a/mdeforge/src/main/java/org/mdeforge/integration/UserRepository.java b/mdeforge/src/main/java/org/mdeforge/integration/UserRepository.java index d54e3bd8..a4bb78ed 100644 --- a/mdeforge/src/main/java/org/mdeforge/integration/UserRepository.java +++ b/mdeforge/src/main/java/org/mdeforge/integration/UserRepository.java @@ -1,5 +1,7 @@ package org.mdeforge.integration; +import java.util.List; + import org.mdeforge.business.model.User; import org.springframework.data.mongodb.repository.MongoRepository; @@ -7,5 +9,6 @@ public interface UserRepository extends MongoRepository{ User findByUsernameAndEnabled(String username, boolean enabled); User findByUsername(String username); User findByEmail(String email); + List findByUsernameContaining(String name); } diff --git a/mdeforge/src/main/java/org/mdeforge/presentation/frontend/PublicController.java b/mdeforge/src/main/java/org/mdeforge/presentation/frontend/PublicController.java index a69e37de..67fb1cf8 100644 --- a/mdeforge/src/main/java/org/mdeforge/presentation/frontend/PublicController.java +++ b/mdeforge/src/main/java/org/mdeforge/presentation/frontend/PublicController.java @@ -12,6 +12,7 @@ import org.mdeforge.business.model.ATLTransformation; import org.mdeforge.business.model.Artifact; import org.mdeforge.business.model.EcoreMetamodel; +import org.mdeforge.business.model.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -62,11 +63,16 @@ public String publications() { public String login() { return "public.login"; } - @RequestMapping(value = "/exist_user", method = { RequestMethod.GET }) + @RequestMapping(value = "/user/search", method = { RequestMethod.GET }) + public @ResponseBody List searchUsers(@RequestParam("username") String username){ + return (userService.findByUsernameContaining(username)); + } + + @RequestMapping(value = "/user/exist_username", method = { RequestMethod.GET }) public @ResponseBody boolean existUser(@RequestParam("username") String username){ return (userService.findOneByUsername(username)==null)?false:true; } - @RequestMapping(value = "/exist_mail", method = { RequestMethod.GET }) + @RequestMapping(value = "/user/exist_email", method = { RequestMethod.GET }) public @ResponseBody boolean existEmail(@RequestParam("email") String email){ return (userService.findOneByEmail(email)==null)?false:true; }