diff --git a/controllers/BlogController.go b/controllers/BlogController.go index 005b61d..8b4f6ba 100644 --- a/controllers/BlogController.go +++ b/controllers/BlogController.go @@ -5,7 +5,6 @@ import ( "beeblog/models" "beeblog/service" "strconv" - "fmt" ) type BlogController struct { @@ -18,9 +17,8 @@ func (this *BlogController) Save() { catory := this.GetString("catory") catoryId, _ := strconv.ParseInt(catory, 10, 64) labels := this.GetStrings("labels[]") - fmt.Println(title,blogHtml,catoryId,labels,labels[0]) - blog := &models.Blog{Title: title,BlogHtml:blogHtml,CategoryId:catoryId} - err := service.SaveBlog(blog,labels) + blog := &models.Blog{Title: title, BlogHtml: blogHtml, CategoryId: catoryId, UserId: 1} + err := service.SaveBlog(blog, labels) if (err == nil) { this.Data["json"] = blog } else { @@ -36,10 +34,9 @@ func (this *BlogController) Get() { if (err == nil) { this.Data["Blog"] = blog } - //this.Data["IsHome"] = true this.TplName = "blog.html" } func (this *BlogController) New() { this.TplName = "newblog.html" -} \ No newline at end of file +} diff --git a/controllers/UserController.go b/controllers/UserController.go index 133f556..3ccc4a3 100644 --- a/controllers/UserController.go +++ b/controllers/UserController.go @@ -25,7 +25,8 @@ func (u *UserController) LoginPage() { //num, err = o.Delete(&u) //fmt.Printf("NUM: %d, ERR: %v\n", num, err) - u.Ctx.WriteString("login page") + //u.Ctx.WriteString("login page") + u.TplName = "login.html" } func (this *UserController) Login() { diff --git a/data/beeblog.db b/data/beeblog.db index 372889d..a2d24ee 100644 Binary files a/data/beeblog.db and b/data/beeblog.db differ diff --git a/models/DataInit.go b/models/DataInit.go index fc41286..b456bdb 100644 --- a/models/DataInit.go +++ b/models/DataInit.go @@ -19,7 +19,7 @@ func RegistDB() { os.Create(_DB_NAME) } //orm.RegisterModel(new(Attachment),new(Topic)) - orm.RegisterModel(new(Attachment),new(User),new(Blog)) + orm.RegisterModel(new(Attachment),new(User),new(Blog),new(NLabel)) orm.RegisterDriver(_SQLITE3_DRIVER,orm.DRSqlite) orm.RegisterDataBase("default",_SQLITE3_DRIVER,_DB_NAME,10) } \ No newline at end of file diff --git a/models/NLabel.go b/models/NLabel.go index 287ea2f..88159dd 100644 --- a/models/NLabel.go +++ b/models/NLabel.go @@ -6,5 +6,6 @@ type NLabel struct { Id int64 Title string UserId int64 + BlogId int64 Ctime time.Time `orm:"auto_now_add;type(datetime)"` } diff --git a/service/BlogService.go b/service/BlogService.go index a5a35bf..c61b272 100644 --- a/service/BlogService.go +++ b/service/BlogService.go @@ -31,18 +31,22 @@ func FindBlogs() ([]*models.Blog, error) { func SaveBlog(blog *models.Blog, strs []string) error { o := orm.NewOrm() + o.Begin() id, eror := o.Insert(blog) if eror != nil { + o.Rollback() return eror } else { blog.Id = id if strs != nil && len(strs) > 0 { - nlabels := make([]*models.NLabel,len(strs)) - //var nlabels [len(*strs)]*models.NLabel + nlabels := make([]*models.NLabel, len(strs)) for i := 0; i < len(strs); i++ { - nlabels[i] = &models.NLabel{Title:strs[i]} + nlabels[i] = &models.NLabel{Title: strs[i], BlogId: id, UserId: blog.UserId} + } + if _, err := o.InsertMulti(len(nlabels), nlabels); err != nil { + o.Rollback() + return err } - o.InsertMulti(len(nlabels),nlabels) } o.Commit() } diff --git a/static/css/login.css b/static/css/login.css new file mode 100644 index 0000000..61e1179 --- /dev/null +++ b/static/css/login.css @@ -0,0 +1,18 @@ +.login-root { + background: #f0e7db url("/static/img/login.png") no-repeat; + padding-top: 50px; + position: absolute; + min-height: 100%; + width: 100%; + overflow: hidden; +} + +.login-root .input-container{ + position: fixed; + left: 65%; + background: url("/static/img/loginbg.png") no-repeat center top; +} +.login-root .input-container .input-root{ + width: 370px; + height: 500px; +} diff --git a/static/img/login.png b/static/img/login.png new file mode 100644 index 0000000..7b8ce0d Binary files /dev/null and b/static/img/login.png differ diff --git a/static/img/loginbg.png b/static/img/loginbg.png new file mode 100644 index 0000000..7fdc184 Binary files /dev/null and b/static/img/loginbg.png differ diff --git a/views/login.html b/views/login.html new file mode 100644 index 0000000..adab1ec --- /dev/null +++ b/views/login.html @@ -0,0 +1,17 @@ +{{template "header"}} +登录 - 个人随笔 + + + +
+{{template "nav" .}} +
+
+
+

登录

+
+
+
+
+ + \ No newline at end of file