func (c Application) SaveUser(user models.User, verifyPassword string) rev.Result { c.Validation.Required(verifyPassword) c.Validation.Required(verifyPassword == user.Password). Message("Password does not match") user.Validate(c.Validation) if c.Validation.HasErrors() { c.Validation.Keep() c.FlashParams() return c.Redirect(Application.Register) } bcryptPassword, _ := bcrypt.GenerateFromPassword( []byte(user.Password), bcrypt.DefaultCost) _, err := c.Txn.Exec( "insert into User (Username, HashedPassword, Name) values (?, ?, ?)", user.Username, bcryptPassword, user.Name) if err != nil { panic(err) } c.Session["user"] = user.Username c.Flash.Success("Welcome, " + user.Name) return c.Redirect(Hotels.Index) }
func (c Application) SaveUser(user models.User, verifyPassword string) revel.Result { c.Validation.Required(verifyPassword) c.Validation.Required(verifyPassword == user.Password). Message("Password does not match") user.Validate(c.Validation) if c.Validation.HasErrors() { c.Validation.Keep() c.FlashParams() return c.Redirect(routes.Application.Register()) } user.HashedPassword, _ = bcrypt.GenerateFromPassword( []byte(user.Password), bcrypt.DefaultCost) err := c.Txn.Insert(&user) if err != nil { panic(err) } c.Session["user"] = user.Username c.Flash.Success("Welcome, " + user.Name) return c.Redirect(routes.Hotels.Index()) }