aboutsummaryrefslogtreecommitdiff
path: root/charakterin.go
diff options
context:
space:
mode:
Diffstat (limited to 'charakterin.go')
-rw-r--r--charakterin.go31
1 files changed, 29 insertions, 2 deletions
diff --git a/charakterin.go b/charakterin.go
index 64af53a..b1500f0 100644
--- a/charakterin.go
+++ b/charakterin.go
@@ -8,6 +8,7 @@ import (
8 "net/http" 8 "net/http"
9 "net/url" 9 "net/url"
10 "time" 10 "time"
11 "regexp"
11 12
12 _ "github.com/lib/pq" 13 _ "github.com/lib/pq"
13) 14)
@@ -36,6 +37,8 @@ type Charakterin struct {
36 Database *sql.DB 37 Database *sql.DB
37} 38}
38 39
40var reEmail, _ = regexp.Compile(`(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,})`)
41
39// New erstellt eine neue Instanz von Charakterin. 42// New erstellt eine neue Instanz von Charakterin.
40func New(db *sql.DB) *Charakterin { 43func New(db *sql.DB) *Charakterin {
41 if err := db.Ping(); err != nil { 44 if err := db.Ping(); err != nil {
@@ -301,6 +304,30 @@ func (c *Charakterin) Register(w http.ResponseWriter, r *http.Request) {
301 username := values.Get("username") 304 username := values.Get("username")
302 password := values.Get("password") 305 password := values.Get("password")
303 email := values.Get("email") 306 email := values.Get("email")
307
308 if len(username) < 3 {
309 data := make(map[string]interface{})
310 data["error"] = "Username zu kurz, du Hurensohn"
311 data["previous_email"] = email
312 c.DisplayRegistrationWithData(w, r, data)
313 return
314 }
315 if len(password) < 3 {
316 data := make(map[string]interface{})
317 data["error"] = "Passwort zu kurz, du Hurensohn"
318 data["previous_user"] = username
319 c.DisplayRegistrationWithData(w, r, data)
320 return
321 }
322 if len(email) < 3 || !reEmail.MatchString(email) {
323 data := make(map[string]interface{})
324 data["error"] = "Fick deine Email"
325 data["previous_email"] = email
326 data["previous_user"] = username
327 c.DisplayRegistrationWithData(w, r, data)
328 return
329 }
330
304 var result string 331 var result string
305 err = c.Database.QueryRow("SELECT * FROM login.register_user($1, $2, $3)", username, password, email).Scan(&result) 332 err = c.Database.QueryRow("SELECT * FROM login.register_user($1, $2, $3)", username, password, email).Scan(&result)
306 if err != nil { 333 if err != nil {
@@ -310,13 +337,13 @@ func (c *Charakterin) Register(w http.ResponseWriter, r *http.Request) {
310 data := make(map[string]interface{}) 337 data := make(map[string]interface{})
311 data["error"] = "Der Benutzername wird bereits verwendet." 338 data["error"] = "Der Benutzername wird bereits verwendet."
312 data["previous_email"] = email 339 data["previous_email"] = email
313 c.DisplayLoginWithData(w, r, data) 340 c.DisplayRegistrationWithData(w, r, data)
314 return 341 return
315 } else if errStr == EmailAlreadyRegistered { 342 } else if errStr == EmailAlreadyRegistered {
316 data := make(map[string]interface{}) 343 data := make(map[string]interface{})
317 data["error"] = "Diese E-Mail wird bereits verwendet." 344 data["error"] = "Diese E-Mail wird bereits verwendet."
318 data["previous_user"] = username 345 data["previous_user"] = username
319 c.DisplayLoginWithData(w, r, data) 346 c.DisplayRegistrationWithData(w, r, data)
320 return 347 return
321 } 348 }
322 349