Skip to content

Commit

Permalink
Add user rest service.
Browse files Browse the repository at this point in the history
related to issue:#70
  • Loading branch information
jdirocco committed Oct 4, 2016
1 parent 241268d commit b41a34e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions mdeforge/src/main/java/org/mdeforge/business/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ public interface UserService {
User findOneByUsername(String username) throws BusinessException;

User findOneByEmail(String email) throws BusinessException;

List<User> findByUsernameContaining(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<User> findByUsernameContaining(String name) {
return userRepository.findByUsernameContaining(name);
}


@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.mdeforge.integration;

import java.util.List;

import org.mdeforge.business.model.User;
import org.springframework.data.mongodb.repository.MongoRepository;

public interface UserRepository extends MongoRepository<User,String>{
User findByUsernameAndEnabled(String username, boolean enabled);
User findByUsername(String username);
User findByEmail(String email);
List<User> findByUsernameContaining(String name);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<User> 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;
}
Expand Down

0 comments on commit b41a34e

Please sign in to comment.