update api

This commit is contained in:
GME 2019-04-11 21:44:53 +02:00
parent 79159487a6
commit a08ff2d5e3
3 changed files with 12 additions and 25 deletions

View file

@ -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);

View file

@ -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{

View file

@ -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);
Boolean response = userImplementation.getUser(user_email);
if(response){
return ResponseEntity.status(HttpStatus.FOUND).body("{\"response\":"+response.toString()+"}");
}else {
return new ResponseEntity("{\"response\":\"error\"}", HttpStatus.NOT_FOUND);
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());
}
}