|
@ -9,7 +9,6 @@ import ( |
|
|
"time" |
|
|
"time" |
|
|
"strconv" |
|
|
"strconv" |
|
|
"encoding/hex" |
|
|
"encoding/hex" |
|
|
"fmt" |
|
|
|
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
type UserController struct { |
|
|
type UserController struct { |
|
@ -23,30 +22,58 @@ func (u *UserController) RegistPage() { |
|
|
u.TplName = "regist.html" |
|
|
u.TplName = "regist.html" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (u *UserController) PersonBlog() { |
|
|
func (this *UserController) PersonBlog() { |
|
|
u.TplName = "ublogs.html" |
|
|
uid := this.GetSession("userid") |
|
|
|
|
|
if uid == nil { |
|
|
|
|
|
this.Redirect("/login", 302) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
size := 15 |
|
|
|
|
|
num, _ := this.GetInt("num") |
|
|
|
|
|
if num <= 0 { |
|
|
|
|
|
num = 1 |
|
|
|
|
|
} |
|
|
|
|
|
flag, _ := this.GetInt("flag") |
|
|
|
|
|
page, err := service.MeBlogs(num, size, flag, uid.(int64)) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
if uid == nil { |
|
|
|
|
|
this.Redirect("/500", 302) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
user, uerr := service.GetUser(uid.(int64)) |
|
|
|
|
|
if uerr != nil { |
|
|
|
|
|
if uid == nil { |
|
|
|
|
|
this.Redirect("/500", 302) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
this.Data["Page"] = page |
|
|
|
|
|
this.Data["Flag"] = 0 |
|
|
|
|
|
this.Data["User"] = user |
|
|
|
|
|
this.TplName = "ublogs.html" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (this *UserController) Login() { |
|
|
func (this *UserController) Login() { |
|
|
username := this.GetString("username") |
|
|
username := this.GetString("username") |
|
|
userpwd := this.GetString("userpwd") |
|
|
userpwd := this.GetString("userpwd") |
|
|
if username == "" { |
|
|
if username == "" { |
|
|
this.Data["json"] = models.ReurnError(1,"用户名为空") |
|
|
this.Data["json"] = models.ReurnError(1, "用户名为空") |
|
|
this.ServeJSON() |
|
|
this.ServeJSON() |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
if len(username) < 4 { |
|
|
if len(username) < 4 { |
|
|
this.Data["json"] = models.ReurnError(1,"用户名最低4位") |
|
|
this.Data["json"] = models.ReurnError(1, "用户名最低4位") |
|
|
this.ServeJSON() |
|
|
this.ServeJSON() |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
if userpwd == "" { |
|
|
if userpwd == "" { |
|
|
this.Data["json"] = models.ReurnError(1,"密码为空") |
|
|
this.Data["json"] = models.ReurnError(1, "密码为空") |
|
|
this.ServeJSON() |
|
|
this.ServeJSON() |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
if len(userpwd) < 6 { |
|
|
if len(userpwd) < 6 { |
|
|
this.Data["json"] = models.ReurnError(1,"密码最低6位") |
|
|
this.Data["json"] = models.ReurnError(1, "密码最低6位") |
|
|
this.ServeJSON() |
|
|
this.ServeJSON() |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
@ -59,12 +86,11 @@ func (this *UserController) Login() { |
|
|
this.Data["json"] = models.ReurnSuccess("") |
|
|
this.Data["json"] = models.ReurnSuccess("") |
|
|
this.SetSession("userid", user.Id) |
|
|
this.SetSession("userid", user.Id) |
|
|
this.SetSession("nickname", user.NickName) |
|
|
this.SetSession("nickname", user.NickName) |
|
|
fmt.Println(this.CruSession) |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
this.Data["json"] = models.ReurnError(1,"用户名或密码错误") |
|
|
this.Data["json"] = models.ReurnError(1, "用户名或密码错误") |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
this.Data["json"] = models.ReurnError(1,"用户名不存在") |
|
|
this.Data["json"] = models.ReurnError(1, "用户名不存在") |
|
|
} |
|
|
} |
|
|
this.ServeJSON() |
|
|
this.ServeJSON() |
|
|
return |
|
|
return |
|
@ -76,28 +102,28 @@ func (this *UserController) Regist() { |
|
|
username = strings.Replace(username, " ", "", -1) |
|
|
username = strings.Replace(username, " ", "", -1) |
|
|
userpwd = strings.Replace(userpwd, " ", "", -1) |
|
|
userpwd = strings.Replace(userpwd, " ", "", -1) |
|
|
if username == "" { |
|
|
if username == "" { |
|
|
this.Data["json"] = models.ReurnError(1,"用户名为空") |
|
|
this.Data["json"] = models.ReurnError(1, "用户名为空") |
|
|
this.ServeJSON() |
|
|
this.ServeJSON() |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
if len(username) < 4 { |
|
|
if len(username) < 4 { |
|
|
this.Data["json"] = models.ReurnError(1,"用户名最低4位") |
|
|
this.Data["json"] = models.ReurnError(1, "用户名最低4位") |
|
|
this.ServeJSON() |
|
|
this.ServeJSON() |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
if userpwd == "" { |
|
|
if userpwd == "" { |
|
|
this.Data["json"] = models.ReurnError(1,"密码为空") |
|
|
this.Data["json"] = models.ReurnError(1, "密码为空") |
|
|
this.ServeJSON() |
|
|
this.ServeJSON() |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
if len(userpwd) < 6 { |
|
|
if len(userpwd) < 6 { |
|
|
this.Data["json"] = models.ReurnError(1,"密码最低6位") |
|
|
this.Data["json"] = models.ReurnError(1, "密码最低6位") |
|
|
this.ServeJSON() |
|
|
this.ServeJSON() |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
user, _ := service.FindByUserName(username) |
|
|
user, _ := service.FindByUserName(username) |
|
|
if user != nil { |
|
|
if user != nil { |
|
|
this.Data["json"] = models.ReurnError(1,"用户已经存在") |
|
|
this.Data["json"] = models.ReurnError(1, "用户已经存在") |
|
|
this.ServeJSON() |
|
|
this.ServeJSON() |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
@ -107,12 +133,12 @@ func (this *UserController) Regist() { |
|
|
h = md5.New() |
|
|
h = md5.New() |
|
|
h.Write([]byte(userpwd + salt)) |
|
|
h.Write([]byte(userpwd + salt)) |
|
|
userpwd = hex.EncodeToString(h.Sum(nil)) |
|
|
userpwd = hex.EncodeToString(h.Sum(nil)) |
|
|
user = &models.User{UserName: username,NickName:username, UserPwd: userpwd, Salt: salt} |
|
|
user = &models.User{UserName: username, NickName: username, UserPwd: userpwd, Salt: salt} |
|
|
err := service.SaveUser(user) |
|
|
err := service.SaveUser(user) |
|
|
if err == nil { |
|
|
if err == nil { |
|
|
this.Data["json"] = models.ReurnSuccess("") |
|
|
this.Data["json"] = models.ReurnSuccess("") |
|
|
} else { |
|
|
} else { |
|
|
this.Data["json"] = models.ReurnError(1,"注册失败") |
|
|
this.Data["json"] = models.ReurnError(1, "注册失败") |
|
|
} |
|
|
} |
|
|
this.ServeJSON() |
|
|
this.ServeJSON() |
|
|
return |
|
|
return |
|
@ -121,6 +147,6 @@ func (this *UserController) Regist() { |
|
|
func (this *UserController) Logout() { |
|
|
func (this *UserController) Logout() { |
|
|
this.DelSession("userid") |
|
|
this.DelSession("userid") |
|
|
this.DelSession("nickname") |
|
|
this.DelSession("nickname") |
|
|
this.Redirect("/",302) |
|
|
this.Redirect("/", 302) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |