ali-bouali / book-social-network

BSN is a social network platform to exchange books between the members.
Apache License 2.0
464 stars 91 forks source link

Small correction. #5

Open bumerrrang opened 2 months ago

bumerrrang commented 2 months ago

https://github.com/ali-bouali/book-social-network/blame/f9e16680db83b154b926aef2984994c252a37cc5/book-network/src/main/java/com/alibou/book/email/EmailService.java#L40

With the code as it is I always got an error: org.thymeleaf.exceptions.TemplateInputException: Error resolving template [ACTIVATE_ACCOUNT], template might not exist or might not be accessible by any of the configured Template Resolvers

After changing templateName = emailTemplate.name(); to templateName = emailTemplate.getName(); everything is working.

elbehimootez commented 2 months ago

thanks for sharing, i'll also have the same error but works fine right now

AtalibAgAlmousleck commented 1 month ago

Alibou sir i'm having an issue that i couldn't fix in the account activation it always saying invalid token

bumerrrang commented 1 month ago

I think that I know how to help, and I hope Ali allows me to answer the question. For activation the application is waiting not a token, but the been generated and saved code:

private String generateActivationCode(int length) {
    String characters = "0123456789";
    StringBuilder codeBuilder = new StringBuilder();

    SecureRandom secureRandom = new SecureRandom();

    for (int i = 0; i < length; i++) {
        int randomIndex = secureRandom.nextInt(characters.length());
        codeBuilder.append(characters.charAt(randomIndex));
    }

    return codeBuilder.toString();
}

So you could try to send it instead of sending token for the activation.

bumerrrang commented 1 month ago

thanks for sharing, i'll also have the same error but works fine right now

Sorry - I think I described the issue badly. The application can be booted and is running without any error, but while you are doing a registration, email can't be sent (it not appears here http://localhost:1080/#/), and in terminal appears this error message org.thymeleaf.exceptions.TemplateInputException: Error resolving template [ACTIVATE_ACCOUNT], template might not exist or might not be accessible by any of the configured Template Resolvers This is why I started the discussion, as I found the correction. The registration can't work without it correctly.

bumerrrang commented 1 month ago

Alibou sir i'm having an issue that i couldn't fix in the account activation it always saying invalid token

Hello, also you could recheck ~ 02:48:00 the tutorial video https://www.youtube.com/watch?v=xqhdRrFzLFY I think the problem is described there.

AtalibAgAlmousleck commented 1 month ago

The issue is that i can reiceive the verification token but when for the activation i got Invalid token exception and i have log the token it seems i got two different token. like this "Invalid token787589,824433"

AtalibAgAlmousleck commented 1 month ago

This is the error i got when verified the account it seems to generate to different token { "message": "Token not found: 787589,622352", "status": 401 }

AtalibAgAlmousleck commented 1 month ago

I have also removed @Transactional on the activateAccount method

bumerrrang commented 1 month ago

You should make postgres and mail containers to start from zero every time - for that I changed this ddl-auto: update to this ddl-auto: create-drop

Now every time you restart the application you have its initial state. What that gave? By your comments I there is some trouble with saving generated token in the database. I think you should debug the code and explore why the saved code is like this '787589,622352', as it has to be two times shorter: this 787589 or this 622352. How it happened you sending while testing this 'doubled' code? It is not right.

This is the error i got when verified the account it seems to generate to different token { "message": "Token not found: 787589,622352", "status": 401 }

AtalibAgAlmousleck commented 1 month ago

Exactly while testing the token has double. Let me show you i have debug image

here is my repository link: https://github.com/AtalibAgAlmousleck/full-stack-spring-boot-angular-books

bumerrrang commented 1 month ago

Exactly while testing the token has double. Let me show you i have debug image

here is my repository link: https://github.com/AtalibAgAlmousleck/full-stack-spring-boot-angular-books

I would like to offer you to find the solution, so please read carefully - I am trying to help. Thanks for sharing the picture - but the main problem is the same - how this double token '787589,622352' appeared in the db? I think you should simply to start with new email and postgres services (the simplest way for me was editing this ddl-auto: update to this ddl-auto: create-drop in the project application-dev.yml file) Then, you could start the application with switched debug here **private String generateAndSaveActivationToken(User user) { // Generate a token String generatedToken = generateActivationCode(6); var token = Token.builder() .token(generatedToken) .createdAt(LocalDateTime.now()) .expiresAt(LocalDateTime.now().plusMinutes(15)) .user(user) .build(); tokenRepository.save(token);

    return generatedToken;
}**

After this method the generated token has to be saved in the db and you could check it. It should contain only six numbers (if yoy did not do any changes in this tutorial). One more question - did you change the EmailService.java #41 templateName = emailTemplate.name(); to templateName = emailTemplate.getName();? I think without this correction the registration process also can't be successfully accomplished.

bumerrrang commented 1 month ago

Exactly while testing the token has double. Let me show you i have debug image

here is my repository link: https://github.com/AtalibAgAlmousleck/full-stack-spring-boot-angular-books

Unfortunately the git link you sent can't be opened - please recheck. Maybe it is better to see your code.