Index: phonelux-backend/pom.xml
===================================================================
--- phonelux-backend/pom.xml	(revision dbd483418f962e3b40992a977eef4ece28007aa2)
+++ phonelux-backend/pom.xml	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
@@ -18,20 +18,25 @@
 	</properties>
 	<dependencies>
+
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-data-jpa</artifactId>
 		</dependency>
+
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-security</artifactId>
 		</dependency>
+
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-web</artifactId>
 		</dependency>
+
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-mail</artifactId>
 		</dependency>
+
 		<dependency>
 			<groupId>org.postgresql</groupId>
@@ -39,4 +44,5 @@
 			<scope>runtime</scope>
 		</dependency>
+
 		<dependency>
 			<groupId>org.projectlombok</groupId>
@@ -44,4 +50,5 @@
 			<optional>true</optional>
 		</dependency>
+
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
@@ -49,4 +56,5 @@
 			<scope>test</scope>
 		</dependency>
+
 		<dependency>
 			<groupId>org.springframework.security</groupId>
@@ -54,4 +62,11 @@
 			<scope>test</scope>
 		</dependency>
+
+		<dependency>
+			<groupId>com.auth0</groupId>
+			<artifactId>java-jwt</artifactId>
+			<version>4.0.0</version>
+		</dependency>
+
 	</dependencies>
 
Index: phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/PhoneController.java
===================================================================
--- phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/PhoneController.java	(revision dbd483418f962e3b40992a977eef4ece28007aa2)
+++ phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/PhoneController.java	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
@@ -3,26 +3,57 @@
 import finki.it.phoneluxbackend.entities.Phone;
 import finki.it.phoneluxbackend.entities.PhoneOffer;
+import finki.it.phoneluxbackend.services.PhoneOfferService;
 import finki.it.phoneluxbackend.services.PhoneService;
+import lombok.AllArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.Comparator;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @RestController
+@AllArgsConstructor
 @RequestMapping(path = "/")
 public class PhoneController {
     private final PhoneService phoneService;
+    private final PhoneOfferService phoneOfferService;
 
-    @Autowired
-    public PhoneController(PhoneService phoneService) {
-        this.phoneService = phoneService;
+//     handle request parameters for filtering phones
+    @GetMapping(path = "/phones")
+    public List<Phone> getPhones(){
+        return phoneService.getPhones().stream()
+                .sorted(Comparator.comparing(Phone::getTotal_offers).reversed())
+                .collect(Collectors.toList());
+    }
+
+    @GetMapping(path = "/phones/{phoneId}")
+    public Phone getPhoneById(@PathVariable("phoneId") Long phoneId)
+    {
+        return phoneService.getPhoneById(phoneId);
+    }
+
+    @GetMapping(path = "/brands")
+    public List<String> getBrands(){
+        return phoneService.getBrands();
+    }
+
+    @GetMapping(path = "/shops")
+    public List<String> getShops(){
+        return phoneOfferService.getShops();
+    }
+
+    @GetMapping(path = "/lowestPrice")
+    public int getLowestPrice()
+    {
+        return phoneOfferService.getLowestPrice();
+    }
+
+    @GetMapping(path = "/highestPrice")
+    public int getHighestPrice()
+    {
+        return phoneOfferService.getHighestPrice();
     }
 
 
-    // handle request parameters for filtering phones
-    @GetMapping
-    public List<Phone> getPhones(){
-        return phoneService.getPhones();
-    }
-
 }
Index: phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/PhoneOfferController.java
===================================================================
--- phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/PhoneOfferController.java	(revision dbd483418f962e3b40992a977eef4ece28007aa2)
+++ phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/PhoneOfferController.java	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
@@ -1,6 +1,9 @@
 package finki.it.phoneluxbackend.controllers;
 
+import finki.it.phoneluxbackend.entities.Phone;
 import finki.it.phoneluxbackend.entities.PhoneOffer;
 import finki.it.phoneluxbackend.services.PhoneOfferService;
+import finki.it.phoneluxbackend.services.PhoneService;
+import lombok.AllArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -12,12 +15,9 @@
 
 @RestController
-@RequestMapping(path = "/phone/{phoneId}")
+@AllArgsConstructor
+@RequestMapping(path = "/phones/offers/{phoneId}")
 public class PhoneOfferController {
     private final PhoneOfferService phoneOfferService;
-
-    @Autowired
-    public PhoneOfferController(PhoneOfferService phoneOfferService) {
-        this.phoneOfferService = phoneOfferService;
-    }
+    private final PhoneService phoneService;
 
     @GetMapping
@@ -25,3 +25,4 @@
         return phoneOfferService.getPhoneOffersForPhone(phoneId);
     }
+
 }
Index: phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/RegistrationController.java
===================================================================
--- phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/RegistrationController.java	(revision dbd483418f962e3b40992a977eef4ece28007aa2)
+++ phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/RegistrationController.java	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
@@ -4,4 +4,5 @@
 import finki.it.phoneluxbackend.services.RegistrationService;
 import lombok.AllArgsConstructor;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
@@ -13,5 +14,5 @@
 
     @PostMapping
-    public String RegisterRequest(@RequestBody RegistrationRequest request)
+    public ResponseEntity<Object> RegisterRequest(@RequestBody RegistrationRequest request)
     {
         return registrationService.register(request);
Index: phonelux-backend/src/main/java/finki/it/phoneluxbackend/entities/ConfirmationToken.java
===================================================================
--- phonelux-backend/src/main/java/finki/it/phoneluxbackend/entities/ConfirmationToken.java	(revision dbd483418f962e3b40992a977eef4ece28007aa2)
+++ phonelux-backend/src/main/java/finki/it/phoneluxbackend/entities/ConfirmationToken.java	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
@@ -13,5 +13,6 @@
 @Setter
 @NoArgsConstructor
-@Entity(name = "confirmation_tokens")
+@Entity(name = "ConfirmationToken")
+@Table(name = "confirmation_tokens")
 public class ConfirmationToken {
 
Index: phonelux-backend/src/main/java/finki/it/phoneluxbackend/entities/Phone.java
===================================================================
--- phonelux-backend/src/main/java/finki/it/phoneluxbackend/entities/Phone.java	(revision dbd483418f962e3b40992a977eef4ece28007aa2)
+++ phonelux-backend/src/main/java/finki/it/phoneluxbackend/entities/Phone.java	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
@@ -28,4 +28,10 @@
     private String image_url;
 
+    @Column(name = "total_offers")
+    private Integer total_offers;
+
+    @Column(name = "lowest_price")
+    private Integer lowestPrice;
+
     @OneToMany(fetch = FetchType.LAZY, mappedBy = "phone")
     @JsonIgnore
Index: phonelux-backend/src/main/java/finki/it/phoneluxbackend/entities/PhoneOffer.java
===================================================================
--- phonelux-backend/src/main/java/finki/it/phoneluxbackend/entities/PhoneOffer.java	(revision dbd483418f962e3b40992a977eef4ece28007aa2)
+++ phonelux-backend/src/main/java/finki/it/phoneluxbackend/entities/PhoneOffer.java	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
@@ -5,5 +5,7 @@
 
 import javax.persistence.*;
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
 
 @AllArgsConstructor
@@ -73,4 +75,7 @@
     private String offer_shop_code;
 
+    @ManyToMany(mappedBy = "favouriteOffers")
+    private List<User> users = new ArrayList<User>();
+
     @ManyToOne(fetch = FetchType.LAZY)
     @JoinColumn(name = "phone_id", referencedColumnName = "id")
Index: phonelux-backend/src/main/java/finki/it/phoneluxbackend/entities/User.java
===================================================================
--- phonelux-backend/src/main/java/finki/it/phoneluxbackend/entities/User.java	(revision dbd483418f962e3b40992a977eef4ece28007aa2)
+++ phonelux-backend/src/main/java/finki/it/phoneluxbackend/entities/User.java	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
@@ -8,6 +8,8 @@
 
 import javax.persistence.*;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.List;
 
 @Getter
@@ -16,5 +18,6 @@
 @NoArgsConstructor
 @AllArgsConstructor
-@Entity(name = "users")
+@Entity(name = "User")
+@Table(name = "users")
 public class User implements UserDetails {
 
@@ -38,4 +41,12 @@
     private Boolean locked = false;
     private Boolean enabled = false;
+
+    @ManyToMany
+    @JoinTable(
+            name = "users_favourite_offers",
+            joinColumns = @JoinColumn(name = "user_id"),
+            inverseJoinColumns = @JoinColumn(name = "offer_id")
+    )
+    private List<PhoneOffer> favouriteOffers = new ArrayList<PhoneOffer>();
 
     public User(String firstName, String lastName, String email, String password, UserRole userRole) {
Index: phonelux-backend/src/main/java/finki/it/phoneluxbackend/repositories/ConfirmationTokenRepository.java
===================================================================
--- phonelux-backend/src/main/java/finki/it/phoneluxbackend/repositories/ConfirmationTokenRepository.java	(revision dbd483418f962e3b40992a977eef4ece28007aa2)
+++ phonelux-backend/src/main/java/finki/it/phoneluxbackend/repositories/ConfirmationTokenRepository.java	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
@@ -17,5 +17,5 @@
     @Transactional
     @Modifying
-    @Query("UPDATE confirmation_tokens c " +
+    @Query("UPDATE ConfirmationToken c " +
             "SET c.confirmedAt = ?2 " +
             "WHERE c.token = ?1")
Index: phonelux-backend/src/main/java/finki/it/phoneluxbackend/repositories/UserRepository.java
===================================================================
--- phonelux-backend/src/main/java/finki/it/phoneluxbackend/repositories/UserRepository.java	(revision dbd483418f962e3b40992a977eef4ece28007aa2)
+++ phonelux-backend/src/main/java/finki/it/phoneluxbackend/repositories/UserRepository.java	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
@@ -18,5 +18,5 @@
     @Transactional
     @Modifying
-    @Query("UPDATE users a " +
+    @Query("UPDATE User a " +
             "SET a.enabled = TRUE WHERE a.email = ?1")
     int enableUser(String email);
Index: phonelux-backend/src/main/java/finki/it/phoneluxbackend/security/CustomAuthenticationFilter.java
===================================================================
--- phonelux-backend/src/main/java/finki/it/phoneluxbackend/security/CustomAuthenticationFilter.java	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
+++ phonelux-backend/src/main/java/finki/it/phoneluxbackend/security/CustomAuthenticationFilter.java	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
@@ -0,0 +1,69 @@
+package finki.it.phoneluxbackend.security;
+
+import com.auth0.jwt.JWT;
+import com.auth0.jwt.algorithms.Algorithm;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import finki.it.phoneluxbackend.entities.User;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
+
+public class CustomAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
+    private final AuthenticationManager authenticationManager;
+
+    public CustomAuthenticationFilter(AuthenticationManager authenticationManager) {
+        this.authenticationManager = authenticationManager;
+    }
+
+    @Override
+    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
+        String email = request.getParameter("email"); // mozda ke treba da se smeni vo username
+        String password = request.getParameter("password");
+        UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(email,password);
+        return authenticationManager.authenticate(authenticationToken);
+    }
+
+    @Override
+    protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authentication) throws IOException, ServletException {
+        User user = (User)authentication.getPrincipal();
+        Algorithm algorithm = Algorithm.HMAC256("secret".getBytes());
+
+        String access_token = JWT.create()
+                .withSubject(user.getEmail())
+                .withExpiresAt(new Date(System.currentTimeMillis() + 10 * 60 * 1000))
+                .withIssuer(request.getRequestURL().toString())
+                .withClaim("role", user.getAuthorities().stream()
+                        .map(GrantedAuthority::getAuthority).collect(Collectors.toList()))
+                .sign(algorithm);
+
+//        String refresh_token = JWT.create()
+//                .withSubject(user.getEmail())
+//                .withExpiresAt(new Date(System.currentTimeMillis() + 30 * 60 * 1000))
+//                .withIssuer(request.getRequestURL().toString())
+//                .withClaim("role",user.getAuthorities().stream()
+//                        .map(GrantedAuthority::getAuthority).collect(Collectors.toList()))
+//                .sign(algorithm);
+
+
+        Map<String,String> tokens = new HashMap<>();
+        tokens.put("access_token",access_token);
+//        tokens.put("refresh_token",refresh_token);
+        response.setContentType(APPLICATION_JSON_VALUE);
+        new ObjectMapper().writeValue(response.getOutputStream(),tokens);
+    }
+}
Index: phonelux-backend/src/main/java/finki/it/phoneluxbackend/security/CustomAuthorizationFilter.java
===================================================================
--- phonelux-backend/src/main/java/finki/it/phoneluxbackend/security/CustomAuthorizationFilter.java	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
+++ phonelux-backend/src/main/java/finki/it/phoneluxbackend/security/CustomAuthorizationFilter.java	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
@@ -0,0 +1,67 @@
+package finki.it.phoneluxbackend.security;
+
+import com.auth0.jwt.JWT;
+import com.auth0.jwt.JWTVerifier;
+import com.auth0.jwt.algorithms.Algorithm;
+import com.auth0.jwt.interfaces.DecodedJWT;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.*;
+
+import static org.springframework.http.HttpHeaders.AUTHORIZATION;
+import static org.springframework.http.HttpStatus.FORBIDDEN;
+import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
+
+public class CustomAuthorizationFilter extends OncePerRequestFilter {
+    @Override
+    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
+        if(request.getServletPath().equals("/login")){
+            filterChain.doFilter(request,response); // not doing anything, just passing the request to the next filter in the filter chain
+        }
+        else{
+            String authorizationHeader = request.getHeader(AUTHORIZATION);
+            if(authorizationHeader != null && authorizationHeader.startsWith("Bearer "))
+            {
+                try {
+                    String token = authorizationHeader.substring("Bearer ".length());
+                    Algorithm algorithm = Algorithm.HMAC256("secret".getBytes());
+                    JWTVerifier verifier = JWT.require(algorithm).build();
+                    DecodedJWT decodedJWT = verifier.verify(token);
+                    String email = decodedJWT.getSubject();
+                    String [] roles = decodedJWT.getClaim("role").asArray(String.class);
+                    Collection<SimpleGrantedAuthority> authorities = new ArrayList<>();
+                    Arrays.stream(roles).forEach(role -> {
+                        authorities.add(new SimpleGrantedAuthority(role));
+                    });
+                    UsernamePasswordAuthenticationToken authenticationToken =
+                            new UsernamePasswordAuthenticationToken(email,null,authorities);
+
+                    SecurityContextHolder.getContext().setAuthentication(authenticationToken);
+                    filterChain.doFilter(request,response);
+
+                }catch(Exception exception){
+                    response.setHeader("error", exception.getMessage());
+                    response.setStatus(FORBIDDEN.value());
+                    Map<String,String> error = new HashMap<>();
+                    error.put("error_message", exception.getMessage());
+                    response.setContentType(APPLICATION_JSON_VALUE);
+                    new ObjectMapper().writeValue(response.getOutputStream(),error);
+                }
+            }
+            else{
+                filterChain.doFilter(request,response);
+            }
+
+        }
+    }
+}
Index: phonelux-backend/src/main/java/finki/it/phoneluxbackend/security/configs/WebSecurityConfig.java
===================================================================
--- phonelux-backend/src/main/java/finki/it/phoneluxbackend/security/configs/WebSecurityConfig.java	(revision dbd483418f962e3b40992a977eef4ece28007aa2)
+++ phonelux-backend/src/main/java/finki/it/phoneluxbackend/security/configs/WebSecurityConfig.java	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
@@ -1,18 +1,21 @@
 package finki.it.phoneluxbackend.security.configs;
 
+import finki.it.phoneluxbackend.security.CustomAuthenticationFilter;
+import finki.it.phoneluxbackend.security.CustomAuthorizationFilter;
 import finki.it.phoneluxbackend.services.UserService;
 import lombok.AllArgsConstructor;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.security.authentication.AuthenticationManager;
 import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
-import org.springframework.security.config.annotation.SecurityBuilder;
 import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
-import org.springframework.security.config.annotation.web.WebSecurityConfigurer;
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration;
 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
+import org.springframework.security.config.http.SessionCreationPolicy;
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
-import org.springframework.security.web.SecurityFilterChain;
+import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
+
+import static org.springframework.http.HttpMethod.GET;
 
 @Configuration
@@ -26,12 +29,19 @@
     @Override
     protected void configure(HttpSecurity http) throws Exception {
-        http
-                .csrf().disable()
-                .authorizeRequests()
-                .antMatchers("/registration/**")
-                .permitAll()
-                .anyRequest()
-                .authenticated().and()
-                .formLogin();
+//        http
+//                .csrf().disable()
+//                .authorizeRequests()
+//                .antMatchers("/registration/**")
+//                .permitAll()
+//                .anyRequest()
+//                .authenticated().and()
+//                .formLogin();
+
+        http.csrf().disable();
+        http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
+//        http.authorizeRequests().antMatchers(GET,"/phones").hasAnyAuthority("USER");
+        http.authorizeRequests().anyRequest().permitAll();
+        http.addFilter(new CustomAuthenticationFilter(authenticationManagerBean()));
+        http.addFilterBefore(new CustomAuthorizationFilter(), UsernamePasswordAuthenticationFilter.class);
 
     }
@@ -42,4 +52,9 @@
     }
 
+    @Bean
+    @Override
+    public AuthenticationManager authenticationManagerBean() throws Exception {
+        return super.authenticationManagerBean();
+    }
 
     public DaoAuthenticationProvider daoAuthenticationProvider(){
Index: phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/PhoneOfferService.java
===================================================================
--- phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/PhoneOfferService.java	(revision dbd483418f962e3b40992a977eef4ece28007aa2)
+++ phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/PhoneOfferService.java	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
@@ -7,5 +7,7 @@
 
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @Service
@@ -24,5 +26,27 @@
             throw new IllegalStateException("Phone with id "+phoneId+" does not exist");
 
-        return phoneRepository.findById(phoneId).get().getPhoneOffers();
+        return phoneRepository.findById(phoneId).get().getPhoneOffers()
+                .stream().sorted(Comparator.comparing(PhoneOffer::getPrice)).collect(Collectors.toList());
     }
+
+    public List<String> getShops() {
+        return phoneOfferRepository.findAll().stream()
+                .map(PhoneOffer::getOffer_shop)
+                .distinct()
+                .collect(Collectors.toList());
+    }
+
+
+    public int getLowestPrice() {
+        return phoneOfferRepository.findAll()
+                .stream().sorted(Comparator.comparing(PhoneOffer::getPrice))
+                .collect(Collectors.toList()).get(0).getPrice();
+    }
+
+    public int getHighestPrice() {
+        return phoneOfferRepository.findAll()
+                .stream().sorted(Comparator.comparing(PhoneOffer::getPrice).reversed())
+                .collect(Collectors.toList()).get(0).getPrice();
+    }
+
 }
Index: phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/PhoneService.java
===================================================================
--- phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/PhoneService.java	(revision dbd483418f962e3b40992a977eef4ece28007aa2)
+++ phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/PhoneService.java	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
@@ -4,8 +4,11 @@
 import finki.it.phoneluxbackend.entities.PhoneOffer;
 import finki.it.phoneluxbackend.repositories.PhoneRepository;
+import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Sort;
 import org.springframework.stereotype.Service;
 
+import java.util.Comparator;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @Service
@@ -17,7 +20,21 @@
     }
 
+
+    // TODO: insert logic to filter
     public List<Phone> getPhones(){
         return phoneRepository.findAll();
     }
 
+    public List<String> getBrands(){
+        return phoneRepository.findAll().stream()
+                .map(Phone::getBrand).distinct()
+                .collect(Collectors.toList());
+    }
+
+    public Phone getPhoneById(Long phoneId) {
+        boolean exists = phoneRepository.existsById(phoneId);
+        if(!exists)
+            throw new IllegalStateException("Phone with id "+phoneId+" does not exist");
+        return phoneRepository.findById(phoneId).get();
+    }
 }
Index: phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/RegistrationService.java
===================================================================
--- phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/RegistrationService.java	(revision dbd483418f962e3b40992a977eef4ece28007aa2)
+++ phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/RegistrationService.java	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
@@ -1,4 +1,8 @@
 package finki.it.phoneluxbackend.services;
 
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.io.JsonStringEncoder;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.util.JSONPObject;
 import finki.it.phoneluxbackend.data.RegistrationRequest;
 import finki.it.phoneluxbackend.data.UserRole;
@@ -8,8 +12,13 @@
 import finki.it.phoneluxbackend.security.email.EmailValidator;
 import lombok.AllArgsConstructor;
+import org.apache.coyote.Response;
+import org.apache.tomcat.util.json.JSONParser;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.time.LocalDateTime;
+import java.util.HashMap;
 
 @Service
@@ -22,12 +31,12 @@
 
 
-    public String register(RegistrationRequest request) {
+    public ResponseEntity<Object> register(RegistrationRequest request) {
         boolean isValidEmail = emailValidator.test(request.getEmail());
 
-        // validacija za mejl na frontend ?
+        // mail is validated on frontend already
         if (!isValidEmail)
             throw new IllegalStateException("Email"+request.getEmail()+" not valid!");
 
-        String token = userService.signUpUser(
+        ResponseEntity response = userService.signUpUser(
                 new User(request.getFirstName(),
                         request.getLastName(),
@@ -36,7 +45,14 @@
                         UserRole.USER));
 
-        String link = "http://localhost:8080/registration/confirm?token="+token;
+        if (response.getStatusCode() == HttpStatus.BAD_REQUEST)
+        {
+            return response;
+        }
+
+        String link = "http://localhost:8080/registration/confirm?token="+response.getBody()
+                .toString().split(":")[1];
         emailSender.send(request.getEmail(), buildEmail(request.getFirstName(),link));
-        return token;
+
+        return response;
     }
 
@@ -113,14 +129,20 @@
     @Transactional
     public String confirmToken(String token) {
-        ConfirmationToken confirmationToken = confirmationTokenService.getToken(token)
-                .orElseThrow(() -> new IllegalStateException("Token not found!"));
+        boolean confirmationTokenExists = confirmationTokenService.getToken(token).isPresent();
+
+        ConfirmationToken confirmationToken;
+
+        if(confirmationTokenExists)
+            confirmationToken = confirmationTokenService.getToken(token).get();
+        else
+            return "Token not found!";
 
         if(confirmationToken.getConfirmedAt() != null)
-            throw new IllegalStateException("Email already confirmed!");
+            return "Email already confirmed!";
 
         LocalDateTime expiresAt = confirmationToken.getExpiresAt();
 
         if (expiresAt.isBefore(LocalDateTime.now())){
-            throw new IllegalStateException("Token expired");
+            return "Token expired";
         }
 
Index: phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/UserService.java
===================================================================
--- phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/UserService.java	(revision dbd483418f962e3b40992a977eef4ece28007aa2)
+++ phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/UserService.java	(revision f25d07ebb042093cfa244826fdc53c72cc4e6854)
@@ -1,3 +1,4 @@
 package finki.it.phoneluxbackend.services;
+
 
 import finki.it.phoneluxbackend.entities.User;
@@ -5,4 +6,6 @@
 import finki.it.phoneluxbackend.entities.ConfirmationToken;
 import lombok.AllArgsConstructor;
+
+import org.springframework.http.ResponseEntity;
 import org.springframework.security.core.userdetails.UserDetails;
 import org.springframework.security.core.userdetails.UserDetailsService;
@@ -12,4 +15,5 @@
 
 import java.time.LocalDateTime;
+
 import java.util.UUID;
 
@@ -28,10 +32,17 @@
     }
 
-    public String signUpUser(User user)
+    public ResponseEntity<Object> signUpUser(User user)
     {
-       boolean userExists =  userRepository.findByEmail(user.getEmail()).isPresent();
+       boolean userExists = userRepository.findByEmail(user.getEmail()).isPresent();
 
-       if (userExists && user.getEnabled()){
-           throw new IllegalStateException("Email "+user.getEmail()+" already taken!");
+
+       if (userExists){
+           User userToRegister =  userRepository.findByEmail(user.getEmail()).get();
+           if(userToRegister.getEnabled()) {
+               return ResponseEntity.badRequest().body("Error: Email "+user.getEmail()+" already taken!");
+           }
+           else {
+               return ResponseEntity.badRequest().body("Email "+user.getEmail()+" not activated!" );
+           }
        }
 
@@ -49,5 +60,5 @@
         confirmationTokenService.saveConfirmationToken(confirmationToken);
 
-        return token;
+        return ResponseEntity.ok().body("token:"+token);
     }
 
