This commit is contained in:
lbenedar
2026-03-20 15:27:25 +03:00
parent 0eaad4ed13
commit 1f3874b703
2 changed files with 25 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"errors"
"net/http"
"time"
"gitea.local.lab/Lbenedar/greenlight/internal/data"
"gitea.local.lab/Lbenedar/greenlight/internal/validator"
@@ -52,8 +53,18 @@ func (app *application) registerUserHandler(w http.ResponseWriter, r *http.Reque
return
}
token, err := app.models.Tokens.New(user.ID, 3*24*time.Hour, data.ScopeActivation)
if err != nil {
app.serverErrorResponse(w, r, err)
return
}
app.background(func() {
err = app.mailer.Send(user.Email, "user_welcome.tmpl", user)
data := map[string]any{
"activationToken": token.Plaintext,
"userID": user.ID,
}
err = app.mailer.Send(user.Email, "user_welcome.tmpl", data)
if err != nil {
app.logger.PrintError(err, nil)
}

View File

@@ -7,6 +7,13 @@ Thanks for signing up for a Greenlight account. We're excited to have you on boa
For future reference, your user ID number is {{.ID}}.
Please send a request to the `PUT /v1/users/activated` endpoint with the following JSON
body to activate your account:
{"token": "{{.activationToken}}"}
Please note that this is a one-time use token and it will expire in 3 days.
Thanks,
The Greenlight Team
@@ -26,6 +33,12 @@ The Greenlight Team
<p>Hi,</p>
<p>Thanks for signing up for a Greenlight account. We're excited to have you on board!</p>
<p>For future reference, your user ID number is {{.ID}}.</p>
<p>Please send a request to the <code>PUT /v1/users/activated</code> endpoint with the
following JSON body to activate your account:</p>
<pre><code>
{"token": "{{.activationToken}}"}
</code></pre>
<p>Please note that this is a one-time use token and it will expire in 3 days.</p>
<p>Thanks,</p>
<p>The Greenlight Team</p>
</body>