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 97fbc67a2265c2ab4f8d16b1d71ea5d43a129fa5)
@@ -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);
+    }
+
 }
