Skip to content

Commit

Permalink
registerManager
Browse files Browse the repository at this point in the history
  • Loading branch information
mertycom committed Feb 2, 2023
1 parent cd64653 commit 0c36cc9
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@ public UserDetails getUserByAuthId(Long authid){
Optional<Auth> auth = authService.findById(authid);
if (auth.isEmpty()) return null;
List<GrantedAuthority> authorities = new ArrayList<>();
/**
* Burada belirtilen isimlendirmeler tamamen size aittir. özel bir kullanım değildir.
* Yetki Adı: yönetici, asistan,
*/

authorities.add(new SimpleGrantedAuthority(auth.get().getRole().toString()));

return User.builder()
.username(auth.get().getEmail())
.password("")
.password(auth.get().getPassword())
.accountLocked(false)
.accountExpired(false)
.authorities(authorities)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

public class RestApi {
public static final String VERSION = "/v1";
public static final String DEV = "/dev";
public static final String TEST = "/test";

public static final String AUTH = VERSION+"/auth";

public static final String LOGIN = "/login";
public static final String REGISTER = "/register";
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public ResponseEntity<LoginResponseDto> login(@RequestBody @Valid LoginRequestDt

@PostMapping(REGISTER)
@CrossOrigin("*")
@Operation(summary = "kayit eden metot")
public ResponseEntity<RegisterResponseDto> register(@RequestBody @Valid RegisterRequestDto dto){
return ResponseEntity.ok(authService.save(dto));
@Operation(summary = "Manager kayit eden metot")
public ResponseEntity<RegisterResponseDto> registerManager(@RequestBody @Valid RegisterRequestDto dto){
return ResponseEntity.ok(authService.registerManager(dto));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.bilgeadam.mapper.IAuthMapper;
import com.bilgeadam.repository.AuthRepository;
import com.bilgeadam.repository.entity.Auth;
import com.bilgeadam.repository.entity.Roles;
import com.bilgeadam.utility.CodeGenerator;
import com.bilgeadam.utility.JwtTokenManager;
import com.bilgeadam.utility.ServiceManager;
Expand Down Expand Up @@ -48,18 +49,17 @@ public LoginResponseDto login(LoginRequestDto dto) {
return loginResponseDto;
}


public RegisterResponseDto save(RegisterRequestDto dto){
public RegisterResponseDto registerManager(RegisterRequestDto dto) {
if(!dto.getPassword().equals(dto.getRePassword()))
throw new AuthMicroserviceException(ErrorType.REGISTER_REPASSWORD_ERROR);
if(authRepository.findOptionalByEmail(dto.getEmail()).isPresent()){
throw new AuthMicroserviceException(ErrorType.DUPLICATE_EMAIL_ERROR);
}
Auth auth = IAuthMapper.INSTANCE.fromRequestToAuth(dto);
auth.setActivationCode(CodeGenerator.generateCode());
auth.setRole(Roles.GENERAL_MANAGER);
save(auth);
userProfileManager.createProfile(IAuthMapper.INSTANCE.fromAuth(auth));
return IAuthMapper.INSTANCE.fromAuthToLoginResponse(auth);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,5 @@ public Optional<Long> getByIdFromToken(String token){
}catch (Exception exception){
return Optional.empty();
}

}
}

0 comments on commit 0c36cc9

Please sign in to comment.