MCPcopy Index your code
hub / github.com/TruthHun/BookStack / isBookOwner

Method isBookOwner

controllers/StaticController.go:126–176  ·  view source on GitHub ↗

是否是书籍项目所有人(书籍项目所有人,可以直链播放音视频)

()

Source from the content-addressed store, hash-verified

124
125// 是否是书籍项目所有人(书籍项目所有人,可以直链播放音视频)
126func (this *StaticController) isBookOwner() (yes bool) {
127 memberID := 0
128 // 从session中获取用户信息
129 if member, ok := this.GetSession(conf.LoginSessionName).(models.Member); ok {
130 memberID = member.MemberId
131 }
132
133 if memberID <= 0 {
134 // 如果Cookie中存在登录信息,从cookie中获取用户信息
135 if cookie, ok := this.GetSecureCookie(conf.GetAppKey(), "login"); ok {
136 var remember CookieRemember
137 if err := utils.Decode(cookie, &remember); err == nil {
138 memberID = remember.MemberId
139 }
140 }
141 }
142 if memberID <= 0 {
143 return
144 }
145
146 referer := this.Ctx.Request.Referer()
147 if referer == "" {
148 return
149 }
150
151 bookIdentify := ""
152 if u, err := url.Parse(referer); err == nil {
153 fmt.Println(u.Path)
154 if slice := strings.Split(u.Path, "/"); len(slice) >= 3 && slice[1] == "api" {
155 bookIdentify = slice[2]
156 }
157 }
158
159 if bookIdentify == "" {
160 return
161 }
162
163 bookID := 0
164 if book, err := models.NewBook().FindByIdentify(bookIdentify, "book_id"); err == nil {
165 bookID = book.BookId
166 }
167 if bookID <= 0 {
168 return
169 }
170
171 if r, err := models.NewRelationship().FindByBookIdAndMemberId(bookID, memberID); err == nil && r.RelationshipId > 0 {
172 return true
173 }
174
175 return false
176}
177
178// 是否是合法的签名(针对音频和视频,签名不可用的时候再验证用户有没有登录,用户登录了再验证用户是不是书籍所有人)
179func (this *StaticController) isValidSign(sign, path string) bool {

Callers 2

UploadsMethod · 0.95
ProjectsFileMethod · 0.95

Calls 6

GetAppKeyFunction · 0.92
DecodeFunction · 0.92
NewBookFunction · 0.92
NewRelationshipFunction · 0.92
FindByIdentifyMethod · 0.45

Tested by

no test coverage detected