/** * returns the current user and a new authorization token in the response */ protected Mono<UserDto> userWithToken(Mono<UserDto> userDto, ServerHttpResponse response) { return lemonReactiveService.userWithToken(userDto, response, jwtExpirationMillis); } }
/** * Signs up a user, and * returns current-user data and an Authorization token as a response header. */ @PostMapping("/users") @ResponseStatus(HttpStatus.CREATED) protected Mono<UserDto> signup(Mono<U> user, ServerHttpResponse response) { log.debug("Signing up: " + user); return userWithToken(lemonReactiveService.signup(user), response); }
/** * Resets password after it's forgotten */ @PostMapping("/reset-password") public Mono<UserDto> resetPassword( @RequestBody @Valid Mono<ResetPasswordForm> form, ServerHttpResponse response) { log.debug("Resetting password ... "); return userWithToken(lemonReactiveService.resetPassword(form), response); }
@Override protected User createAdminUser() { User user = super.createAdminUser(); user.setName(ADMIN_NAME); return user; }
/** * Verifies current-user */ @PostMapping("/users/{id}/verification") public Mono<UserDto> verifyUser( @PathVariable ID id, ServerWebExchange exchange) { log.debug("Verifying user ..."); return userWithToken(lemonReactiveService.verifyUser(id, exchange.getFormData()), exchange.getResponse()); }
/** * Changes the email */ @PostMapping("/users/{userId}/email") public Mono<UserDto> changeEmail( @PathVariable ID userId, ServerWebExchange exchange) { log.debug("Changing email of user ..."); return userWithToken(lemonReactiveService.changeEmail( userId, exchange.getFormData()), exchange.getResponse()); }
/** * Updates a user */ @PatchMapping(value = "/users/{id}") public Mono<UserDto> updateUser( @PathVariable ID id, @RequestBody @NotBlank Mono<String> patch, ServerHttpResponse response) { log.debug("Updating user ... "); return userWithToken(lemonReactiveService.updateUser(id, patch), response); }
/** * Changes password */ @PostMapping("/users/{id}/password") @ResponseStatus(HttpStatus.NO_CONTENT) public Mono<Void> changePassword(@PathVariable ID id, @RequestBody @Valid Mono<ChangePasswordForm> changePasswordForm, ServerHttpResponse response) { log.debug("Changing password ... "); return userWithToken(lemonReactiveService.changePassword(id, changePasswordForm), response).then(); }
@Override protected void updateUserFields(User user, User updatedUser, UserDto currentUser) { super.updateUserFields(user, updatedUser, currentUser); user.setName(updatedUser.getName()); }
public Mono<UserDto> verifyUser(ID userId, Mono<MultiValueMap<String, String>> formData) { log.debug("Verifying user ..."); return Mono.zip(findUserById(userId), formData) .map(this::verifyUser) .flatMap(userRepository::save) .map(AbstractMongoUser::toUserDto); }
public UniqueEmailValidator(MongoTemplate mongoTemplate, LemonReactiveService<?,?> lemonReactiveService) { this.mongoTemplate = mongoTemplate; this.userClass = lemonReactiveService.newUser().getClass(); log.info("Created"); }
@Bean @ConditionalOnMissingBean(IdConverter.class) public <ID extends Serializable> IdConverter<ID> idConverter(LemonReactiveService<?,ID> lemonService) { return id -> lemonService.toId(id); }
/** * Fetch a new token - for session sliding, switch user etc. */ @PostMapping("/fetch-new-auth-token") public Mono<Map<String, String>> fetchNewToken(ServerWebExchange exchange) { log.debug("Fetching a new token ... "); return lemonReactiveService.fetchNewToken(exchange); //return LecUtils.mapOf("token", lemonService.fetchNewToken(expirationMillis, username)); }
/** * This method is called after the application is ready. * Needs to be public - otherwise Spring screams. * * @param event */ @EventListener public void afterApplicationReady(ApplicationReadyEvent event) { log.info("Starting up Spring Lemon ..."); onStartup(); // delegate to onStartup() log.info("Spring Lemon started"); }
/** * Fetches a user by ID */ @GetMapping("/users/{id}") public Mono<U> fetchUserById(@PathVariable ID id) { log.debug("Fetching user: " + id); return lemonReactiveService.fetchUserById(id); }
/** * Fetches a user by email */ @PostMapping("/users/fetch-by-email") public Mono<U> fetchUserByEmail(ServerWebExchange exchange) { log.debug("Fetching user by email ... "); return lemonReactiveService.fetchUserByEmail(exchange.getFormData()); }
/** * Fetch a self-sufficient token with embedded UserDto - for interservice communications */ @GetMapping("/fetch-full-token") public Mono<Map<String, String>> fetchFullToken(@RequestHeader(HttpHeaders.AUTHORIZATION) String authHeader) { log.debug("Fetching a micro token"); return lemonReactiveService.fetchFullToken(authHeader); }
@Override public Mono<UserDto> signup( @RequestBody @JsonView(UserUtils.SignupInput.class) @Validated(SignUpValidation.class) Mono<User> user, ServerHttpResponse response) { return super.signup(user, response); } }
public Mono<U> fetchUserById(ID userId) { // fetch the user return findUserById(userId) .zipWith(LecrUtils.currentUser()) .doOnNext(this::hideConfidentialFields) .map(Tuple2::getT1); }
/** * Resends verification mail to the user. */ public Mono<Void> resendVerificationMail(ID userId) { return findUserById(userId) .zipWith(LecrUtils.currentUser()) .doOnNext(this::ensureEditable) .map(Tuple2::getT1) .doOnNext(this::resendVerificationMail).then(); }