validate email on register/forgot
Fixes #21. Change-Id: I21bfd87d6fd730e8a90ceec77c9b23a90bc397e9
This commit is contained in:
parent
cce3166bdd
commit
adcc05ea3a
19
server.go
19
server.go
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/mail"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
verrors "mcquay.me/vain/errors"
|
verrors "mcquay.me/vain/errors"
|
||||||
@ -125,7 +126,14 @@ func (s *Server) register(w http.ResponseWriter, req *http.Request) {
|
|||||||
http.Error(w, "must provide one email parameter", http.StatusBadRequest)
|
http.Error(w, "must provide one email parameter", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tok, err := s.db.Register(email[0])
|
|
||||||
|
addr := email[0]
|
||||||
|
if _, err := mail.ParseAddress(addr); err != nil {
|
||||||
|
http.Error(w, fmt.Sprintf("invalid email detected: %v", err), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tok, err := s.db.Register(addr)
|
||||||
if err := verrors.ToHTTP(err); err != nil {
|
if err := verrors.ToHTTP(err); err != nil {
|
||||||
http.Error(w, err.Message, err.Code)
|
http.Error(w, err.Message, err.Code)
|
||||||
return
|
return
|
||||||
@ -160,7 +168,14 @@ func (s *Server) forgot(w http.ResponseWriter, req *http.Request) {
|
|||||||
http.Error(w, "must provide one email parameter", http.StatusBadRequest)
|
http.Error(w, "must provide one email parameter", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tok, err := s.db.forgot(email[0])
|
|
||||||
|
addr := email[0]
|
||||||
|
if _, err := mail.ParseAddress(addr); err != nil {
|
||||||
|
http.Error(w, fmt.Sprintf("invalid email detected: %v", err), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tok, err := s.db.forgot(addr)
|
||||||
if err := verrors.ToHTTP(err); err != nil {
|
if err := verrors.ToHTTP(err); err != nil {
|
||||||
http.Error(w, err.Message, err.Code)
|
http.Error(w, err.Message, err.Code)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user