From fb42c216818e05af7fce1f41908bdb969ba43903 Mon Sep 17 00:00:00 2001 From: jan Date: Wed, 2 Nov 2016 15:15:53 +0100 Subject: fette checks bei registration diff --git a/charakterin.go b/charakterin.go index 64af53a..b1500f0 100644 --- a/charakterin.go +++ b/charakterin.go @@ -8,6 +8,7 @@ import ( "net/http" "net/url" "time" + "regexp" _ "github.com/lib/pq" ) @@ -36,6 +37,8 @@ type Charakterin struct { Database *sql.DB } +var reEmail, _ = regexp.Compile(`(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,})`) + // New erstellt eine neue Instanz von Charakterin. func New(db *sql.DB) *Charakterin { if err := db.Ping(); err != nil { @@ -301,6 +304,30 @@ func (c *Charakterin) Register(w http.ResponseWriter, r *http.Request) { username := values.Get("username") password := values.Get("password") email := values.Get("email") + + if len(username) < 3 { + data := make(map[string]interface{}) + data["error"] = "Username zu kurz, du Hurensohn" + data["previous_email"] = email + c.DisplayRegistrationWithData(w, r, data) + return + } + if len(password) < 3 { + data := make(map[string]interface{}) + data["error"] = "Passwort zu kurz, du Hurensohn" + data["previous_user"] = username + c.DisplayRegistrationWithData(w, r, data) + return + } + if len(email) < 3 || !reEmail.MatchString(email) { + data := make(map[string]interface{}) + data["error"] = "Fick deine Email" + data["previous_email"] = email + data["previous_user"] = username + c.DisplayRegistrationWithData(w, r, data) + return + } + var result string err = c.Database.QueryRow("SELECT * FROM login.register_user($1, $2, $3)", username, password, email).Scan(&result) if err != nil { @@ -310,13 +337,13 @@ func (c *Charakterin) Register(w http.ResponseWriter, r *http.Request) { data := make(map[string]interface{}) data["error"] = "Der Benutzername wird bereits verwendet." data["previous_email"] = email - c.DisplayLoginWithData(w, r, data) + c.DisplayRegistrationWithData(w, r, data) return } else if errStr == EmailAlreadyRegistered { data := make(map[string]interface{}) data["error"] = "Diese E-Mail wird bereits verwendet." data["previous_user"] = username - c.DisplayLoginWithData(w, r, data) + c.DisplayRegistrationWithData(w, r, data) return } -- cgit v0.10.1