diff options
| author | Horus_Arch | 2015-02-10 10:10:22 +0100 |
|---|---|---|
| committer | Horus_Arch | 2015-02-10 10:10:22 +0100 |
| commit | c7869f2326d4e8282697c6961f39f1b19b4c8c94 (patch) | |
| tree | c4ac577605c894ac6e0baa8660f740823f609790 /app/controllers/app.go | |
| parent | 8c30749613bcf1ce47fff0a6d1a60c34f91f01c4 (diff) | |
| download | webmon-c7869f2326d4e8282697c6961f39f1b19b4c8c94.tar.gz | |
Mailer views.
Diffstat (limited to 'app/controllers/app.go')
| -rw-r--r-- | app/controllers/app.go | 95 |
1 files changed, 58 insertions, 37 deletions
diff --git a/app/controllers/app.go b/app/controllers/app.go index 4aad9a3..4aae8aa 100644 --- a/app/controllers/app.go +++ b/app/controllers/app.go @@ -70,42 +70,70 @@ func (c App) Login(email string, legacy bool, user string, password string, pass defer conn.Close() _, err := conn.Do("SET", key, u.email, 86400) // Send email with confirmation link - // TODO Implementing the function - SendConfirmationKey(email, key) + mailers.SendConfirmationKey(email, key) // TODO Print message that a mail was sent return c.Redirect(App.PrintLogin) } } -func (c App) Confirm(key string) revel.Result { +func (c App) Confirm(key, registration string) revel.Result { - c.Validation.Required(key).Message("No key provided.") + if registration == "" { + // Processing login - conn := pool.Get() - confirmKey, err := conn.Do("GET", key) - c.Validation.Required(err == nil).Message("Oops, there is currently an internal problem. Please check later again.") - c.Validation.Required(confirmKey).Message("Key does not seem to be valid.") + c.Validation.Required(key).Message("No key provided.") - _, _ = conn.Do("DEL", key) + conn := pool.Get() + confirmKey, err := conn.Do("GET", key) + c.Validation.Required(err == nil).Message("Oops, there is currently an internal problem. Please check later again.") + c.Validation.Required(confirmKey).Message("Key does not seem to be valid.") - if c.Validation.HasErrors() { - c.Validation.Keep() - c.FlashParams() - return c.Redirect(App.PrintLogin) - } + _, _ = conn.Do("DEL", key) - u := User{} - db.Where("email = ?", email).First(&u) + if c.Validation.HasErrors() { + c.Validation.Keep() + c.FlashParams() + return c.Redirect(App.PrintLogin) + } + + u := User{} + db.Where("email = ?", email).First(&u) + + if u.confirmed == false { + // E-Mail is now confirmed + u.confirmed = true + u.confirmationkey = nil + db.Save(&u) + } + + c.Session["login"] = "true" + c.Session["uid"] = u.id + + } else { + // Processing registration confirmation + + c.Validation.Required(registration).Message("No confirmation key provided.") + + u := User{} + db.Where("confirmationkey = ?").First(&u) + + c.Validation.Required(registration == u.confirmationkey).Message("Key does not seem to be valid.") + + if c.Validation.HasErrors() { + c.Validation.Keep() + c.FlashParams() + return c.Redirect(App.PrintLogin) + } - if u.confirmed == false { - // E-Mail is now confirmed u.confirmed = true + u.confirmationkey = nil db.Save(&u) - } - c.Session["login"] = "true" - c.Session["uid"] = u.id + c.Session["login"] = "true" + c.Session["uid"] = u.id + + } return c.Redirect(App.Account) } @@ -127,30 +155,23 @@ func (c App) Register(email, confirmEmail, user, password, confirmPassword strin } p := HashPassword(password) + key := RandomKey() // Create key to confirm mail adress u := User{ - Name: user, - Email: email, - Password: p, - Confirmed: false, - Alerts: []Alert{{Email: email}}, + Name: user, + Email: email, + Password: p, + Confirmed: false, + ConfirmationKey: key, + Alerts: []Alert{{Email: email}}, } db.NewRecord(user) db.Create(&user) db.Save(&user) - // Create key to confirm mail adress - key := RandomKey() - - // Redis - conn := pool.Get() - defer conn.Close() - _, err := conn.Do("SET", key, email) - // Send email with confirmation link - // TODO Implementing the function - SendConfirmationKey(email, key) + mailers.ConfirmRegistration(email, key) c.Flash.Success("A mail with a confirmation link was sent. Please confirm your mail adress now.") - return c.Redirect(App.PrintLogin) + return c.Redirect(App.PrintRegister) } |
