ch15.3
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gitea.local.lab/Lbenedar/greenlight/internal/data"
|
"gitea.local.lab/Lbenedar/greenlight/internal/data"
|
||||||
"gitea.local.lab/Lbenedar/greenlight/internal/validator"
|
"gitea.local.lab/Lbenedar/greenlight/internal/validator"
|
||||||
@@ -52,8 +53,18 @@ func (app *application) registerUserHandler(w http.ResponseWriter, r *http.Reque
|
|||||||
return
|
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() {
|
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 {
|
if err != nil {
|
||||||
app.logger.PrintError(err, nil)
|
app.logger.PrintError(err, nil)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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}}.
|
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,
|
Thanks,
|
||||||
|
|
||||||
The Greenlight Team
|
The Greenlight Team
|
||||||
@@ -26,6 +33,12 @@ The Greenlight Team
|
|||||||
<p>Hi,</p>
|
<p>Hi,</p>
|
||||||
<p>Thanks for signing up for a Greenlight account. We're excited to have you on board!</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>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>Thanks,</p>
|
||||||
<p>The Greenlight Team</p>
|
<p>The Greenlight Team</p>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user