Browse Source

Activation key structure

main
ddangelorb 4 years ago
parent
commit
31181f92ed
  1. 10
      src/main/java/org/waterproofingdata/wpdauth/controller/UsersController.java
  2. 1
      src/main/java/org/waterproofingdata/wpdauth/dto/UsersRequestDTO.java
  3. 2
      src/main/java/org/waterproofingdata/wpdauth/dto/UsersResponseDTO.java
  4. 4
      src/main/java/org/waterproofingdata/wpdauth/repository/EduCemadenOrganizationsRepository.java
  5. 2
      src/main/java/org/waterproofingdata/wpdauth/repository/UsersRolesproviderActivationKeyRepository.java
  6. 15
      src/main/java/org/waterproofingdata/wpdauth/service/UsersService.java

10
src/main/java/org/waterproofingdata/wpdauth/controller/UsersController.java

@ -77,7 +77,10 @@ public class UsersController {
@ApiResponse(code = 404, message = "The user doesn't exist"), //
@ApiResponse(code = 500, message = "Expired or invalid JWT token")})
public UsersResponseDTO search(@ApiParam("Username") @PathVariable String username) {
return modelMapper.map(userService.search(username), UsersResponseDTO.class);
UsersResponseDTO urDTO = modelMapper.map(userService.search(username), UsersResponseDTO.class);
urDTO.setEduCemadenOrganization(userService.findEduCemadenOrganizationById(urDTO.getId()));
urDTO.setRolesProviderActivationKeys(userService.findRolesproviderActivationKeysById(urDTO.getId()));
return urDTO;
}
@GetMapping(value = "/me")
@ -88,7 +91,10 @@ public class UsersController {
@ApiResponse(code = 403, message = "Access denied"), //
@ApiResponse(code = 500, message = "Expired or invalid JWT token")})
public UsersResponseDTO whoami(HttpServletRequest req) {
return modelMapper.map(userService.whoami(req), UsersResponseDTO.class);
UsersResponseDTO urDTO = modelMapper.map(userService.whoami(req), UsersResponseDTO.class);
urDTO.setEduCemadenOrganization(userService.findEduCemadenOrganizationById(urDTO.getId()));
urDTO.setRolesProviderActivationKeys(userService.findRolesproviderActivationKeysById(urDTO.getId()));
return urDTO;
}
@GetMapping("/refresh")

1
src/main/java/org/waterproofingdata/wpdauth/dto/UsersRequestDTO.java

@ -9,6 +9,7 @@ import lombok.Setter;
public class UsersRequestDTO {
@ApiModelProperty(position = 0)
private String username;
@ApiModelProperty(position = 1)
private String password;
}

2
src/main/java/org/waterproofingdata/wpdauth/dto/UsersResponseDTO.java

@ -26,5 +26,5 @@ public class UsersResponseDTO {
EduCemadenOrganizations eduCemadenOrganization;
@ApiModelProperty(position = 4)
List<UsersRolesproviderActivationKey> rolesProviderActivationKey;
List<UsersRolesproviderActivationKey> rolesProviderActivationKeys;
}

4
src/main/java/org/waterproofingdata/wpdauth/repository/EduCemadenOrganizationsRepository.java

@ -11,9 +11,9 @@ public interface EduCemadenOrganizationsRepository extends JpaRepository<EduCema
EduCemadenOrganizations findByPhone(String phone);
@Query(value = "SELECT e.*, ueo.activationkey FROM educemaden_organizations e INNER JOIN users_educemaden_organizations ueo ON e.id = ueo.educemaden_organizations_id WHERE ueo.users_id = ?1;", nativeQuery = true)
EduCemadenOrganizations findByUserId(Integer idUser);
EduCemadenOrganizations findByUserId(Integer userid);
@Transactional
@Query(value = "INSERT INTO users_educemaden_organizations(id, users_id, educemaden_organizations_id, activationkey) VALUES (DEFAULT, ?1, ?2, ?3);", nativeQuery = true)
void insertUsersEduCemadenOrganizations(Integer idUser, Integer idEduCemadenOrganizations, String activationkey);
void insertUsersEduCemadenOrganizations(Integer userid, Integer eduCemadenOrganizationsid, String activationkey);
}

2
src/main/java/org/waterproofingdata/wpdauth/repository/UsersRolesproviderActivationKeyRepository.java

@ -5,6 +5,6 @@ import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.waterproofingdata.wpdauth.model.UsersRolesproviderActivationKey;
public interface UsersRolesproviderActivationKeyRepository extends JpaRepository<UsersRolesproviderActivationKey, Integer> {
public interface UsersRolesproviderActivationKeyRepository extends JpaRepository<UsersRolesproviderActivationKey, Integer> {
List<UsersRolesproviderActivationKey> findByUsersid(Integer usersid);
}

15
src/main/java/org/waterproofingdata/wpdauth/service/UsersService.java

@ -1,5 +1,6 @@
package org.waterproofingdata.wpdauth.service;
import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
@ -12,9 +13,12 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.waterproofingdata.wpdauth.exception.CustomException;
import org.waterproofingdata.wpdauth.model.EduCemadenOrganizations;
import org.waterproofingdata.wpdauth.model.Users;
import org.waterproofingdata.wpdauth.model.UsersRolesproviderActivationKey;
import org.waterproofingdata.wpdauth.repository.EduCemadenOrganizationsRepository;
import org.waterproofingdata.wpdauth.repository.UsersRepository;
import org.waterproofingdata.wpdauth.repository.UsersRolesproviderActivationKeyRepository;
import org.waterproofingdata.wpdauth.security.JwtTokenProvider;
@Service
@ -25,6 +29,9 @@ public class UsersService {
@Autowired
private EduCemadenOrganizationsRepository eduCemadenOrganizationsRepository;
@Autowired
private UsersRolesproviderActivationKeyRepository usersRolesproviderActivationKeyRepository;
@Autowired
private PasswordEncoder passwordEncoder;
@ -77,6 +84,14 @@ public class UsersService {
return userRepository.findByUsername(jwtTokenProvider.getUsername(jwtTokenProvider.resolveToken(req)));
}
public EduCemadenOrganizations findEduCemadenOrganizationById(Integer userid) {
return eduCemadenOrganizationsRepository.findByUserId(userid);
}
public List<UsersRolesproviderActivationKey> findRolesproviderActivationKeysById(Integer usersid) {
return usersRolesproviderActivationKeyRepository.findByUsersid(usersid);
}
public String refresh(String username) {
return jwtTokenProvider.createToken(username, userRepository.findByUsername(username).getRoles());
}

Loading…
Cancel
Save