From 26f781239bfcda867f19262becee3b9687a7c79d Mon Sep 17 00:00:00 2001 From: Horus_Arch Date: Sun, 15 Feb 2015 17:59:13 +0100 Subject: Crashs on startup with error message 'Cannot start transaction.' --- app/controllers/app.go | 51 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'app/controllers/app.go') diff --git a/app/controllers/app.go b/app/controllers/app.go index 754deee..2b8945c 100644 --- a/app/controllers/app.go +++ b/app/controllers/app.go @@ -1,6 +1,10 @@ package controllers -import "github.com/revel/revel" +import ( + _ "github.com/jinzhu/gorm" + _ "github.com/mattn/go-sqlite3" + "github.com/revel/revel" +) type App struct { //*revel.Controller @@ -11,10 +15,49 @@ func (c App) Index() revel.Result { return c.Render() } -func (c App) Register() revel.Result { - return c.Render() +func (c App) DoRegister(name, email, confirmEmail, password, confirmPassword string) revel.Result { + c.Validation.Required(name).Message("Please provide a user name.") + c.Validation.Required(email).Message("Please provide a mail adress.") + c.Validation.Required(email == confirmEmail).Message("Mail adresses do not match.") + c.Validation.Required(password).Message("Please provide a password.") + c.Validation.Required(password == confirmPassword).Message("Passwords do not match.") + + if c.Validation.HasErrors() { + c.Validation.Keep() + c.FlashParams() + return c.Redirect(App.Register) + } + + hash := HashPassword(password) + revel.INFO.Printf("%s \n", hash) + user := User{Name: name, Email: email, Password: hash} + + //c.Validation.Required(c.Db.NewRecord(user)).Message("User name already used.") + /* + if !c.Db.NewRecord(user) { + revel.ERROR.Println("User name already in use.") + } + */ + + revel.INFO.Printf("%s", c.Gdb) + c.Gdb.Debug().NewRecord(user) + c.Gdb.Debug().Save(&user) + //c.Db.Debug().NewRecord(user) + //c.Db.Debug().Save(&user) + //c.Db.Create(&user) + + /* + if c.Validation.HasErrors() { + c.Validation.Keep() + c.FlashParams() + return c.Redirect(App.Register) + } + */ + + //return c.Render() + return c.Redirect(App.Register) } -func (c App) DoRegister() revel.Result { +func (c App) Register() revel.Result { return c.Render() } -- cgit v1.2.3