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

Small correction. #5

Open
bumerrrang opened this issue May 14, 2024 · 12 comments
Open

Small correction. #5

bumerrrang opened this issue May 14, 2024 · 12 comments

Comments

@bumerrrang
Copy link

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
Copy link

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

@AtalibAgAlmousleck
Copy link

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

@bumerrrang
Copy link
Author

bumerrrang commented May 21, 2024

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
Copy link
Author

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
Copy link
Author

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
Copy link

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
Copy link

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
Copy link

I have also removed @transactional on the activateAccount method

@bumerrrang
Copy link
Author

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
Copy link

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
Copy link
Author

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
Copy link
Author

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.

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

No branches or pull requests

3 participants