@POST @Consumes("application/json") public Response registerUser(InputStream data) throws IOException { User userObj = null; Gson gson = new Gson(); BufferedReader br = new BufferedReader(new InputStreamReader(data)); String bla = br.readLine(); System.out.println(bla); userObj = gson.fromJson(bla, User.class); // System.out.println("username: "******"email =" + userObj.getEmail()); System.out.println("pw =" + userObj.getPw()); try { new AccessManager().insertUser(userObj); } catch (Exception ex) { ex.printStackTrace(); } if (userObj.getUsername() != null) { String result = "User erfolgeich angelegt"; return Response.status(200).entity(result).build(); } else return Response.status(401).entity("Register Failed").build(); }
@POST @Path("/login") @Consumes("application/json") public Response login1(InputStream data) { String result; Gson gson = new Gson(); User userObj = null; BufferedReader br = new BufferedReader(new InputStreamReader(data)); System.out.println("login"); UserLogin tempUser = gson.fromJson(br, UserLogin.class); System.out.println(tempUser.emailOrUsername); try { userObj = new AccessManager().getUserLogin(tempUser.emailOrUsername); } catch (Exception e) { e.printStackTrace(); } if (userObj != null && tempUser.pw.equals(userObj.getPw())) { String user; userObj.setPw("null"); gson = new Gson(); user = gson.toJson(userObj); return Response.status(200).entity(user).type("application/json").build(); } else { return Response.status(401).entity("Check failed").build(); } }