update api
This commit is contained in:
parent
79159487a6
commit
a08ff2d5e3
|
@ -69,7 +69,7 @@ public class UserDao {
|
||||||
deleteBuilder.delete();
|
deleteBuilder.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean verifyUserExist(String email) throws Exception {
|
public boolean verifyUserExist(String email) throws Exception {
|
||||||
userDao = createUserDaoConnection();
|
userDao = createUserDaoConnection();
|
||||||
QueryBuilder<User, String> queryBuilder = userDao.queryBuilder();
|
QueryBuilder<User, String> queryBuilder = userDao.queryBuilder();
|
||||||
queryBuilder.where().eq("email",email);
|
queryBuilder.where().eq("email",email);
|
||||||
|
|
|
@ -62,19 +62,9 @@ public class UserImplementation {
|
||||||
userDao.deleteUser(user.getEmail());
|
userDao.deleteUser(user.getEmail());
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUser(String email, String password) throws Exception{
|
public Boolean getUser(String email) throws Exception{
|
||||||
UserDao userDao = new UserDao();
|
UserDao userDao = new UserDao();
|
||||||
User user1 = userDao.getUserWithEmail(email);
|
return userDao.verifyUserExist(email);
|
||||||
if(user1 != null){
|
|
||||||
String hash = user1.getPassword();
|
|
||||||
if(BCrypt.checkpw(password, hash)){
|
|
||||||
return user1;
|
|
||||||
}else{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUserId(String user_hash, String user_email) throws Exception{
|
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);
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(responseS);
|
||||||
}
|
}
|
||||||
case "Not Allowed" :{
|
case "Not Allowed" :{
|
||||||
StringResponse responseS = new StringResponse("Forbidden");
|
StringResponse responseS = new StringResponse("Wrong authentication");
|
||||||
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(responseS);
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(responseS);
|
||||||
}
|
}
|
||||||
case "" :{
|
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)
|
@ResponseStatus(HttpStatus.OK)
|
||||||
public ResponseEntity<User> getUser(@Valid @RequestBody User user){
|
public ResponseEntity getUser(@RequestParam(value = "user_email") String user_email){
|
||||||
try{
|
try{
|
||||||
UserImplementation userImplementation = new UserImplementation();
|
UserImplementation userImplementation = new UserImplementation();
|
||||||
User response = userImplementation.getUser(user.getEmail(), user.getPassword());
|
Boolean response = userImplementation.getUser(user_email);
|
||||||
if(response != null){
|
if(response){
|
||||||
User userResponse = new User();
|
return ResponseEntity.status(HttpStatus.FOUND).body("{\"response\":"+response.toString()+"}");
|
||||||
userResponse.setUser_hash(response.getUser_hash());
|
|
||||||
userResponse.setUserId(response.getUserId());
|
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(userResponse);
|
|
||||||
}else {
|
}else {
|
||||||
return new ResponseEntity("{\"response\":\"error\"}", HttpStatus.NOT_FOUND);
|
return ResponseEntity.status(HttpStatus.OK).body("{\"response\":"+response.toString()+"}");
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
}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