-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marc Gorzala
committed
Oct 19, 2022
1 parent
fd1e230
commit 47f4870
Showing
26 changed files
with
253 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
docker exec -i dancer_dancer-db_1 psql -h localhost -U dancer postgres << SQL | ||
-- https://stackoverflow.com/questions/17449420/postgresql-unable-to-drop-database-because-of-some-auto-connections-to-db | ||
REVOKE CONNECT ON DATABASE dancer FROM public; | ||
SELECT pid, pg_terminate_backend(pid) | ||
FROM pg_stat_activity | ||
WHERE datname = 'dancer' AND pid <> pg_backend_pid(); | ||
drop database dancer; | ||
create database dancer; | ||
GRANT CONNECT ON DATABASE dancer TO public; | ||
SQL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/net/dancier/dancer/authentication/event/NewUserCreatedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package net.dancier.dancer.authentication.event; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
@Builder | ||
@Data | ||
public class NewUserCreatedEvent { | ||
|
||
private UUID id; | ||
|
||
private String email; | ||
|
||
private Set<String> roles; | ||
|
||
private Boolean isEmailValidated; | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/net/dancier/dancer/authentication/event/NewUserCreatedEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package net.dancier.dancer.authentication.event; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import net.dancier.dancer.authentication.model.EmailValidationCode; | ||
import net.dancier.dancer.authentication.repository.EmailValidationCodeRepository; | ||
import net.dancier.dancer.mail.service.MailCreationService; | ||
import net.dancier.dancer.mail.service.MailEnqueueService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.Instant; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class NewUserCreatedEventListener { | ||
|
||
private final static Logger log = LoggerFactory.getLogger(NewUserCreatedEventListener.class); | ||
|
||
private final EmailValidationCodeRepository emailValidationCodeRepository; | ||
private final MailEnqueueService mailEnqueueService; | ||
|
||
private final MailCreationService mailCreationService; | ||
|
||
private final String frontendBaseName; | ||
|
||
@EventListener | ||
void handle(NewUserCreatedEvent newUserCreatedEvent) { | ||
Objects.requireNonNull(newUserCreatedEvent.getId()); | ||
EmailValidationCode emailValidationCode = emailValidationCodeRepository | ||
.findByUserId(newUserCreatedEvent.getId()) | ||
.orElseGet(() -> new EmailValidationCode()); | ||
emailValidationCode.setExpiresAt(Instant | ||
.now() | ||
.plus(3, ChronoUnit.HOURS)); | ||
emailValidationCode.setUserId(newUserCreatedEvent.getId()); | ||
emailValidationCode.setCode(UUID.randomUUID().toString()); | ||
emailValidationCodeRepository.save(emailValidationCode); | ||
enqueueUserMail(newUserCreatedEvent, emailValidationCode.getCode()); | ||
log.debug("Created validation code: " + emailValidationCode.getCode() + " for user: " + newUserCreatedEvent); | ||
} | ||
|
||
private void enqueueUserMail(NewUserCreatedEvent newUserCreatedEvent, String code) { | ||
mailEnqueueService.enqueueMail( | ||
mailCreationService.createDancierMessageFromTemplate( | ||
newUserCreatedEvent.getEmail(), | ||
MailCreationService.NO_REPLY_FROM, | ||
"Dancier - bestätige Deine E-Mail-Adresse!", | ||
MailCreationService.NEW_USER_VALIDATE_EMAIL, | ||
Map.of( "validationLink", emailValidationLink(code) | ||
)) | ||
); | ||
} | ||
|
||
private String emailValidationLink(String validationCode) { | ||
return frontendBaseName + "/registration/verify-account/" + validationCode; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
src/main/java/net/dancier/dancer/cabaceo/CabaceoController.java
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
src/main/java/net/dancier/dancer/cabaceo/CabaceoService.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
src/main/java/net/dancier/dancer/cabaceo/NewCabaceoDto.java
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
src/main/java/net/dancier/dancer/core/AuthenticationSucceededEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package net.dancier.dancer.core; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
import org.springframework.security.core.Authentication; | ||
|
||
@Builder | ||
@Data | ||
public class AuthenticationSucceededEvent { | ||
|
||
Authentication authentication; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.