Add backend hook to register users

This commit is contained in:
Amarpreet Minhas 2020-01-21 22:06:03 -05:00
parent d27a499c07
commit aa2731e789

View file

@ -97,8 +97,23 @@ func Routes() *chi.Mux {
} }
func verify(w http.ResponseWriter, r *http.Request) { func verify(w http.ResponseWriter, r *http.Request) {
token := chi.URLParam(r, "token") returnMessage := ReturnMessage{}
fmt.Println(token) _, claims, _ := jwtauth.FromContext(r.Context())
sqlStatement := `
UPDATE users
SET verified = $1
WHERE username = $2;`
_, err := DB.Exec(sqlStatement, true, claims["username"])
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
returnMessage.Message = "unexpected error verifying account. please contact the administrator"
render.JSON(w, r, returnMessage)
return
}
w.WriteHeader(http.StatusOK)
returnMessage.Message = "your email has been verified!"
render.JSON(w, r, returnMessage)
return
} }
func register(w http.ResponseWriter, r *http.Request) { func register(w http.ResponseWriter, r *http.Request) {