Browse Source

login

layui
yirenyishi 6 years ago
parent
commit
6b34183810
  1. 9
      controllers/BlogController.go
  2. 3
      controllers/UserController.go
  3. BIN
      data/beeblog.db
  4. 2
      models/DataInit.go
  5. 1
      models/NLabel.go
  6. 12
      service/BlogService.go
  7. 18
      static/css/login.css
  8. BIN
      static/img/login.png
  9. BIN
      static/img/loginbg.png
  10. 17
      views/login.html

9
controllers/BlogController.go

@ -5,7 +5,6 @@ import (
"beeblog/models" "beeblog/models"
"beeblog/service" "beeblog/service"
"strconv" "strconv"
"fmt"
) )
type BlogController struct { type BlogController struct {
@ -18,9 +17,8 @@ func (this *BlogController) Save() {
catory := this.GetString("catory") catory := this.GetString("catory")
catoryId, _ := strconv.ParseInt(catory, 10, 64) catoryId, _ := strconv.ParseInt(catory, 10, 64)
labels := this.GetStrings("labels[]") labels := this.GetStrings("labels[]")
fmt.Println(title,blogHtml,catoryId,labels,labels[0]) blog := &models.Blog{Title: title, BlogHtml: blogHtml, CategoryId: catoryId, UserId: 1}
blog := &models.Blog{Title: title,BlogHtml:blogHtml,CategoryId:catoryId} err := service.SaveBlog(blog, labels)
err := service.SaveBlog(blog,labels)
if (err == nil) { if (err == nil) {
this.Data["json"] = blog this.Data["json"] = blog
} else { } else {
@ -36,10 +34,9 @@ func (this *BlogController) Get() {
if (err == nil) { if (err == nil) {
this.Data["Blog"] = blog this.Data["Blog"] = blog
} }
//this.Data["IsHome"] = true
this.TplName = "blog.html" this.TplName = "blog.html"
} }
func (this *BlogController) New() { func (this *BlogController) New() {
this.TplName = "newblog.html" this.TplName = "newblog.html"
} }

3
controllers/UserController.go

@ -25,7 +25,8 @@ func (u *UserController) LoginPage() {
//num, err = o.Delete(&u) //num, err = o.Delete(&u)
//fmt.Printf("NUM: %d, ERR: %v\n", num, err) //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() { func (this *UserController) Login() {

BIN
data/beeblog.db

Binary file not shown.

2
models/DataInit.go

@ -19,7 +19,7 @@ func RegistDB() {
os.Create(_DB_NAME) os.Create(_DB_NAME)
} }
//orm.RegisterModel(new(Attachment),new(Topic)) //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.RegisterDriver(_SQLITE3_DRIVER,orm.DRSqlite)
orm.RegisterDataBase("default",_SQLITE3_DRIVER,_DB_NAME,10) orm.RegisterDataBase("default",_SQLITE3_DRIVER,_DB_NAME,10)
} }

1
models/NLabel.go

@ -6,5 +6,6 @@ type NLabel struct {
Id int64 Id int64
Title string Title string
UserId int64 UserId int64
BlogId int64
Ctime time.Time `orm:"auto_now_add;type(datetime)"` Ctime time.Time `orm:"auto_now_add;type(datetime)"`
} }

12
service/BlogService.go

@ -31,18 +31,22 @@ func FindBlogs() ([]*models.Blog, error) {
func SaveBlog(blog *models.Blog, strs []string) error { func SaveBlog(blog *models.Blog, strs []string) error {
o := orm.NewOrm() o := orm.NewOrm()
o.Begin()
id, eror := o.Insert(blog) id, eror := o.Insert(blog)
if eror != nil { if eror != nil {
o.Rollback()
return eror return eror
} else { } else {
blog.Id = id blog.Id = id
if strs != nil && len(strs) > 0 { if strs != nil && len(strs) > 0 {
nlabels := make([]*models.NLabel,len(strs)) nlabels := make([]*models.NLabel, len(strs))
//var nlabels [len(*strs)]*models.NLabel
for i := 0; i < len(strs); i++ { 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() o.Commit()
} }

18
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;
}

BIN
static/img/login.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 504 KiB

BIN
static/img/loginbg.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

17
views/login.html

@ -0,0 +1,17 @@
{{template "header"}}
<title>登录 - 个人随笔</title>
<link type="text/css" rel="styleSheet" href="/static/css/login.css"/>
</head>
<body>
<div class="root-container">
{{template "nav" .}}
<div class="login-root">
<div class="input-container">
<div class="input-root">
<p>登录</p>
</div>
</div>
</div>
</div>
</body>
</html>
Loading…
Cancel
Save