Creating the reset password route and handler
This commit is contained in:
parent
7db64eff6a
commit
2a5841d649
@ -1,8 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"myapp/internal/cards"
|
"myapp/internal/cards"
|
||||||
"myapp/internal/models"
|
"myapp/internal/models"
|
||||||
|
"myapp/internal/urlsigner"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@ -324,3 +326,21 @@ func (app *application) ForgotPassword(w http.ResponseWriter, r *http.Request) {
|
|||||||
app.errorLog.Println(err)
|
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)
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
@ -34,6 +34,8 @@ type config struct {
|
|||||||
secret string
|
secret string
|
||||||
key string
|
key string
|
||||||
}
|
}
|
||||||
|
secretkey string
|
||||||
|
frontend string
|
||||||
}
|
}
|
||||||
|
|
||||||
type application struct {
|
type application struct {
|
||||||
@ -83,6 +85,8 @@ func main() {
|
|||||||
"DSN",
|
"DSN",
|
||||||
)
|
)
|
||||||
flag.StringVar(&cfg.api, "api", "http://localhost:4001", "URL to api")
|
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()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ func (app *application) routes() http.Handler {
|
|||||||
mux.Post("/login", app.PostLoginPage)
|
mux.Post("/login", app.PostLoginPage)
|
||||||
mux.Get("/logout", app.Logout)
|
mux.Get("/logout", app.Logout)
|
||||||
mux.Get("/forgot-password", app.ForgotPassword)
|
mux.Get("/forgot-password", app.ForgotPassword)
|
||||||
|
mux.Get("/reset-password", app.ShowResetPassword)
|
||||||
|
|
||||||
fileServer := http.FileServer(http.Dir("./static"))
|
fileServer := http.FileServer(http.Dir("./static"))
|
||||||
mux.Handle("/static/*", http.StripPrefix("/static", fileServer))
|
mux.Handle("/static/*", http.StripPrefix("/static", fileServer))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user