(app *App, r *http.Request)
| 359 | } |
| 360 | |
| 361 | func 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 | |
| 398 | var fileRegex = regexp.MustCompile("/([^/]*\\.[^/]*)$") |
| 399 |
no test coverage detected