use revel 1.0.0 && go module

This commit is contained in:
lealife
2021-03-26 14:19:53 +08:00
parent 5e61291703
commit 1b006b83ad
801 changed files with 228 additions and 207009 deletions

View File

@ -27,7 +27,7 @@ func (c *BaseController) Message(message string, args ...interface{}) (value str
func (c BaseController) GetUserId() string {
if userId, ok := c.Session["UserId"]; ok {
return userId
return userId.(string)
}
return ""
}
@ -47,51 +47,30 @@ func (c BaseController) GetObjectUserId() bson.ObjectId {
func (c BaseController) GetEmail() string {
if email, ok := c.Session["Email"]; ok {
return email
return email.(string)
}
return ""
}
func (c BaseController) GetUsername() string {
if email, ok := c.Session["Username"]; ok {
return email
return email.(string)
}
return ""
}
// 得到用户信息
func (c BaseController) GetUserInfo() info.User {
if userId, ok := c.Session["UserId"]; ok && userId != "" {
userId := c.GetUserId()
if userId != "" {
return userService.GetUserInfo(userId)
/*
notebookWidth, _ := strconv.Atoi(c.Session["NotebookWidth"])
noteListWidth, _ := strconv.Atoi(c.Session["NoteListWidth"])
mdEditorWidth, _ := strconv.Atoi(c.Session["MdEditorWidth"])
LogJ(c.Session)
user := info.User{UserId: bson.ObjectIdHex(userId),
Email: c.Session["Email"],
Logo: c.Session["Logo"],
Username: c.Session["Username"],
UsernameRaw: c.Session["UsernameRaw"],
Theme: c.Session["Theme"],
NotebookWidth: notebookWidth,
NoteListWidth: noteListWidth,
MdEditorWidth: mdEditorWidth,
}
if c.Session["Verified"] == "1" {
user.Verified = true
}
if c.Session["LeftIsMin"] == "1" {
user.LeftIsMin = true
}
return user
*/
}
return info.User{}
}
func (c BaseController) GetUserAndBlogUrl() info.UserAndBlogUrl {
if userId, ok := c.Session["UserId"]; ok && userId != "" {
userId := c.GetUserId()
if userId != "" {
return userService.GetUserAndBlogUrl(userId)
}
return info.UserAndBlogUrl{}
@ -103,7 +82,7 @@ func (c BaseController) GetSession(key string) string {
if !ok {
v = ""
}
return v
return v.(string)
}
func (c BaseController) SetSession(userInfo info.User) {
if userInfo.UserId.Hex() != "" {

View File

@ -110,7 +110,7 @@ func (c Blog) setPreviewUrl() {
if username != "" {
userIdOrEmail = username
}
themeId := c.Session["themeId"]
themeId := c.GetSession("themeId")
theme := themeService.GetTheme(userId, themeId)
// siteUrl := configService.GetSiteUrl()

View File

@ -34,7 +34,7 @@ func (c Captcha) Get() revel.Result {
out := io.Writer(c.Response.GetWriter())
image.WriteTo(out)
sessionId := c.Session["_ID"]
sessionId := c.GetSession("_ID")
// LogJ(c.Session)
// Log("------")
// Log(str)

View File

@ -25,7 +25,7 @@ func (c Preview) getPreviewThemeAbsolutePath(themeId string) bool {
if themeId != "" {
c.Session["themeId"] = themeId // 存到session中, 下次的url就不能带了, 待优化, 有时会取不到
} else {
themeId = c.Session["themeId"] // 直接从session中获取
themeId = c.GetSession("themeId") // 直接从session中获取
}
if themeId == "" {
return false

View File

@ -83,7 +83,7 @@ func AuthInterceptor(c *revel.Controller) revel.Result {
// 验证是否已登录
// 必须是管理员
if username, ok := c.Session["Username"]; ok && username == configService.GetAdminUsername() {
if username, ok := c.Session["Username"]; ok && username.(string) == configService.GetAdminUsername() {
return nil // 已登录
}

View File

@ -23,18 +23,18 @@ type ApiBaseContrller struct {
// 得到token, 这个token是在AuthInterceptor设到Session中的
func (c ApiBaseContrller) getToken() string {
return c.Session["_token"]
return c.GetSession("_token")
}
// userId
// _userId是在AuthInterceptor设置的
func (c ApiBaseContrller) getUserId() string {
return c.Session["_userId"]
return c.GetSession("_userId")
}
// 得到用户信息
func (c ApiBaseContrller) getUserInfo() info.User {
userId := c.Session["_userId"]
userId := c.GetSession("_userId")
if userId == "" {
return info.User{}
}

View File

@ -90,7 +90,10 @@ func AuthInterceptor(c *revel.Controller) revel.Result {
if noToken && userId == "" {
// 从session中获取, api/file/getImage, api/file/getAttach, api/file/getAllAttach
// 客户端
userId, _ = c.Session["UserId"]
userIdI, _ := c.Session["UserId"]
if userIdI != nil {
userId = userIdI.(string)
}
}
c.Session["_userId"] = userId