summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorhorus_arch2015-03-19 13:39:37 +0100
committerhorus_arch2015-03-19 13:39:37 +0100
commitf334c93c0364d14a2b55641b155ad58f715a4b39 (patch)
tree63ffbfc845f441802bd59c07adf2d9fe2f86c4bc /app
parent3c9bdbc66998075278f7d79fa10709e7fab5deb6 (diff)
downloadfreemail-f334c93c0364d14a2b55641b155ad58f715a4b39.tar.gz
Rewriting from scratch.
Diffstat (limited to 'app')
-rw-r--r--app/controllers/app.go63
-rw-r--r--app/controllers/db.go138
-rw-r--r--app/controllers/email.dbbin10240 -> 0 bytes
-rw-r--r--app/controllers/init.go10
-rw-r--r--app/controllers/utilities.go98
-rw-r--r--app/init.go38
-rw-r--r--app/views/App/DomainRegister.html50
-rw-r--r--app/views/App/Index.html13
-rw-r--r--app/views/App/Index.html.bak23
-rw-r--r--app/views/App/Register.html78
-rw-r--r--app/views/debug.html64
-rw-r--r--app/views/errors/404.html20
-rw-r--r--app/views/errors/500.html16
-rw-r--r--app/views/flash.html18
-rw-r--r--app/views/footer.html19
-rw-r--r--app/views/header.html19
-rw-r--r--app/views/navbar.html23
17 files changed, 0 insertions, 690 deletions
diff --git a/app/controllers/app.go b/app/controllers/app.go
deleted file mode 100644
index 2b8945c..0000000
--- a/app/controllers/app.go
+++ /dev/null
@@ -1,63 +0,0 @@
-package controllers
-
-import (
- _ "github.com/jinzhu/gorm"
- _ "github.com/mattn/go-sqlite3"
- "github.com/revel/revel"
-)
-
-type App struct {
- //*revel.Controller
- GormController
-}
-
-func (c App) Index() 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) Register() revel.Result {
- return c.Render()
-}
diff --git a/app/controllers/db.go b/app/controllers/db.go
deleted file mode 100644
index 5b7dd97..0000000
--- a/app/controllers/db.go
+++ /dev/null
@@ -1,138 +0,0 @@
-package controllers
-
-import (
- "github.com/jinzhu/gorm"
- // _ "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
- 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
-}
-*/
-
-// 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
- 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_name", "name")
- Gdb.Model(&user).AddUniqueIndex("idx_user_email", "email")
-
- /*
- 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.Gdb before each transaction
-func (c *GormController) Begin() revel.Result {
- txn := Gdb.Begin()
- if txn.Error != nil {
- //panic(txn.Error)
- revel.ERROR.Printf("%s \n", txn.Error)
- }
- c.Gdb = txn
- return nil
-}
-
-// This method clears the c.Gdb after each transaction
-func (c *GormController) Commit() revel.Result {
- if c.Gdb == nil {
- return nil
- }
- c.Gdb.Commit()
- if err := c.Gdb.Error; err != nil && err != sql.ErrTxDone {
- panic(err)
- }
- c.Gdb = nil
- return nil
-}
-
-// This method clears the c.Gdb after each transaction, too
-func (c *GormController) Rollback() revel.Result {
- if c.Gdb == nil {
- return nil
- }
- c.Gdb.Rollback()
- if err := c.Gdb.Error; err != nil && err != sql.ErrTxDone {
- panic(err)
- }
- c.Gdb = nil
- return nil
-}
diff --git a/app/controllers/email.db b/app/controllers/email.db
deleted file mode 100644
index 4a4cefc..0000000
--- a/app/controllers/email.db
+++ /dev/null
Binary files differ
diff --git a/app/controllers/init.go b/app/controllers/init.go
deleted file mode 100644
index a5c9096..0000000
--- a/app/controllers/init.go
+++ /dev/null
@@ -1,10 +0,0 @@
-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/controllers/utilities.go b/app/controllers/utilities.go
deleted file mode 100644
index 693a459..0000000
--- a/app/controllers/utilities.go
+++ /dev/null
@@ -1,98 +0,0 @@
-package controllers
-
-import (
- "crypto/md5"
- "fmt"
- // "github.com/garyburd/redigo/redis"
- "github.com/revel/revel"
- "golang.org/x/crypto/bcrypt"
- "io"
- "io/ioutil"
- "math/rand"
- "net/http"
- // "time"
-)
-
-// Returns the content of a webpage as string
-func HttpGet(url string) (http.Header, string, error) {
- response, err := http.Get(url)
- if err != nil {
- return nil, "Get request failed.", err
- }
-
- defer response.Body.Close()
- contents, err := ioutil.ReadAll(response.Body)
- if err != nil {
- return nil, "Reading body failed.", err
- }
-
- return response.Header, string(contents), nil
-}
-
-// Hashs and returns a string (md5)
-func Hash(content string) string {
- h := md5.New()
- io.WriteString(h, content)
- hash := fmt.Sprintf("%x", h.Sum(nil))
-
- return hash
-}
-
-// Creates a random string
-func RandomKey() string {
- letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
- key := make([]rune, 40)
- for i := range key {
- key[i] = letters[rand.Intn(len(letters))]
- }
-
- return string(key)
-}
-
-//var pool = newPool()
-
-/*
-// Creates a pool with connections to Redis
-func newPool() *redis.Pool {
- return &redis.Pool{
- MaxIdle: 3,
- IdleTimeout: 240 * time.Second,
- Dial: func() (redis.Conn, error) {
- //c, err := redis.Dial("tcp", ":6379")
- c, err := redis.Dial("tcp", revel.Config.StringDefault("redis.server", "127.0.0.1")+":"+revel.Config.StringDefault("redis.port", "6379"))
- if err != nil {
- return nil, err
- }
- return c, err
- },
- TestOnBorrow: func(c redis.Conn, t time.Time) error {
- _, err := c.Do("PING")
- return err
- },
- }
-}
-*/
-
-// Hashs password with bcrypt and returns the string
-func HashPassword(password string) string {
- if password == "" {
- return ""
- }
- p := []byte(password)
- hash, err := bcrypt.GenerateFromPassword(p, 10)
- if err != nil {
- revel.ERROR.Printf("%s \n", err)
- return ""
- }
- return string(hash)
-}
-
-// Verify password and hash
-func VerifyPassword(password, hash string) bool {
- err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
- if err != nil {
- revel.ERROR.Printf("%s \n", err)
- return false
- }
- return true
-}
diff --git a/app/init.go b/app/init.go
deleted file mode 100644
index 2305d73..0000000
--- a/app/init.go
+++ /dev/null
@@ -1,38 +0,0 @@
-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/DomainRegister.html b/app/views/App/DomainRegister.html
deleted file mode 100644
index 9c8683c..0000000
--- a/app/views/App/DomainRegister.html
+++ /dev/null
@@ -1,50 +0,0 @@
-{{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/Index.html b/app/views/App/Index.html
deleted file mode 100644
index cf36a51..0000000
--- a/app/views/App/Index.html
+++ /dev/null
@@ -1,13 +0,0 @@
-{{set . "title" "Home"}}
-{{template "header.html" .}}
-{{template "navbar.html" .}}
-
-<div class="container">
- <div class="text-center">
- <div class="row">
- </div>
- </div>
-</div>
-
-
-{{template "footer.html" .}}
diff --git a/app/views/App/Index.html.bak b/app/views/App/Index.html.bak
deleted file mode 100644
index deb2304..0000000
--- a/app/views/App/Index.html.bak
+++ /dev/null
@@ -1,23 +0,0 @@
-{{set . "title" "Home"}}
-{{template "header.html" .}}
-
-<header class="hero-unit" style="background-color:#A9F16C">
- <div class="container">
- <div class="row">
- <div class="hero-text">
- <h1>It works!</h1>
- <p></p>
- </div>
- </div>
- </div>
-</header>
-
-<div class="container">
- <div class="row">
- <div class="span6">
- {{template "flash.html" .}}
- </div>
- </div>
-</div>
-
-{{template "footer.html" .}}
diff --git a/app/views/App/Register.html b/app/views/App/Register.html
deleted file mode 100644
index e950804..0000000
--- a/app/views/App/Register.html
+++ /dev/null
@@ -1,78 +0,0 @@
-{{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='/register'>
- <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="name">Name*</label>
- <div class="col-md-4">
- <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>
-
- <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/debug.html b/app/views/debug.html
deleted file mode 100644
index f3975b7..0000000
--- a/app/views/debug.html
+++ /dev/null
@@ -1,64 +0,0 @@
-<style type="text/css">
- #sidebar {
- position: absolute;
- right: 0px;
- top:69px;
- max-width: 75%;
- z-index: 1000;
- background-color: #fee;
- border: thin solid grey;
- padding: 10px;
- }
- #toggleSidebar {
- position: absolute;
- right: 0px;
- top: 50px;
- background-color: #fee;
- }
-
-</style>
-<div id="sidebar" style="display:none;">
- <h4>Available pipelines</h4>
- <dl>
- {{ range $index, $value := .}}
- <dt>{{$index}}</dt>
- <dd>{{$value}}</dd>
- {{end}}
- </dl>
- <h4>Flash</h4>
- <dl>
- {{ range $index, $value := .flash}}
- <dt>{{$index}}</dt>
- <dd>{{$value}}</dd>
- {{end}}
- </dl>
-
- <h4>Errors</h4>
- <dl>
- {{ range $index, $value := .errors}}
- <dt>{{$index}}</dt>
- <dd>{{$value}}</dd>
- {{end}}
- </dl>
-</div>
-<a id="toggleSidebar" href="#" class="toggles"><i class="icon-chevron-left"></i></a>
-
-<script>
- $sidebar = 0;
- $('#toggleSidebar').click(function() {
- if ($sidebar === 1) {
- $('#sidebar').hide();
- $('#toggleSidebar i').addClass('icon-chevron-left');
- $('#toggleSidebar i').removeClass('icon-chevron-right');
- $sidebar = 0;
- }
- else {
- $('#sidebar').show();
- $('#toggleSidebar i').addClass('icon-chevron-right');
- $('#toggleSidebar i').removeClass('icon-chevron-left');
- $sidebar = 1;
- }
-
- return false;
- });
-</script>
diff --git a/app/views/errors/404.html b/app/views/errors/404.html
deleted file mode 100644
index ebdfe10..0000000
--- a/app/views/errors/404.html
+++ /dev/null
@@ -1,20 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
- <head>
- <title>Not found</title>
- </head>
- <body>
-{{if eq .RunMode "dev"}}
-{{template "errors/404-dev.html" .}}
-{{else}}
- {{with .Error}}
- <h1>
- {{.Title}}
- </h1>
- <p>
- {{.Description}}
- </p>
- {{end}}
-{{end}}
- </body>
-</html>
diff --git a/app/views/errors/500.html b/app/views/errors/500.html
deleted file mode 100644
index 0cef4de..0000000
--- a/app/views/errors/500.html
+++ /dev/null
@@ -1,16 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title>Application error</title>
- </head>
- <body>
- {{if eq .RunMode "dev"}}
- {{template "errors/500-dev.html" .}}
- {{else}}
- <h1>Oops, an error occured</h1>
- <p>
- This exception has been logged.
- </p>
- {{end}}
- </body>
-</html>
diff --git a/app/views/flash.html b/app/views/flash.html
deleted file mode 100644
index 9c9ade9..0000000
--- a/app/views/flash.html
+++ /dev/null
@@ -1,18 +0,0 @@
-{{if .flash.success}}
-<div class="alert alert-success">
- {{.flash.success}}
-</div>
-{{end}}
-
-{{if or .errors .flash.error}}
-<div class="alert alert-error">
- {{if .flash.error}}
- {{.flash.error}}
- {{end}}
- <ul style="margin-top:10px;">
- {{range .errors}}
- <li>{{.}}</li>
- {{end}}
- </ul>
-</div>
-{{end}}
diff --git a/app/views/footer.html b/app/views/footer.html
deleted file mode 100644
index 1b06355..0000000
--- a/app/views/footer.html
+++ /dev/null
@@ -1,19 +0,0 @@
- {{if eq .RunMode "dev"}}
- {{template "debug.html" .}}
- {{end}}
- {{range .moreScripts}}
- <script src="/public/{{.}}" type="text/javascript" charset="utf-8"></script>
- {{end}}
-<div class="footer">
- <div class="container">
- <div class="row">
- <footer>
- <p id="copyright-text" align='right'> Copyright 2015 <a class="footer-a" href="//www.iamfabulous.de" title="Maximilian Möhring">Maximilian M&ouml;hring</a></p>
- </footer>
- </div>
- </div>
-</div>
-<script src="//code.jquery.com/jquery-1.10.1.min.js"></script>
-<script src="/static/js/bootstrap.js"></script>
- </body>
-</html>
diff --git a/app/views/header.html b/app/views/header.html
deleted file mode 100644
index 2875487..0000000
--- a/app/views/header.html
+++ /dev/null
@@ -1,19 +0,0 @@
-<!DOCTYPE html>
-
-<html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>{{.title}}</title>
- <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
- <!--link rel="stylesheet" type="text/css" href="/static/css/bootstrap.css"-->
- <link rel="stylesheet" type="text/css" href="/static/css/style.css">
- <link rel="shortcut icon" type="image/png" href="/static/img/favicon.ico">
- {{range .moreStyles}}
- <link rel="stylesheet" type="text/css" href="/public/{{.}}">
- {{end}}
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <noscript>
- <style>.navbar{margin-bottom:0;}</style>
- </noscript>
- </head>
- <body>
diff --git a/app/views/navbar.html b/app/views/navbar.html
deleted file mode 100644
index 2e45d0a..0000000
--- a/app/views/navbar.html
+++ /dev/null
@@ -1,23 +0,0 @@
-<nav class="navbar navbar-default navbar-custom" role="navigation">
- <div class="container">
- <div class="navbar-header">
- <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbarCollapse">
- <span class="sr-only">Toggle navigation</span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- </button>
- <a class="navbar-brand" href="/"><span class="glyphicon glyphicon-home"></span> Home</a>
- </div>
- <div class="collapse navbar-collapse" id="navbarCollapse">
- <ul class="nav navbar-nav navbar-bar-left">
- <li>
- <a href="#" >About</a>
- </li>
- <li>
- <a href="#" >About</a>
- </li>
- </ul>
- </div>
- </div>
-</nav>