Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @POST
- @Path("/registracija")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.TEXT_PLAIN)
- public boolean registracija(Korisnik k) {
- // validacija korisnika na serveru
- if (validirajKorisnika(k) && !postojiKorisnik(k.getKorisnickoIme())) {
- Korisnici korisnici = getKorisnici();
- k.setAvatar("Database/SlikeKorisnika/" + k.getKorisnickoIme() + ".png");
- korisnici.dodajNovogKorisnika(k, ctx.getRealPath(""));
- return true;
- } else {
- return false;
- }
- }
- @SuppressWarnings("resource")
- @POST
- @Path("/uploadSlike")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.TEXT_PLAIN)
- public boolean uploadFile(UploadSlike upload) {
- String bytes = upload.getImage();
- String[] by = bytes.split(",");
- Korisnik ks = null;
- if (upload.getKorisnickoIme().equals("")) {
- if(request.getSession().getAttribute("ulogovanKorisnik") != null)
- ks = (Korisnik) request.getSession().getAttribute("ulogovanKorisnik");
- else
- return false;
- } else {
- for (Korisnik k : getKorisnici().getKorisnici()) {
- if (k.getKorisnickoIme().toUpperCase().equals(upload.getKorisnickoIme().toUpperCase())) {
- ks = k;
- break;
- }
- }
- if(ks == null)
- return false;
- }
- File img = new File(ctx.getRealPath("") + ks.getAvatar());
- FileOutputStream fos = null;
- try {
- fos = new FileOutputStream(img);
- } catch (FileNotFoundException e1) {
- return false;
- }
- try {
- fos.write(Base64.getDecoder().decode(by[1]));
- } catch (IOException e) {
- return false;
- }
- return true;
- }
Add Comment
Please, Sign In to add comment