01.02.2019
This commit is contained in:
parent
9de6e5d0de
commit
a88803ac6f
3
bower_components/css/app.css
vendored
3
bower_components/css/app.css
vendored
@ -5,4 +5,5 @@ body {
|
||||
textarea {
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
}
|
||||
}
|
||||
|
||||
|
27
main.go
27
main.go
@ -38,19 +38,26 @@ func edit(rend render.Render, w http.ResponseWriter, r *http.Request, params mar
|
||||
func savePost(rend render.Render, w http.ResponseWriter, r *http.Request) {
|
||||
id := r.FormValue("id")
|
||||
title := r.FormValue("title")
|
||||
contentMd := r.FormValue("content")
|
||||
contentHtml := helpers.MarkdownToHtml(contentMd)
|
||||
|
||||
if id != "" {
|
||||
if err := models.Posts.Update(id, title, contentHtml, contentMd); err != nil {
|
||||
rend.Error(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if title == "" {
|
||||
rend.Error(http.StatusNotFound)
|
||||
return
|
||||
} else {
|
||||
contentMd := r.FormValue("content")
|
||||
contentHtml := helpers.MarkdownToHtml(contentMd)
|
||||
contentCom := r.FormValue("content1")
|
||||
|
||||
if _, err := models.Posts.Create(helpers.GenerateId(), title, contentHtml, contentMd); err != nil {
|
||||
rend.Error(http.StatusBadRequest)
|
||||
return
|
||||
if id != "" {
|
||||
if err := models.Posts.Update(id, title, contentHtml, contentMd, contentCom); err != nil {
|
||||
rend.Error(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
|
||||
if _, err := models.Posts.Create(helpers.GenerateId(), title, contentHtml, contentMd, contentCom); err != nil {
|
||||
rend.Error(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ type Post struct {
|
||||
Title string `bson:"title"`
|
||||
ContentHtml string `bson:"content_html"`
|
||||
ContentMd string `bson:"content_md"`
|
||||
ContentCom string `bson:"content_com"`
|
||||
}
|
||||
|
||||
//Post
|
||||
@ -27,12 +28,13 @@ func (posts) FindAll() ([]*Post, error) {
|
||||
return ps, common.DB.Posts.Find(nil).All(&ps)
|
||||
}
|
||||
|
||||
func (posts) Create(id, title, contentHtml, contentMd string) (*Post, error) {
|
||||
func (posts) Create(id, title, contentHtml, contentMd, contentCom string) (*Post, error) {
|
||||
p := &Post{
|
||||
Id: id,
|
||||
Title: title,
|
||||
ContentMd: contentMd,
|
||||
ContentHtml: contentHtml,
|
||||
ContentCom: contentCom,
|
||||
}
|
||||
if err := common.DB.Posts.Insert(p); err != nil {
|
||||
return nil, err
|
||||
@ -41,12 +43,13 @@ func (posts) Create(id, title, contentHtml, contentMd string) (*Post, error) {
|
||||
|
||||
}
|
||||
|
||||
func (posts) Update(id, title, contentHtml, contentMd string) error {
|
||||
func (posts) Update(id, title, contentHtml, contentMd, contentCom string) error {
|
||||
if err := common.DB.Posts.UpdateId(id,
|
||||
bson.M{"$set": bson.M{
|
||||
"title": title,
|
||||
"content_html": contentHtml,
|
||||
"content_md": contentMd,
|
||||
"content_com": contentCom,
|
||||
}}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
45
test.go
Normal file
45
test.go
Normal file
@ -0,0 +1,45 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func sayhelloName(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm() //Parse url parameters passed, then parse the response packet for the POST body (request body)
|
||||
// attention: If you do not call ParseForm method, the following data can not be obtained form
|
||||
fmt.Println(r.Form) // print information on server side.
|
||||
fmt.Println("path", r.URL.Path)
|
||||
fmt.Println("scheme", r.URL.Scheme)
|
||||
fmt.Println(r.Form["url_long"])
|
||||
for k, v := range r.Form {
|
||||
fmt.Println("key:", k)
|
||||
fmt.Println("val:", strings.Join(v, ""))
|
||||
}
|
||||
fmt.Fprintf(w, "Hello astaxie!") // write data to response
|
||||
}
|
||||
|
||||
func login(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("method:", r.Method) //get request method
|
||||
if r.Method == "GET" {
|
||||
t, _ := template.ParseFiles("login.gtpl")
|
||||
t.Execute(w, nil)
|
||||
} else {
|
||||
r.ParseForm()
|
||||
// logic part of log in
|
||||
fmt.Println("username:", r.Form["username"])
|
||||
fmt.Println("password:", r.Form["password"])
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", sayhelloName) // setting router rule
|
||||
http.HandleFunc("/login", login)
|
||||
err := http.ListenAndServe(":9090", nil) // setting listening port
|
||||
if err != nil {
|
||||
log.Fatal("ListenAndServe: ", err)
|
||||
}
|
||||
}
|
@ -8,12 +8,30 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-2"></div>
|
||||
<div class="col-xs-2">
|
||||
|
||||
</div>
|
||||
<div class="col-xs-8">
|
||||
{{ $value.ContentHtml | unescape }}
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-xs-8">
|
||||
<br/><br/>Komentarz
|
||||
<fieldset style="border: 2px solid; width: 450px; height: 160px; padding: 3;">{{ $value.ContentCom | unescape }}</fieldset>
|
||||
<form action="/createCom" method="POST" role="form"></form>
|
||||
<input type="hidden" name="id" value="{{.Id}}"/>
|
||||
<div class="form-group">
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="col-xs-2"></div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
@ -15,7 +15,12 @@
|
||||
<label for="content">Treść</label>
|
||||
<textarea name="content" id="content">{{.ContentMd}}</textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default">Akceptuj</button>
|
||||
|
||||
<div class="form-group"><br>
|
||||
<label for="content1">Kom</label>
|
||||
<textarea name="content1" id="content1">{{.ContentCom}}</textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default">Akceptuj</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-xs-6" id="md">
|
||||
|
Loading…
Reference in New Issue
Block a user