summaryrefslogtreecommitdiff
path: root/app/controllers/app.go
diff options
context:
space:
mode:
authorHorus32015-02-10 14:01:31 +0100
committerHorus32015-02-10 14:01:31 +0100
commit5a5d0fd250c28c3560ff00b9a367938e915eed7f (patch)
tree145fa031631390a93e41a226ba9dc19190ba27b2 /app/controllers/app.go
parentc7869f2326d4e8282697c6961f39f1b19b4c8c94 (diff)
downloadwebmon-5a5d0fd250c28c3560ff00b9a367938e915eed7f.tar.gz
Restructuring and bug fixes.
Diffstat (limited to 'app/controllers/app.go')
-rw-r--r--app/controllers/app.go63
1 files changed, 36 insertions, 27 deletions
diff --git a/app/controllers/app.go b/app/controllers/app.go
index 4aae8aa..fb11d01 100644
--- a/app/controllers/app.go
+++ b/app/controllers/app.go
@@ -1,8 +1,9 @@
package controllers
import (
- "github.com/garyburd/redigo/redis"
+ "github.com/jinzhu/gorm"
"github.com/revel/revel"
+ // "github.com/revel/revel/modules/jobs/app/jobs"
)
type App struct {
@@ -31,7 +32,7 @@ func (c App) Login(email string, legacy bool, user string, password string, pass
// Show login form with username and password
c.Validation.Required(user).Message("Please enter a user name.")
c.Validation.Required(password).Message("Please enter a password.")
- c.Validation.Required(confirm).Message("Please confirm your password.")
+ c.Validation.Required(passwordConfirm).Message("Please confirm your password.")
c.Validation.Required(password == passwordConfirm).Message("The passwords do not match.")
} else {
// Show login form only with email
@@ -48,8 +49,9 @@ func (c App) Login(email string, legacy bool, user string, password string, pass
if legacy {
// do database lookup and show if its matched
db.Where("name = ?", user).First(&u)
- c.Validation.Required(u.confirmed).Message("Your mail adress is not confirmed yet.")
- c.Validation.Required(VerifyPassword(password, u.password)).Message("The user/password combination does not exists.")
+ c.Validation.Required(u.Confirmed).Message("Your mail adress is not confirmed yet.")
+ verify, _ := VerifyPassword(password, u.Password)
+ c.Validation.Required(verify).Message("The user/password combination does not exists.")
if c.Validation.HasErrors() {
c.Validation.Keep()
@@ -58,21 +60,27 @@ func (c App) Login(email string, legacy bool, user string, password string, pass
}
c.Session["login"] = "true"
- c.Session["uid"] = u.id
+ c.Session["uid"] = string(u.Id)
return c.Redirect(App.Account)
} else {
- db.Where("email = ?", email).First(&u)
+ if db.Where("email = ?", email).First(&u).Error == gorm.RecordNotFound {
+ // Invalid Email
+ c.Flash.Error("No valid mail adress.")
+ return c.Redirect(App.PrintLogin)
+ }
// Get random string
key := RandomKey()
// Set key in redis
conn := pool.Get()
defer conn.Close()
- _, err := conn.Do("SET", key, u.email, 86400)
+ _, _ = conn.Do("SET", key, u.Email, 86400)
// Send email with confirmation link
- mailers.SendConfirmationKey(email, key)
+ //jobs.Now(Mailer{}.SendConfirmationKey(email, key))
+ _ = Mailer{}.SendConfirmationKey(email, key)
+
+ c.Flash.Success("A mail with a confirmation link was sent. Follow the instructions there.")
- // TODO Print message that a mail was sent
return c.Redirect(App.PrintLogin)
}
}
@@ -98,17 +106,17 @@ func (c App) Confirm(key, registration string) revel.Result {
}
u := User{}
- db.Where("email = ?", email).First(&u)
+ db.Where("email = ?", confirmKey).First(&u)
- if u.confirmed == false {
+ if u.Confirmed == false {
// E-Mail is now confirmed
- u.confirmed = true
- u.confirmationkey = nil
+ u.Confirmed = true
+ u.ConfirmationKey = ""
db.Save(&u)
}
c.Session["login"] = "true"
- c.Session["uid"] = u.id
+ c.Session["uid"] = string(u.Id)
} else {
// Processing registration confirmation
@@ -118,7 +126,7 @@ func (c App) Confirm(key, registration string) revel.Result {
u := User{}
db.Where("confirmationkey = ?").First(&u)
- c.Validation.Required(registration == u.confirmationkey).Message("Key does not seem to be valid.")
+ c.Validation.Required(registration == u.ConfirmationKey).Message("Key does not seem to be valid.")
if c.Validation.HasErrors() {
c.Validation.Keep()
@@ -126,12 +134,12 @@ func (c App) Confirm(key, registration string) revel.Result {
return c.Redirect(App.PrintLogin)
}
- u.confirmed = true
- u.confirmationkey = nil
+ u.Confirmed = true
+ u.ConfirmationKey = ""
db.Save(&u)
c.Session["login"] = "true"
- c.Session["uid"] = u.id
+ c.Session["uid"] = string(u.Id)
}
@@ -140,12 +148,12 @@ func (c App) Confirm(key, registration string) revel.Result {
func (c App) Register(email, confirmEmail, user, password, confirmPassword string) revel.Result {
- c.Validation.Required(email).Messagel("Please provide a mail adress.")
- c.Validation.Required(email == confirmEmail).Messagel("The mail adresses do not match.")
- c.Validation.Required(user).Messagel("Please provide a user name.")
+ c.Validation.Required(email).Message("Please provide a mail adress.")
+ c.Validation.Required(email == confirmEmail).Message("The mail adresses do not match.")
+ c.Validation.Required(user).Message("Please provide a user name.")
if password != "" {
- c.Validation.Required(password == confirmPassword).Messagel("Passwords do not match.")
+ c.Validation.Required(password == confirmPassword).Message("Passwords do not match.")
}
if c.Validation.HasErrors() {
@@ -154,7 +162,7 @@ func (c App) Register(email, confirmEmail, user, password, confirmPassword strin
return c.Redirect(App.PrintRegister)
}
- p := HashPassword(password)
+ p, _ := HashPassword(password)
key := RandomKey() // Create key to confirm mail adress
u := User{
Name: user,
@@ -165,12 +173,13 @@ func (c App) Register(email, confirmEmail, user, password, confirmPassword strin
Alerts: []Alert{{Email: email}},
}
- db.NewRecord(user)
- db.Create(&user)
- db.Save(&user)
+ db.NewRecord(u)
+ db.Create(&u)
+ db.Save(&u)
// Send email with confirmation link
- mailers.ConfirmRegistration(email, key)
+ //jobs.Now(Mailer{}.ConfirmRegistration(email, key))
+ _ = Mailer{}.ConfirmRegistration(user, email, key)
c.Flash.Success("A mail with a confirmation link was sent. Please confirm your mail adress now.")
return c.Redirect(App.PrintRegister)