Ignore:
Timestamp:
09/07/22 00:51:50 (2 years ago)
Author:
Marko <Marko@…>
Branches:
master
Children:
527b93f
Parents:
dbd4834
Message:

Edited registration and login services

File:
1 edited

Legend:

Unmodified
Added
Removed
  • phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/UserService.java

    rdbd4834 rf25d07e  
    11package finki.it.phoneluxbackend.services;
     2
    23
    34import finki.it.phoneluxbackend.entities.User;
     
    56import finki.it.phoneluxbackend.entities.ConfirmationToken;
    67import lombok.AllArgsConstructor;
     8
     9import org.springframework.http.ResponseEntity;
    710import org.springframework.security.core.userdetails.UserDetails;
    811import org.springframework.security.core.userdetails.UserDetailsService;
     
    1215
    1316import java.time.LocalDateTime;
     17
    1418import java.util.UUID;
    1519
     
    2832    }
    2933
    30     public String signUpUser(User user)
     34    public ResponseEntity<Object> signUpUser(User user)
    3135    {
    32        boolean userExists =  userRepository.findByEmail(user.getEmail()).isPresent();
     36       boolean userExists = userRepository.findByEmail(user.getEmail()).isPresent();
    3337
    34        if (userExists && user.getEnabled()){
    35            throw new IllegalStateException("Email "+user.getEmail()+" already taken!");
     38
     39       if (userExists){
     40           User userToRegister =  userRepository.findByEmail(user.getEmail()).get();
     41           if(userToRegister.getEnabled()) {
     42               return ResponseEntity.badRequest().body("Error: Email "+user.getEmail()+" already taken!");
     43           }
     44           else {
     45               return ResponseEntity.badRequest().body("Email "+user.getEmail()+" not activated!" );
     46           }
    3647       }
    3748
     
    4960        confirmationTokenService.saveConfirmationToken(confirmationToken);
    5061
    51         return token;
     62        return ResponseEntity.ok().body("token:"+token);
    5263    }
    5364
Note: See TracChangeset for help on using the changeset viewer.