Creating the reset password route and handler

This commit is contained in:
vinchent 2024-08-21 12:17:49 +02:00
parent 7db64eff6a
commit 2a5841d649
3 changed files with 25 additions and 0 deletions

View File

@ -1,8 +1,10 @@
package main
import (
"fmt"
"myapp/internal/cards"
"myapp/internal/models"
"myapp/internal/urlsigner"
"net/http"
"strconv"
@ -324,3 +326,21 @@ func (app *application) ForgotPassword(w http.ResponseWriter, r *http.Request) {
app.errorLog.Println(err)
}
}
func (app *application) ShowResetPassword(w http.ResponseWriter, r *http.Request) {
theURL := r.RequestURI
testURL := fmt.Sprintf("%s%s", app.config.frontend, theURL)
signer := urlsigner.Signer{
Secret: []byte(app.config.secretkey),
}
valid := signer.VerifyToken(testURL)
if valid {
w.Write([]byte("valid"))
} else {
w.Write([]byte("invalid"))
}
// if err := app.renderTemplate(w, r, "reset-password", &templateData{}); err != nil {
// app.errorLog.Println(err)
// }
}

View File

@ -34,6 +34,8 @@ type config struct {
secret string
key string
}
secretkey string
frontend string
}
type application struct {
@ -83,6 +85,8 @@ func main() {
"DSN",
)
flag.StringVar(&cfg.api, "api", "http://localhost:4001", "URL to api")
flag.StringVar(&cfg.secretkey, "secret", "secRetKeY", "secret key")
flag.StringVar(&cfg.frontend, "frontend", "http://localhost:4000", "frontend address")
flag.Parse()

View File

@ -32,6 +32,7 @@ func (app *application) routes() http.Handler {
mux.Post("/login", app.PostLoginPage)
mux.Get("/logout", app.Logout)
mux.Get("/forgot-password", app.ForgotPassword)
mux.Get("/reset-password", app.ShowResetPassword)
fileServer := http.FileServer(http.Dir("./static"))
mux.Handle("/static/*", http.StripPrefix("/static", fileServer))