Compare commits
2 Commits
f5ace34852
...
3aab4827fe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3aab4827fe | ||
|
|
64b7fa4f50 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ test.txt
|
||||
ledger-quicknote
|
||||
*.txt
|
||||
.htpasswd
|
||||
data
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
{{ .Date }} {{ with .Name }}{{ . }}{{ else }}{{ .Destination }}{{ end }}
|
||||
{{ .Destination }} ${{ .Amount }}
|
||||
{{ with .Source }}{{ . }}{{ else }}cash{{ end }}
|
||||
|
||||
3
main.go
3
main.go
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/base64"
|
||||
"flag"
|
||||
"log"
|
||||
"path"
|
||||
"text/template"
|
||||
|
||||
"github.com/gorilla/securecookie"
|
||||
@@ -41,7 +42,7 @@ func init() {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
store, err = auth.New(HTPASSWD_FILE, hashKey)
|
||||
store, err = auth.New(path.Join(DATA_DIR, HTPASSWD_FILE), hashKey)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
18
route.go
18
route.go
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"text/template"
|
||||
@@ -71,12 +70,8 @@ func router() *gin.Engine {
|
||||
})
|
||||
|
||||
authZone.GET("/edit", func(c *gin.Context) {
|
||||
c.Redirect(303, fmt.Sprintf("/edit/%s", DEFAULT_JOURNAL))
|
||||
})
|
||||
|
||||
authZone.GET("/edit/:filename", func(c *gin.Context) {
|
||||
user := getUser(c)
|
||||
filename := c.Param("filename")
|
||||
filename := c.Query("filename")
|
||||
list, err := user.List()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -103,17 +98,18 @@ func router() *gin.Engine {
|
||||
})
|
||||
})
|
||||
|
||||
authZone.POST("/edit/:filename", func(c *gin.Context) {
|
||||
authZone.POST("/edit", func(c *gin.Context) {
|
||||
user := getUser(c)
|
||||
filename := c.Param("filename")
|
||||
filename := c.PostForm("filename")
|
||||
data := c.PostForm("data")
|
||||
err := user.overwriteFile(filename, data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
HTML(c, 200, "success.html", struct {
|
||||
Tx string
|
||||
}{data})
|
||||
HTML(c, 200, "success.html", gin.H{
|
||||
"FileName": filename,
|
||||
"Tx": data,
|
||||
})
|
||||
})
|
||||
|
||||
authZone.GET("/download", func(c *gin.Context) {
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
{{ define "title" }}編輯{{ end }}
|
||||
{{ define "main" }}
|
||||
<h1>編輯帳本</h1>
|
||||
<h1>編輯檔案</h1>
|
||||
<aside>
|
||||
<ul>
|
||||
{{ range .FileList }}
|
||||
<li><a href="/edit/{{ . }}">{{ . }}</a></li>
|
||||
<li><a href="/edit?filename={{ . }}">{{ . }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
<p><a href="/edit">新檔案</a></p>
|
||||
</aside>
|
||||
|
||||
<p>{{ .FileName }}{{ if not .Exists }} - New file{{ end }}</p>
|
||||
|
||||
<form action="/edit/{{ .FileName }}" method="POST">
|
||||
<form action="/edit" method="POST">
|
||||
<label>Filename: <input type="text" name="filename" value="{{ .FileName }}"></label><br>
|
||||
<textarea name="data" rows="15" cols="40">{{ .Data }}</textarea><br>
|
||||
<input type="submit" value="儲存">
|
||||
<input type="submit" value="{{ if .Exists }}儲存{{ else }}新增{{ end }}">
|
||||
</form>
|
||||
{{ end }}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{{ define "title" }}Success{{ end }}
|
||||
{{ define "main" }}
|
||||
<p><strong>Success</strong></p>
|
||||
<p><a href="/edit?filename={{ .FileName }}">繼續編輯</a></p>
|
||||
<pre><code>{{ .Tx }}</code></pre>
|
||||
<p><a href="/dashboard">Back to home</a></p>
|
||||
{{ end }}
|
||||
|
||||
Reference in New Issue
Block a user