MCPcopy
hub / github.com/writefreely/writefreely / pageForReq

Function pageForReq

app.go:361–396  ·  view source on GitHub ↗
(app *App, r *http.Request)

Source from the content-addressed store, hash-verified

359}
360
361func pageForReq(app *App, r *http.Request) page.StaticPage {
362 p := page.StaticPage{
363 AppCfg: app.cfg.App,
364 Path: r.URL.Path,
365 Version: "v" + softwareVer,
366 }
367
368 // Use custom style, if file exists
369 if _, err := os.Stat(filepath.Join(app.cfg.Server.StaticParentDir, staticDir, "local", "custom.css")); err == nil {
370 p.CustomCSS = true
371 }
372
373 // Add user information, if given
374 var u *User
375 accessToken := r.FormValue("t")
376 if accessToken != "" {
377 userID := app.db.GetUserID(accessToken)
378 if userID != -1 {
379 var err error
380 u, err = app.db.GetUserByID(userID)
381 if err == nil {
382 p.Username = u.Username
383 }
384 }
385 } else {
386 u = getUserSession(app, r)
387 if u != nil {
388 p.Username = u.Username
389 p.IsAdmin = u != nil && u.IsAdmin()
390 p.CanInvite = canUserInvite(app.cfg, p.IsAdmin)
391 }
392 }
393 p.CanViewReader = !app.cfg.App.Private || u != nil
394
395 return p
396}
397
398var fileRegex = regexp.MustCompile("/([^/]*\\.[^/]*)$")
399

Callers 15

handleViewPostFunction · 0.85
viewCollectionPostFunction · 0.85
NewUserPageFunction · 0.85
viewLoginFunction · 0.85
viewResetPasswordFunction · 0.85
UserMethod · 0.85
AdminMethod · 0.85
AdminApperMethod · 0.85
PageMethod · 0.85
WebErrorsMethod · 0.85
WebMethod · 0.85
DownloadMethod · 0.85

Calls 5

IsAdminMethod · 0.95
getUserSessionFunction · 0.85
canUserInviteFunction · 0.85
GetUserIDMethod · 0.65
GetUserByIDMethod · 0.65

Tested by

no test coverage detected