From 2f9fe2cfad83416647beed9c3c9085d686c43b09 Mon Sep 17 00:00:00 2001 From: Horus_Arch Date: Sat, 14 Feb 2015 23:11:57 +0100 Subject: Initial commit. --- .gitignore | 4 + app/controllers/app.go | 20 + app/controllers/db.go | 92 + app/controllers/email.db | Bin 0 -> 6144 bytes app/controllers/init.go | 12 + app/init.go | 38 + app/views/App/Index.html | 13 + app/views/App/Index.html.bak | 23 + app/views/App/Register.html | 50 + app/views/debug.html | 64 + app/views/errors/404.html | 20 + app/views/errors/500.html | 16 + app/views/flash.html | 18 + app/views/footer.html | 19 + app/views/header.html | 19 + app/views/navbar.html | 23 + conf/app.conf | 158 + conf/routes | 28 + messages/sample.en | 7 + public/css/bootstrap.css | 5774 +++++++++++++++++++++++++++++ public/img/favicon.png | Bin 0 -> 5639 bytes public/img/glyphicons-halflings-white.png | Bin 0 -> 8777 bytes public/img/glyphicons-halflings.png | Bin 0 -> 12799 bytes public/js/jquery-1.9.1.min.js | 5 + tests/apptest.go | 21 + 25 files changed, 6424 insertions(+) create mode 100644 .gitignore create mode 100644 app/controllers/app.go create mode 100644 app/controllers/db.go create mode 100644 app/controllers/email.db create mode 100644 app/controllers/init.go create mode 100644 app/init.go create mode 100644 app/views/App/Index.html create mode 100644 app/views/App/Index.html.bak create mode 100644 app/views/App/Register.html create mode 100644 app/views/debug.html create mode 100644 app/views/errors/404.html create mode 100644 app/views/errors/500.html create mode 100644 app/views/flash.html create mode 100644 app/views/footer.html create mode 100644 app/views/header.html create mode 100644 app/views/navbar.html create mode 100644 conf/app.conf create mode 100644 conf/routes create mode 100644 messages/sample.en create mode 100644 public/css/bootstrap.css create mode 100644 public/img/favicon.png create mode 100644 public/img/glyphicons-halflings-white.png create mode 100644 public/img/glyphicons-halflings.png create mode 100644 public/js/jquery-1.9.1.min.js create mode 100644 tests/apptest.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..70a8117 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +test-results/ +tmp/ +routes/ +*.swp diff --git a/app/controllers/app.go b/app/controllers/app.go new file mode 100644 index 0000000..754deee --- /dev/null +++ b/app/controllers/app.go @@ -0,0 +1,20 @@ +package controllers + +import "github.com/revel/revel" + +type App struct { + //*revel.Controller + GormController +} + +func (c App) Index() revel.Result { + return c.Render() +} + +func (c App) Register() revel.Result { + return c.Render() +} + +func (c App) DoRegister() revel.Result { + return c.Render() +} diff --git a/app/controllers/db.go b/app/controllers/db.go new file mode 100644 index 0000000..0f50968 --- /dev/null +++ b/app/controllers/db.go @@ -0,0 +1,92 @@ +package controllers + +import ( + "github.com/jinzhu/gorm" + _ "github.com/mattn/go-sqlite3" + "github.com/revel/revel" + "time" +) + +type User struct { + Id int64 + Name string + Email string + Password string + Domains []Domain + CreatedAt time.Time + UpdatedAt time.Time + DeletedAt time.Time +} + +type Domain struct { + Id int64 + UserId int64 + Domain string + CreatedAt time.Time + UpdatedAt time.Time + DeletedAt time.Time +} + +type GormController struct { + *revel.Controller + Db *gorm.DB +} + +var Gdb gorm.DB + +func InitDB() { + Gdb, err := gorm.Open(revel.Config.StringDefault("db.driver", "sqlite3"), revel.Config.StringDefault("db.spec", "email.db")) + if err != nil { + revel.ERROR.Printf("%s", err) + } + Gdb.LogMode(true) + Gdb.SetLogger(gorm.Logger{revel.TRACE}) + user := User{} + Gdb.AutoMigrate(&user) + Gdb.Model(&user).AddUniqueIndex("idx_user_password", "password") + Gdb.Model(&user).AddUniqueIndex("idx_user_email", "email") + + domain := Domain{} + Gdb.AutoMigrate(&domain) + Gdb.Model(&domain).AddUniqueIndex("idx_domain_name", "domain") +} + +/* +// transactions + +// This method fills the c.Txn before each transaction +func (c *GormController) Begin() revel.Result { + txn := Gdb.Begin() + if txn.Error != nil { + panic(txn.Error) + } + c.Txn = txn + return nil +} + +// This method clears the c.Txn after each transaction +func (c *GormController) Commit() revel.Result { + if c.Txn == nil { + return nil + } + c.Txn.Commit() + if err := c.Txn.Error; err != nil && err != sql.ErrTxDone { + panic(err) + } + c.Txn = nil + return nil +} + +// This method clears the c.Txn after each transaction, too +func (c *GormController) Rollback() revel.Result { + if c.Txn == nil { + return nil + } + c.Txn.Rollback() + if err := c.Txn.Error; err != nil && err != sql.ErrTxDone { + panic(err) + } + c.Txn = nil + return nil +} +*/ diff --git a/app/controllers/email.db b/app/controllers/email.db new file mode 100644 index 0000000..2199268 Binary files /dev/null and b/app/controllers/email.db differ diff --git a/app/controllers/init.go b/app/controllers/init.go new file mode 100644 index 0000000..affa2e0 --- /dev/null +++ b/app/controllers/init.go @@ -0,0 +1,12 @@ +package controllers + +import "github.com/revel/revel" + +func init() { + revel.OnAppStart(InitDB) // invoke InitDB function before + /* + revel.InterceptMethod((*GormController).Begin, revel.BEFORE) + revel.InterceptMethod((*GormController).Commit, revel.AFTER) + revel.InterceptMethod((*GormController).Rollback, revel.FINALLY) + */ +} diff --git a/app/init.go b/app/init.go new file mode 100644 index 0000000..2305d73 --- /dev/null +++ b/app/init.go @@ -0,0 +1,38 @@ +package app + +import "github.com/revel/revel" + +func init() { + // Filters is the default set of global filters. + revel.Filters = []revel.Filter{ + revel.PanicFilter, // Recover from panics and display an error page instead. + revel.RouterFilter, // Use the routing table to select the right Action + revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters. + revel.ParamsFilter, // Parse parameters into Controller.Params. + revel.SessionFilter, // Restore and write the session cookie. + revel.FlashFilter, // Restore and write the flash cookie. + revel.ValidationFilter, // Restore kept validation errors and save new ones from cookie. + revel.I18nFilter, // Resolve the requested language + HeaderFilter, // Add some security based headers + revel.InterceptorFilter, // Run interceptors around the action. + revel.CompressFilter, // Compress the result. + revel.ActionInvoker, // Invoke the action. + } + + // register startup functions with OnAppStart + // ( order dependent ) + // revel.OnAppStart(InitDB) + // revel.OnAppStart(FillCache) +} + +// TODO turn this into revel.HeaderFilter +// should probably also have a filter for CSRF +// not sure if it can go in the same filter or not +var HeaderFilter = func(c *revel.Controller, fc []revel.Filter) { + // Add some common security headers + c.Response.Out.Header().Add("X-Frame-Options", "SAMEORIGIN") + c.Response.Out.Header().Add("X-XSS-Protection", "1; mode=block") + c.Response.Out.Header().Add("X-Content-Type-Options", "nosniff") + + fc[0](c, fc[1:]) // Execute the next filter stage. +} diff --git a/app/views/App/Index.html b/app/views/App/Index.html new file mode 100644 index 0000000..cf36a51 --- /dev/null +++ b/app/views/App/Index.html @@ -0,0 +1,13 @@ +{{set . "title" "Home"}} +{{template "header.html" .}} +{{template "navbar.html" .}} + +
+ {{.Description}} +
+ {{end}} +{{end}} + + diff --git a/app/views/errors/500.html b/app/views/errors/500.html new file mode 100644 index 0000000..0cef4de --- /dev/null +++ b/app/views/errors/500.html @@ -0,0 +1,16 @@ + + + ++ This exception has been logged. +
+ {{end}} + + diff --git a/app/views/flash.html b/app/views/flash.html new file mode 100644 index 0000000..9c9ade9 --- /dev/null +++ b/app/views/flash.html @@ -0,0 +1,18 @@ +{{if .flash.success}} +