summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorHorus_Arch2015-02-15 17:59:13 +0100
committerHorus_Arch2015-02-15 17:59:13 +0100
commit26f781239bfcda867f19262becee3b9687a7c79d (patch)
tree04a439594815ce1b37a1a73303eee4ac7a5be487 /app
parenta69bf1307d20a395b0eca9ffae06f57a659dabf1 (diff)
downloadfreemail-26f781239bfcda867f19262becee3b9687a7c79d.tar.gz
Crashs on startup with error message 'Cannot start transaction.'
Diffstat (limited to 'app')
-rw-r--r--app/controllers/app.go51
-rw-r--r--app/controllers/db.go98
-rw-r--r--app/controllers/email.dbbin6144 -> 10240 bytes
-rw-r--r--app/controllers/init.go8
-rw-r--r--app/views/App/DomainRegister.html50
-rw-r--r--app/views/App/Register.html34
6 files changed, 203 insertions, 38 deletions
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()
}
diff --git a/app/controllers/db.go b/app/controllers/db.go
index 0f50968..5b7dd97 100644
--- a/app/controllers/db.go
+++ b/app/controllers/db.go
@@ -2,22 +2,25 @@ package controllers
import (
"github.com/jinzhu/gorm"
- _ "github.com/mattn/go-sqlite3"
+ // _ "github.com/mattn/go-sqlite3"
+ "database/sql"
"github.com/revel/revel"
"time"
)
+// Website user
type User struct {
- Id int64
- Name string
- Email string
- Password string
- Domains []Domain
+ 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
@@ -26,67 +29,110 @@ type Domain struct {
UpdatedAt time.Time
DeletedAt time.Time
}
+*/
+
+// Domains for which we do E-Mail hosting
+type VirtualDomain struct {
+ Id int64
+ User User
+ UserId int64
+ Name string
+}
+
+// User for postfix
+type VirtualUser struct {
+ Id int64
+ UserId int64
+ VirtualDomain VirtualDomain
+ VirtualDomainId int64
+ Password string
+ Email string
+}
+
+// E-Mail aliase for postfix
+type VirtualAliase struct {
+ Id int64
+ VirtualDomain VirtualDomain
+ VirtualDomainId int64
+ Source string
+ Destination string
+}
type GormController struct {
*revel.Controller
- Db *gorm.DB
+ Gdb *gorm.DB
}
var Gdb gorm.DB
func InitDB() {
+ // db.Init()
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_name", "name")
Gdb.Model(&user).AddUniqueIndex("idx_user_email", "email")
- domain := Domain{}
- Gdb.AutoMigrate(&domain)
- Gdb.Model(&domain).AddUniqueIndex("idx_domain_name", "domain")
+ /*
+ domain := Domain{}
+ Gdb.AutoMigrate(&domain)
+ Gdb.Model(&domain).AddUniqueIndex("idx_domain_name", "domain")
+ */
+
+ vu := VirtualUser{}
+ Gdb.AutoMigrate(&vu)
+ Gdb.Model(&vu).AddUniqueIndex("idx_virtual_user_email", "email")
+ Gdb.Debug().Model(&vu).Related(&user)
+ Gdb.Debug().Model(&user).Related(&vu)
+
+ vd := VirtualDomain{}
+ Gdb.AutoMigrate(&vd)
+
+ va := VirtualAliase{}
+ Gdb.AutoMigrate(&va)
}
-/*
// transactions
-// This method fills the c.Txn before each transaction
+// This method fills the c.Gdb before each transaction
func (c *GormController) Begin() revel.Result {
txn := Gdb.Begin()
if txn.Error != nil {
- panic(txn.Error)
+ //panic(txn.Error)
+ revel.ERROR.Printf("%s \n", txn.Error)
}
- c.Txn = txn
+ c.Gdb = txn
return nil
}
-// This method clears the c.Txn after each transaction
+// This method clears the c.Gdb after each transaction
func (c *GormController) Commit() revel.Result {
- if c.Txn == nil {
+ if c.Gdb == nil {
return nil
}
- c.Txn.Commit()
- if err := c.Txn.Error; err != nil && err != sql.ErrTxDone {
+ c.Gdb.Commit()
+ if err := c.Gdb.Error; err != nil && err != sql.ErrTxDone {
panic(err)
}
- c.Txn = nil
+ c.Gdb = nil
return nil
}
-// This method clears the c.Txn after each transaction, too
+// This method clears the c.Gdb after each transaction, too
func (c *GormController) Rollback() revel.Result {
- if c.Txn == nil {
+ if c.Gdb == nil {
return nil
}
- c.Txn.Rollback()
- if err := c.Txn.Error; err != nil && err != sql.ErrTxDone {
+ c.Gdb.Rollback()
+ if err := c.Gdb.Error; err != nil && err != sql.ErrTxDone {
panic(err)
}
- c.Txn = nil
+ c.Gdb = nil
return nil
}
-*/
diff --git a/app/controllers/email.db b/app/controllers/email.db
index 2199268..4a4cefc 100644
--- a/app/controllers/email.db
+++ b/app/controllers/email.db
Binary files differ
diff --git a/app/controllers/init.go b/app/controllers/init.go
index affa2e0..a5c9096 100644
--- a/app/controllers/init.go
+++ b/app/controllers/init.go
@@ -4,9 +4,7 @@ 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)
- */
+ revel.InterceptMethod((*GormController).Begin, revel.BEFORE)
+ revel.InterceptMethod((*GormController).Commit, revel.AFTER)
+ revel.InterceptMethod((*GormController).Rollback, revel.FINALLY)
}
diff --git a/app/views/App/DomainRegister.html b/app/views/App/DomainRegister.html
new file mode 100644
index 0000000..9c8683c
--- /dev/null
+++ b/app/views/App/DomainRegister.html
@@ -0,0 +1,50 @@
+{{set . "title" "Register"}}
+{{template "header.html" .}}
+{{template "navbar.html" .}}
+
+ <div>
+ <div class="noscript">
+ <div class="container">
+ <div class="row text-center noscript">
+ <noscript>
+ <!--h5>Please enable JavaScript. This page will not work otherwise.</h5-->
+ </noscript>
+ <h5>Please note: We haven't started yet! This is just a demo page.</h4>
+ </div>
+ </div>
+ </div>
+ </div>
+
+
+ <div class="container">
+ <div class="text-center">
+ <div class="row">
+ <form class="form-horizontal" method='POST' action='./'>
+ <fieldset>
+ <legend>
+ <h1>Mail Exchange</h1>
+ <p>Free E-Mail hosting for your own domain. <br>Reqister yourself below and point your MX entry to "mx.iamfabulous.de"</p>
+ </legend>
+
+ <div class="form-group">
+ <label class="col-md-4 control-label" for="domain">Domain*</label>
+ <div class="col-md-4">
+ <input id="domain" name="domain" placeholder="Your domain here." class="form-control input-md" required="" type="text">
+ </div>
+ </div>
+
+ <div class="form-group">
+ <label class="col-md-4 control-label" for="submit"></label>
+ <div class="col-md-4">
+ <button id="submit" name="submit" class="btn btn-primary"><span class="glyphicon glyphicon-log-in"></span> Register</button>
+ </div>
+ </div>
+
+
+ </fieldset>
+ </form>
+ </div>
+ </div>
+ </div>
+
+{{template "footer.html" .}}
diff --git a/app/views/App/Register.html b/app/views/App/Register.html
index 9c8683c..e950804 100644
--- a/app/views/App/Register.html
+++ b/app/views/App/Register.html
@@ -19,7 +19,7 @@
<div class="container">
<div class="text-center">
<div class="row">
- <form class="form-horizontal" method='POST' action='./'>
+ <form class="form-horizontal" method='POST' action='/register'>
<fieldset>
<legend>
<h1>Mail Exchange</h1>
@@ -27,9 +27,37 @@
</legend>
<div class="form-group">
- <label class="col-md-4 control-label" for="domain">Domain*</label>
+ <label class="col-md-4 control-label" for="name">Name*</label>
<div class="col-md-4">
- <input id="domain" name="domain" placeholder="Your domain here." class="form-control input-md" required="" type="text">
+ <input id="name" name="name" placeholder="Your name here." class="form-control input-md" required="" type="text">
+ </div>
+ </div>
+
+ <div class="form-group">
+ <label class="col-md-4 control-label" for="email">Email*</label>
+ <div class="col-md-4">
+ <input id="email" name="email" placeholder="Your E-Mail here." class="form-control input-md" required="" type="text">
+ </div>
+ </div>
+
+ <div class="form-group">
+ <label class="col-md-4 control-label" for="confirmEmail">Confirm Email*</label>
+ <div class="col-md-4">
+ <input id="confirmEmail" name="confirmEmail" placeholder="Confirm your E-Mail." class="form-control input-md" required="" type="text">
+ </div>
+ </div>
+
+ <div class="form-group">
+ <label class="col-md-4 control-label" for="password">Password*</label>
+ <div class="col-md-4">
+ <input id="password" name="password" placeholder="Your password here." class="form-control input-md" required="" type="password">
+ </div>
+ </div>
+
+ <div class="form-group">
+ <label class="col-md-4 control-label" for="confirmPassword">Confirm Password*</label>
+ <div class="col-md-4">
+ <input id="confirmPassword" name="confirmPassword" placeholder="Confirm your password." class="form-control input-md" required="" type="password">
</div>
</div>