Index: sources/app/src/main/java/parkup/services/AdministratorService.java
===================================================================
--- sources/app/src/main/java/parkup/services/AdministratorService.java	(revision ce6ad22249e902dea17e6ba473846ccebdd4330c)
+++ sources/app/src/main/java/parkup/services/AdministratorService.java	(revision 9504a097ce80831ea7e7130dff7215d5fbf8e939)
@@ -1,5 +1,4 @@
 package parkup.services;
 
-import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Objects;
@@ -14,5 +13,4 @@
 import org.springframework.stereotype.Service;
 import parkup.configs.email.EmailValidator;
-import parkup.configs.token.ConfirmationToken;
 import parkup.configs.token.ConfirmationTokenService;
 import parkup.entities.Administrator;
@@ -42,16 +40,22 @@
     }
 
-    public void addAdministrator(Administrator administrator) {
+    public Optional<Administrator> addAdministrator(Administrator administrator) {
         Optional<Administrator> administratorOpt = this.administratorRepository.findAdministratorByEmail(administrator.getEmail());
         if (administratorOpt.isPresent()) {
             throw new IllegalStateException("Email already taken, try adding an administrator with a different valid email address");
         } else {
-            System.out.println(administrator);
-            this.administratorRepository.save(administrator);
+            if (administrator.getEmail() != null && administrator.getEmail().length() > 1 && administrator.getEmail().contains("@")) {
+                //System.out.println(regPark);
+                this.administratorRepository.save(administrator);
+            }
+            else {
+                throw new IllegalStateException("email not valid");
+            }
         }
+        return administratorOpt;
     }
 
     @Transactional
-    public void updateAdministrator(int administratorId, String firstName, String lastName, String mobile, String email) {
+    public Administrator updateAdministrator(int administratorId, String firstName, String lastName, String mobile, String email) {
         Optional<Administrator> administratorOpt = Optional.ofNullable(this.administratorRepository.findByAdministratorId(administratorId));
         if (administratorOpt.isPresent()) {
@@ -62,6 +66,7 @@
                     throw new IllegalStateException("email taken");
                 }
-
                 administratorNov.setEmail(email);
+            }else{
+                throw new IllegalStateException("email not valid");
             }
 
@@ -77,8 +82,13 @@
                 administratorNov.setMobile(mobile);
             }
+            return administratorNov;
         }
+        else {
+            throw new IllegalStateException("Administrator doesn't exist, therefore can't be updated");
+        }
+
     }
 
-    public void deleteAdministrator(int administratorId) {
+    public Optional<Administrator> deleteAdministrator(int administratorId) {
         Optional<Administrator> administratorOpt = Optional.ofNullable(this.administratorRepository.findByAdministratorId(administratorId));
         if (administratorOpt.isPresent()) {
@@ -87,4 +97,5 @@
             throw new IllegalStateException("Administrator doesn't exist, therefore can't be deleted");
         }
+        return administratorOpt;
     }
 
@@ -126,12 +137,12 @@
 
         String token = UUID.randomUUID().toString();
-        ConfirmationToken confirmationToken = new ConfirmationToken(
-                token,
-                LocalDateTime.now(),
-                LocalDateTime.now().plusMinutes(15),
-                administrator
-        );
+        //ConfirmationTokenRP confirmationToken = new ConfirmationTokenRP(
+        //        token,
+        //        LocalDateTime.now(),
+        //        LocalDateTime.now().plusMinutes(15),
+        //        administrator
+        //);
 
-        confirmationTokenService.saveConfirmationToken(confirmationToken);
+        //confirmationTokenService.saveConfirmationToken(confirmationToken);
 
         // TODO: SEND EMAIL
Index: sources/app/src/main/java/parkup/services/ParkingSessionService.java
===================================================================
--- sources/app/src/main/java/parkup/services/ParkingSessionService.java	(revision ce6ad22249e902dea17e6ba473846ccebdd4330c)
+++ sources/app/src/main/java/parkup/services/ParkingSessionService.java	(revision 9504a097ce80831ea7e7130dff7215d5fbf8e939)
@@ -3,7 +3,9 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import parkup.data.Tablicka;
 import parkup.entities.ParkingSession;
 import parkup.repositories.ParkingSessionRepository;
 
+import javax.transaction.Transactional;
 import java.util.List;
 import java.util.Objects;
@@ -28,8 +30,10 @@
     }
 
-    public void updateParkingSession(int parkingSessionId, String timeStart, String timeEnd) {
+    @Transactional
+    public void updateParkingSession(int parkingSessionId, String timeStart, String timeEnd, Tablicka tablicka) {
         Optional<ParkingSession> parkingSessionOpt = Optional.ofNullable(parkingSessionRepository.findByPssId(parkingSessionId));
         if (parkingSessionOpt.isPresent()) {
             ParkingSession parkingSessionNov = parkingSessionRepository.findByPssId(parkingSessionId);
+
             if(!parkingSessionNov.getTimeStart().equals(timeStart) && !parkingSessionNov.getTimeStart().equals(timeEnd))
                 parkingSessionNov.setTimeStart(timeStart);
@@ -37,11 +41,18 @@
             if(!parkingSessionNov.getTimeEnd().equals(timeEnd) && !parkingSessionNov.getTimeEnd().equals(timeStart))
                 parkingSessionNov.setTimeEnd(timeEnd);
+
+            if(tablicka!=null && !Objects.equals(parkingSessionNov.getTablica(),tablicka)){
+                parkingSessionNov.setTablica(tablicka);
+            }
+        }else{
+            throw new IllegalStateException("The ParkingSession does not exist");
         }
     }
 
-    public void deleteParkingSession(int parkingSessionId) {
+    public Optional<ParkingSession> deleteParkingSession(int parkingSessionId) {
         Optional<ParkingSession> parkingSessionOpt = Optional.ofNullable(parkingSessionRepository.findByPssId(parkingSessionId));
         if (parkingSessionOpt.isPresent()) {
             parkingSessionRepository.deleteByPssId(parkingSessionId);
+            return parkingSessionOpt;
         } else {
             throw new IllegalStateException("ParkingSpace doesn't exist, therefore can't be deleted");
@@ -49,6 +60,6 @@
     }
 
-    public void addParkingSession(ParkingSession parkingSession) {
-        Optional <ParkingSession> parkingSessionOpt = Optional.ofNullable(parkingSessionRepository.findByPssId(parkingSession.getPssId()));
+    public Optional<ParkingSession> addParkingSession(ParkingSession parkingSession) {
+        Optional<ParkingSession> parkingSessionOpt = Optional.ofNullable(parkingSessionRepository.findByPssId(parkingSession.getPssId()));
         if (parkingSessionOpt.isPresent()) {
             throw new IllegalStateException("ID already taken, ParkingSession cannot be added");
@@ -56,4 +67,5 @@
             System.out.println(parkingSession);
             parkingSessionRepository.save(parkingSession);
+            return parkingSessionOpt;
         }
     }
Index: sources/app/src/main/java/parkup/services/ParkingSpaceService.java
===================================================================
--- sources/app/src/main/java/parkup/services/ParkingSpaceService.java	(revision ce6ad22249e902dea17e6ba473846ccebdd4330c)
+++ sources/app/src/main/java/parkup/services/ParkingSpaceService.java	(revision 9504a097ce80831ea7e7130dff7215d5fbf8e939)
@@ -6,4 +6,5 @@
 import parkup.repositories.ParkingSpaceRepository;
 
+import javax.transaction.Transactional;
 import java.util.List;
 import java.util.Objects;
@@ -28,6 +29,6 @@
     }
 
-    public void addParkingSpace(ParkingSpace parkingSpace) {
-        Optional <ParkingSpace> parkingSpaceOpt = Optional.ofNullable(parkingSpaceRepository.findByPsName(parkingSpace.getPsName()));
+    public Optional<ParkingSpace> addParkingSpace(ParkingSpace parkingSpace) {
+        Optional<ParkingSpace> parkingSpaceOpt = Optional.ofNullable(parkingSpaceRepository.findByPsName(parkingSpace.getPsName()));
         if (parkingSpaceOpt.isPresent()) {
             throw new IllegalStateException("Name already taken, try adding a ParkingZone with a different name");
@@ -36,7 +37,9 @@
             parkingSpaceRepository.save(parkingSpace);
         }
+        return parkingSpaceOpt;
     }
 
-    public void updateParkingSpace(int parkingSpaceId, String psName, boolean taken, boolean handicaped) {
+    @Transactional
+    public ParkingSpace updateParkingSpace(int parkingSpaceId, String psName, boolean taken, boolean handicaped, float lat, float lng) {
         Optional<ParkingSpace> ParkingSpaceOpt = Optional.ofNullable(parkingSpaceRepository.findByPsId(parkingSpaceId));
         if (ParkingSpaceOpt.isPresent()) {
@@ -58,8 +61,20 @@
                 ParkingSpaceNov.setHandicaped(handicaped);
             }
+
+            if(lat!=0 && !Objects.equals(ParkingSpaceNov.getLat(), lat)){
+                ParkingSpaceNov.setLat(lat);
+            }
+
+            if(lng!=0 && !Objects.equals(ParkingSpaceNov.getLng(), lng)){
+                ParkingSpaceNov.setLng(lng);
+            }
+            return ParkingSpaceNov;
+        }else{
+            throw new IllegalStateException("ParkingSpace does not exist");
         }
     }
 
-    public void deleteParkingSpace(int parkingSpaceId) {
+    @Transactional
+    public Optional<ParkingSpace> deleteParkingSpace(int parkingSpaceId) {
         Optional<ParkingSpace> parkingSpaceOpt = Optional.ofNullable(parkingSpaceRepository.findByPsId(parkingSpaceId));
         if (parkingSpaceOpt.isPresent()) {
@@ -68,4 +83,5 @@
             throw new IllegalStateException("ParkingSpace doesn't exist, therefore can't be deleted");
         }
+        return parkingSpaceOpt;
     }
 }
Index: sources/app/src/main/java/parkup/services/ParkingZoneService.java
===================================================================
--- sources/app/src/main/java/parkup/services/ParkingZoneService.java	(revision ce6ad22249e902dea17e6ba473846ccebdd4330c)
+++ sources/app/src/main/java/parkup/services/ParkingZoneService.java	(revision 9504a097ce80831ea7e7130dff7215d5fbf8e939)
@@ -2,10 +2,13 @@
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.stereotype.Service;
-import parkup.entities.Administrator;
+import parkup.data.ParkingZoneLocation;
+import parkup.entities.ParkingSpace;
 import parkup.entities.ParkingZone;
 import parkup.repositories.ParkingZoneRepository;
 
 import javax.transaction.Transactional;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
@@ -30,5 +33,14 @@
     }
 
-    public void addParkingZone(ParkingZone parkingZone) {   //zavisno vo koj grad ili opstina i napravi proverki pred dodavanje, implementiraj u naredna faza
+    public List<String> getAllParkingZoneNames() {
+        List<ParkingZone> parkingZones = this.parkingZoneRepository.findAll();
+        List<String> parkingZonesNames = new ArrayList<>();
+        for (ParkingZone pz : parkingZones){
+            parkingZonesNames.add(pz.getPzName());
+        }
+        return parkingZonesNames;
+    }
+
+    public Optional<ParkingZone> addParkingZone(ParkingZone parkingZone) {   //zavisno vo koj grad ili opstina i napravi proverki pred dodavanje, implementiraj u naredna faza
         Optional<ParkingZone> parkingZoneOpt = Optional.ofNullable(parkingZoneRepository.findByPzName(parkingZone.getPzName()));
         if (parkingZoneOpt.isPresent()) {
@@ -38,8 +50,23 @@
             parkingZoneRepository.save(parkingZone);
         }
+        return parkingZoneOpt;
     }
 
+    public ParkingZone addParkingZoneNameOnly(String name) {
+        Optional<ParkingZone> parkingZoneOpt = Optional.ofNullable(parkingZoneRepository.findByPzName(name));
+        if (parkingZoneOpt.isPresent()) {
+            throw new IllegalStateException("Name already taken, try adding a ParkingZone with a different name");
+        } else {
+            ParkingZone parkingZone = new ParkingZone(name.trim());
+            parkingZoneRepository.save(parkingZone);
+            return parkingZone;
+        }
+    }
+
+    //TODO prati niza od objekti ParkingSpaces i prati objekt ParkingZoneLocation
     @Transactional
-    public void updateParkingZone(int parkingZoneId, String pzName, int price, int capacity, String workHours, String location) {
+    public ParkingZone updateParkingZone(int parkingZoneId, String pzName, int price, int capacity,
+                                         String location, int from, int to, String color,
+                                         List<ParkingSpace> parkingSpaces, ParkingZoneLocation parkingZoneLocation) {
         Optional<ParkingZone> parkingZoneOpt = Optional.ofNullable(parkingZoneRepository.findByPzId(parkingZoneId));
         if (parkingZoneOpt.isPresent()) {
@@ -62,15 +89,37 @@
             }
 
-            if (workHours != null && workHours.length() > 0 && !Objects.equals(parkingZoneNov.getWorkHours(), workHours)) {
-                parkingZoneNov.setWorkHours(workHours);
-            }
-
             if (location != null && location.length() > 0 && !Objects.equals(parkingZoneNov.getLocation(), location)) {
                 parkingZoneNov.setLocation(location);
             }
+
+            if (from != 0 && !Objects.equals(parkingZoneNov.getFrom(), from)) {
+                parkingZoneNov.setFrom(from);
+            }
+
+            if (to != 0 && !Objects.equals(parkingZoneNov.getTo(), to)) {
+                parkingZoneNov.setTo(to);
+            }
+
+            if (color != null && color.length() > 0 && !Objects.equals(parkingZoneNov.getColor(), color)) {
+                parkingZoneNov.setColor(color);
+            }
+
+            if(parkingZoneLocation!=null){
+                parkingZoneNov.setParkingZoneLocation(parkingZoneLocation);
+            }
+
+            if(!parkingSpaces.isEmpty()){
+                //TODO kreiraj lista od parkingSpaces, ni gi prakja false isHandicaped i isTaken
+                parkingZoneNov.setParkingSpaces(parkingSpaces);
+            }
+
+            return parkingZoneNov;
+        } else {
+            throw new IllegalStateException("There ParkingZone does not exist");
         }
     }
 
-    public void deleteParkingZone(int parkingZoneId) {
+    @Transactional
+    public Optional<ParkingZone> deleteParkingZone(int parkingZoneId) {
         Optional<ParkingZone> parkingZoneOpt = Optional.ofNullable(parkingZoneRepository.findByPzId(parkingZoneId));
         if (parkingZoneOpt.isPresent()) {
@@ -79,4 +128,5 @@
             throw new IllegalStateException("ParkingZone doesn't exist, therefore can't be deleted");
         }
+        return parkingZoneOpt;
     }
 }
Index: sources/app/src/main/java/parkup/services/RegistriranParkiracService.java
===================================================================
--- sources/app/src/main/java/parkup/services/RegistriranParkiracService.java	(revision ce6ad22249e902dea17e6ba473846ccebdd4330c)
+++ sources/app/src/main/java/parkup/services/RegistriranParkiracService.java	(revision 9504a097ce80831ea7e7130dff7215d5fbf8e939)
@@ -1,20 +1,36 @@
 package parkup.services;
 
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
+import java.util.UUID;
 import javax.transaction.Transactional;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
+import parkup.configs.email.EmailValidator;
+import parkup.configs.token.ConfirmationTokenRP;
+import parkup.configs.token.ConfirmationTokenService;
+import parkup.data.Tablicka;
 import parkup.entities.RegistriranParkirac;
 import parkup.repositories.RegistriranParkiracRepository;
 
 @Service
-public class RegistriranParkiracService {
+public class RegistriranParkiracService implements UserDetailsService {
     private final RegistriranParkiracRepository registriranParkiracRepository;
+    private final BCryptPasswordEncoder bCryptPasswordEncoder;
+    private final ConfirmationTokenService confirmationTokenService;
+    private EmailValidator emailValidator;
 
     @Autowired
-    public RegistriranParkiracService(RegistriranParkiracRepository registriranParkiracRepository) {
+    public RegistriranParkiracService(RegistriranParkiracRepository registriranParkiracRepository, BCryptPasswordEncoder bCryptPasswordEncoder, ConfirmationTokenService confirmationTokenService) {
         this.registriranParkiracRepository = registriranParkiracRepository;
+        this.bCryptPasswordEncoder = bCryptPasswordEncoder;
+        this.confirmationTokenService = confirmationTokenService;
     }
 
@@ -23,16 +39,22 @@
     }
 
-    public void addRegPark(RegistriranParkirac regPark) {
+    public Optional<RegistriranParkirac> addRegPark(RegistriranParkirac regPark) {
         Optional<RegistriranParkirac> regParkOpt = this.registriranParkiracRepository.findRegistriranParkiracByEmail(regPark.getEmail());
         if (regParkOpt.isPresent()) {
             throw new IllegalStateException("Email already taken, try adding a registriranParkirac with a different valid email address");
         } else {
-            System.out.println(regPark);
-            this.registriranParkiracRepository.save(regPark);
+            if (regPark.getEmail() != null && regPark.getEmail().length() > 1 && regPark.getEmail().contains("@")) {
+                //System.out.println(regPark);
+                this.registriranParkiracRepository.save(regPark);
+            }
+            else {
+                throw new IllegalStateException("email not valid");
+            }
         }
+        return regParkOpt;
     }
 
     @Transactional
-    public void updateRegPark(int regParkId, String name, String surname, String mobile, String email) {
+    public RegistriranParkirac updateRegPark(int regParkId, String name, String surname, String mobile, String email,List<Tablicka> regTablicki) {
         Optional<RegistriranParkirac> regParkOpt = Optional.ofNullable(this.registriranParkiracRepository.findByRegParkId(regParkId));
         if (regParkOpt.isPresent()) {
@@ -58,14 +80,24 @@
                 regParkNov.setMobile(mobile);
             }
+            regParkNov.setRegTablicki(regTablicki);
+            return regParkNov;
+        }else{
+            throw new IllegalStateException("RegistriranParkirac doesn't exist, therefore can't be updated");
         }
     }
 
-    public void deleteRegPark(int regParkId) {
+    @Transactional
+    @Modifying
+    public Optional<RegistriranParkirac> deleteRegPark(int regParkId) {
         Optional<RegistriranParkirac> regPark = Optional.ofNullable(this.registriranParkiracRepository.findByRegParkId(regParkId));
         if (regPark.isPresent()) {
+            //TODO da povikamo metod od ConfirmationTokenService za brisenje na ConfirmationTokenRP *DONE
+            //TODO da se izbrisat tablicki i da ne se dupliraat istite tablicki pri update ili add na nov registriranParkirac
+            this.confirmationTokenService.deleteByRegistriranParkirac_RegParkId(regParkId);
             this.registriranParkiracRepository.deleteByRegParkId(regParkId);
         } else {
             throw new IllegalStateException("RegistriranParkirac doesn't exist, therefore can't be deleted");
         }
+        return regPark;
     }
 
@@ -74,3 +106,50 @@
         return regPark.orElse(null);
     }
+
+    @Override
+    public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
+        return registriranParkiracRepository.findRegistriranParkiracByEmail(email)
+                .orElseThrow(() ->
+                        new UsernameNotFoundException("Email not found"));
+
+    }
+
+    public String signUpRegistriranParkirac(RegistriranParkirac registriranParkirac){
+        boolean registriranParkiracExists = registriranParkiracRepository
+                .findRegistriranParkiracByEmail(registriranParkirac.getEmail())
+                .isPresent();
+        if(registriranParkiracExists){
+            // TODO check if attributes are the same and
+            // TODO if email not confirmed send confirmation email
+
+            throw new IllegalStateException("Email already taken");
+        }
+
+        String encodedPassword = bCryptPasswordEncoder
+                .encode(registriranParkirac.getPassword());
+
+        registriranParkirac.setPassword(encodedPassword);
+
+        registriranParkiracRepository.save(registriranParkirac);
+
+        // TODO: Send confirmation token
+
+        String token = UUID.randomUUID().toString();
+        ConfirmationTokenRP confirmationTokenRP = new ConfirmationTokenRP(
+                token,
+                LocalDateTime.now(),
+                LocalDateTime.now().plusMinutes(15),
+                registriranParkirac
+        );
+
+        confirmationTokenService.saveConfirmationTokenRP(confirmationTokenRP);
+
+        // TODO: SEND EMAIL
+
+        return token;
+    }
+
+    public int enableRegistriranParkirac(String email) {
+        return registriranParkiracRepository.enableRegistriranParkirac(email);
+    }
 }
Index: sources/app/src/main/java/parkup/services/VrabotenService.java
===================================================================
--- sources/app/src/main/java/parkup/services/VrabotenService.java	(revision ce6ad22249e902dea17e6ba473846ccebdd4330c)
+++ sources/app/src/main/java/parkup/services/VrabotenService.java	(revision 9504a097ce80831ea7e7130dff7215d5fbf8e939)
@@ -1,21 +1,31 @@
 package parkup.services;
 
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.UUID;
+import java.time.LocalDateTime;
+import java.util.*;
 import javax.transaction.Transactional;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
+import parkup.configs.token.ConfirmationTokenW;
+import parkup.configs.token.ConfirmationTokenService;
 import parkup.entities.Vraboten;
 import parkup.repositories.VrabotenRepository;
+import parkup.data.VrabotenDemo;
 
 @Service
-public class VrabotenService {
+public class VrabotenService implements UserDetailsService {
     private final VrabotenRepository vrabotenRepository;
+    private final BCryptPasswordEncoder bCryptPasswordEncoder;
+    private final ConfirmationTokenService confirmationTokenService;
 
     @Autowired
-    public VrabotenService(VrabotenRepository vrabotenRepository) {
+    public VrabotenService(VrabotenRepository vrabotenRepository, BCryptPasswordEncoder bCryptPasswordEncoder, ConfirmationTokenService confirmationTokenService) {
         this.vrabotenRepository = vrabotenRepository;
+        this.bCryptPasswordEncoder = bCryptPasswordEncoder;
+        this.confirmationTokenService = confirmationTokenService;
     }
 
@@ -29,16 +39,32 @@
     }
 
-    public void addVraboten(Vraboten vraboten) {
+    public List<VrabotenDemo> getAllVraboteniDemos() {
+        List<Vraboten> vraboteni = this.vrabotenRepository.findAll();
+        List<VrabotenDemo> vrabotenDemos = new ArrayList<>();
+        for (Vraboten v : vraboteni){
+            VrabotenDemo vd = new VrabotenDemo(v.getFirstName(), v.getLastName(), v.getEmail());
+            vrabotenDemos.add(vd);
+        }
+        return vrabotenDemos;
+    }
+
+    public Optional<Vraboten> addVraboten(Vraboten vraboten) {
         Optional<Vraboten> vrabotenOpt = this.vrabotenRepository.findVrabotenByEmail(vraboten.getEmail());
         if (vrabotenOpt.isPresent()) {
             throw new IllegalStateException("Email already taken, try adding a vraboten with a different valid email address");
         } else {
-            System.out.println(vraboten);
-            this.vrabotenRepository.save(vraboten);
+            if (vraboten.getEmail() != null && vraboten.getEmail().length() > 1 && vraboten.getEmail().contains("@")) {
+                //System.out.println(vraboten);
+                this.vrabotenRepository.save(vraboten);
+            }
+            else{
+                throw new IllegalStateException("email not valid");
+            }
         }
+        return vrabotenOpt;
     }
 
     @Transactional
-    public void updateVraboten(int vrabotenId, String firstName, String lastName, String mobile, String email) {
+    public Vraboten updateVraboten(int vrabotenId, String firstName, String lastName, String mobile, String email, String status) {
         Optional<Vraboten> vrabotenOpt = Optional.ofNullable(this.vrabotenRepository.findByVrabotenId(vrabotenId));
         if (vrabotenOpt.isPresent()) {
@@ -49,6 +75,7 @@
                     throw new IllegalStateException("email taken");
                 }
-
                 vrabotenNov.setEmail(email);
+            } else {
+                throw new IllegalStateException("email not valid");
             }
 
@@ -64,14 +91,88 @@
                 vrabotenNov.setMobile(mobile);
             }
+
+            if (mobile != null && status.length() > 0 && !Objects.equals(vrabotenNov.getStatus(), status)) {
+                if(status.equals("raboti") || status.equals("ne raboti") || status.equals("na odmor") || status.equals("na boleduvanje")){
+                    vrabotenNov.setStatus(status);
+                }else{
+                    throw new IllegalStateException("Please enter one of the following statuses: 'raboti', 'ne raboti', 'na odmor', 'na boleduvanje'");
+                }
+            }
+
+            return vrabotenNov;
         }
-    }
+        else{
+            throw new IllegalStateException("Vraboten doesn't exist, therefore can't be updated");
+        }
+    }//za menjanje password da se implementira
 
-    public void deleteVraboten(int vrabotenId) {
+    @Modifying
+    @Transactional
+    public Optional<Vraboten> deleteVraboten(int vrabotenId) {
         Optional<Vraboten> vrabotenOpt = Optional.ofNullable(this.vrabotenRepository.findByVrabotenId(vrabotenId));
         if (vrabotenOpt.isPresent()) {
+            //TODO da povikamo metod od ConfirmationTokenService za brisenje na ConfirmationTokenW
+            this.confirmationTokenService.deleteByVraboten_VrabotenId(vrabotenId);
             this.vrabotenRepository.deleteByVrabotenId(vrabotenId);
         } else {
             throw new IllegalStateException("Vraboten doesn't exist, therefore can't be deleted");
         }
+        return vrabotenOpt;
     }
+
+    @Transactional
+    public void lockVrabotenAcc(int vrabotenId) {
+        Vraboten vrabotenOpt = this.vrabotenRepository.findByVrabotenId(vrabotenId);
+        if (vrabotenOpt!=null) {
+            vrabotenOpt.lockVraboten();
+        } else {
+            throw new IllegalStateException("Vraboten doesn't exist, therefore his account can't be locked/unlocked");
+        }
+    }//dali treba da stoi @Transactional gore nad funkcijata?
+
+    @Override
+    public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
+        return vrabotenRepository.findVrabotenByEmail(email)
+                .orElseThrow(() ->
+                        new UsernameNotFoundException("Email not found"));
+    }
+    public String signUpVraboten(Vraboten vraboten){
+        boolean vrabotenExists = vrabotenRepository
+                .findVrabotenByEmail(vraboten.getEmail())
+                .isPresent();
+        if(vrabotenExists){
+            // TODO check if attributes are the same and
+            // TODO if email not confirmed send confirmation email
+
+            throw new IllegalStateException("Email already taken");
+        }
+
+        String encodedPassword = bCryptPasswordEncoder
+                .encode(vraboten.getPassword());
+
+        vraboten.setPassword(encodedPassword);
+
+        vrabotenRepository.save(vraboten);
+
+        // TODO: Send confirmation token
+
+        String token = UUID.randomUUID().toString();
+        ConfirmationTokenW confirmationTokenW = new ConfirmationTokenW(
+                token,
+                LocalDateTime.now(),
+                LocalDateTime.now().plusMinutes(15),
+                vraboten
+        );
+
+        confirmationTokenService.saveConfirmationTokenW(confirmationTokenW);
+
+        // TODO: SEND EMAIL
+
+        return token;
+    }
+
+    public int enableVraboten(String email) {
+        return vrabotenRepository.enableVraboten(email);
+    }
+
 }
