Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a verification email on registration #27

Merged

Conversation

Eukon05
Copy link
Contributor

@Eukon05 Eukon05 commented Jul 3, 2022

The user now has to confirm their email address after registration.

In order to test this functionality, you need to have MailDev installed, or use a real email account and modify the properties file accordingly.

- Modified User and CreateUserDTO to account for a new field: email

- Every new account is now disabled by default, and it needs to be activated via email

- Modified createUser() method in UserServiceImpl to send an activation email to the user after registration

- Created a method confirmUserRegistration() in UserServiceImpl, that is used to enable new accounts

- Created a new endpoint for confirming the registration
- Every hour, the app scans the DB for expired tokens and deletes them.

- If the token happens to be an unconfirmed registration token, the user associated with it is also deleted.

- When a user is deleted, all roles associated with them are also deleted.

- Additionally, I've also added a check for the email address on registration - the app will throw an exception if the address is already registered.
@MateuszCiapala
Copy link
Member

Conflicts has to be resolved before merge, resolve them and reopen pull request.

# Conflicts:
#	src/main/java/pl/simpleascoding/tutoringplatform/api/publicResource/UserController.java
#	src/main/java/pl/simpleascoding/tutoringplatform/service/user/UserFacade.java
#	src/main/java/pl/simpleascoding/tutoringplatform/service/user/UserServiceImpl.java
@Eukon05 Eukon05 reopened this Jul 5, 2022
@Eukon05
Copy link
Contributor Author

Eukon05 commented Jul 5, 2022

Conflicts resolved

@@ -0,0 +1,7 @@
package pl.simpleascoding.tutoringplatform.exception;

public class EmailTakenException extends RuntimeException {
Copy link
Member

@dawciobiel dawciobiel Jul 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proponowana nazwa klasy:

EmailAddressAlreadyTakenException
EmailAaddressAlreadyInUseException

Copy link
Member

@dawciobiel dawciobiel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite errors related to joining String objects, I approve. The code will be refactored in the future to use internationalized texts. So there is no point in correcting it twice.


public class EmailTakenException extends RuntimeException {
public EmailTakenException(String email) {
super("Email \"" + email + "\" is already in use");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tutaj jest konkatencja 3ch obiektów klasy String. Więc wychodzi, że JVM wykonuje takie operacje aby utworzyć wynikowy obiekt:

  • stworzenie obiektu: "Email" // p.s. Chyba miało być: E-mail

  • stworzenie obiektu: " is already in use" // p.s. is jest tutaj w zasadzie nie potrzebne, bo i tak zdanie będzie poprawne

  • stworzenie obiektu "Email adres@domena.com"

  • stworzenie obiektu "Email adres@domena.com is already in use"

  • garbage collector za jakiś okres czasu będzie musiał zwolnić zarezerwowaną pamięć dla obiektów: "Email", "is already in use". A więc będzie musiał mieć dodatkową robotę.

JVM też musi wykonać dodatkową robotę aby obiekty String stworzyć - właściwie na darmo, bo za chwile nie są one już potrzebne.

Więc może zamiast tak łączyć i rzeźbić warto użyć klasy StringBuffer bądź StringBuilder. Zależnie od wymaganego bezpieczeństwa wielowątkowości przy tej operacji.
string-vs-stringbuffer-vs-stringbuilder

p.s. W tym miejscu będzie też w przyszłości użyta metoda do pobrania odpowiedniej wersji językowej komunikatu. Ale przeróbka będzie banalnie prosta w pszyszłości.

StringBuilder sb = new StringBuilder("E-mail [");
sb.append(email);
sb.append("] already in use");

A w przyszłości całość będzie taka:
super(LanguageBundle.getMessage("EMAIL_ADDRESS_ALREADY_IN_USE_EXCEPTION", email);


public class UserAlreadyEnabledException extends RuntimeException {
public UserAlreadyEnabledException(String username) {
super("User \"" + username + "\" is already enabled");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taka sama uwaga jak przy klasie:
src/main/java/pl/simpleascoding/tutoringplatform/exception/EmailTakenException.java

@dawciobiel dawciobiel merged commit 7d961fc into Simple-as-Coding:main Jul 6, 2022
@Eukon05 Eukon05 deleted the register-mail-confirmation branch July 8, 2022 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants