Merge branch 'features1.4/user' into develop-1.4
This commit is contained in:
commit
253ce1996a
|
@ -69,7 +69,7 @@ public class UserDao {
|
|||
deleteBuilder.delete();
|
||||
}
|
||||
|
||||
private boolean verifyUserExist(String email) throws Exception {
|
||||
public boolean verifyUserExist(String email) throws Exception {
|
||||
userDao = createUserDaoConnection();
|
||||
QueryBuilder<User, String> queryBuilder = userDao.queryBuilder();
|
||||
queryBuilder.where().eq("email",email);
|
||||
|
|
|
@ -62,19 +62,9 @@ public class UserImplementation {
|
|||
userDao.deleteUser(user.getEmail());
|
||||
}
|
||||
|
||||
public User getUser(String email, String password) throws Exception{
|
||||
public Boolean getUser(String email) throws Exception{
|
||||
UserDao userDao = new UserDao();
|
||||
User user1 = userDao.getUserWithEmail(email);
|
||||
if(user1 != null){
|
||||
String hash = user1.getPassword();
|
||||
if(BCrypt.checkpw(password, hash)){
|
||||
return user1;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
return userDao.verifyUserExist(email);
|
||||
}
|
||||
|
||||
public int getUserId(String user_hash, String user_email) throws Exception{
|
||||
|
|
|
@ -64,7 +64,7 @@ public class UserResource {
|
|||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(responseS);
|
||||
}
|
||||
case "Not Allowed" :{
|
||||
StringResponse responseS = new StringResponse("Forbidden");
|
||||
StringResponse responseS = new StringResponse("Wrong authentication");
|
||||
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(responseS);
|
||||
}
|
||||
case "" :{
|
||||
|
@ -86,22 +86,19 @@ public class UserResource {
|
|||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/get", method = RequestMethod.POST, produces = "application/json")
|
||||
@RequestMapping(value = "/get", method = RequestMethod.GET, params = {"user_email"}, produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity<User> getUser(@Valid @RequestBody User user){
|
||||
public ResponseEntity getUser(@RequestParam(value = "user_email") String user_email){
|
||||
try{
|
||||
UserImplementation userImplementation = new UserImplementation();
|
||||
User response = userImplementation.getUser(user.getEmail(), user.getPassword());
|
||||
if(response != null){
|
||||
User userResponse = new User();
|
||||
userResponse.setUser_hash(response.getUser_hash());
|
||||
userResponse.setUserId(response.getUserId());
|
||||
return ResponseEntity.status(HttpStatus.OK).body(userResponse);
|
||||
}else{
|
||||
return new ResponseEntity("{\"response\":\"error\"}", HttpStatus.NOT_FOUND);
|
||||
Boolean response = userImplementation.getUser(user_email);
|
||||
if(response){
|
||||
return ResponseEntity.status(HttpStatus.FOUND).body("{\"response\":"+response.toString()+"}");
|
||||
}else {
|
||||
return ResponseEntity.status(HttpStatus.OK).body("{\"response\":"+response.toString()+"}");
|
||||
}
|
||||
}catch (Exception e){
|
||||
return new ResponseEntity(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue