D
D
Dos2020-02-23 23:23:42
symfony
Dos, 2020-02-23 23:23:42

What is the best way to insert a link in an email?

Hey! I'm making an API. There is a standard registration functionality:
1. Registration request
2. Registration confirmation

I send letters through the SignUpConfirmTokenSender service .

public function send(Email $email, string $token): void
    {
        $message = (new Swift_Message($this->translator->trans('Sig Up Confirmation', [], 'mail')))
            ->setTo($email->getValue())
            ->setBody($this->twig->render('mail/user/signup.html.twig', ['token' => $token]), 'text/html');

        if (!$this->mailer->send($message)) {
            throw new RuntimeException($this->translator->trans('Unable to send message.', [], 'error'));
        }
    }


And the template itself
{% extends 'mail.html.twig' %}

{% block body %}
    <p>Password Reset Link:</p>
    {% set url = url('auth.reset.reset', {'token': token}) %}
    <p><a href="{{ url }}">{{ url }}</a></p>
{% endblock %}


The difficulty arose when changing this link in the letter. It would be possible to leave it as it is now, but this link leads to the API. The response of which will not be a beautiful window with a confirmation notification, but a json string. So what is the best way to insert this link now?

1. Immediately in the letter
2. Transfer to the parameter configs
3. Transfer in the controller and then to the service.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2020-02-24
@HistoryART

Generate a link on the server, let's say the user's id in bcrypt format cut in half, and immediately enter this code into the database, and the link status can be a separate field, or separated by a colon.
dsf23$fd:false/true
Next, create a page to which your link will lead, pass the same encrypted id to the url parameters, if everything is ok, display the confirm button, all sorts of goodies like a smiley and a greeting - if the link is already true, let's say, display your account is already activated, run away from here. as a result, the link should be like this:
my-app.com/dsf23$fd
Then the script takes the link from the url, divides the string into an array by : and as a result you have an array of two elements for the corresponding checks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question