MCPcopy Index your code
hub / github.com/writefreely/writefreely / handleViewAdminUser

Function handleViewAdminUser

admin.go:234–319  ·  view source on GitHub ↗
(app *App, u *User, w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

232}
233
234func handleViewAdminUser(app *App, u *User, w http.ResponseWriter, r *http.Request) error {
235 vars := mux.Vars(r)
236 username := vars["username"]
237 if username == "" {
238 return impart.HTTPError{http.StatusFound, "/admin/users"}
239 }
240
241 p := struct {
242 *UserPage
243 *AdminPage
244 Config config.AppCfg
245 Message string
246
247 User *User
248 Colls []inspectedCollection
249 LastPost string
250 NewPassword string
251 TotalPosts int64
252 ClearEmail string
253 }{
254 AdminPage: NewAdminPage(app),
255 Config: app.cfg.App,
256 Message: r.FormValue("m"),
257 Colls: []inspectedCollection{},
258 }
259
260 var err error
261 p.User, err = app.db.GetUserForAuth(username)
262 if err != nil {
263 if err == ErrUserNotFound {
264 return err
265 }
266 log.Error("Could not get user: %v", err)
267 return impart.HTTPError{http.StatusInternalServerError, err.Error()}
268 }
269
270 flashes, _ := getSessionFlashes(app, w, r, nil)
271 for _, flash := range flashes {
272 if strings.HasPrefix(flash, "SUCCESS: ") {
273 p.NewPassword = strings.TrimPrefix(flash, "SUCCESS: ")
274 p.ClearEmail = p.User.EmailClear(app.keys)
275 }
276 }
277 p.UserPage = NewUserPage(app, r, u, p.User.Username, nil)
278 p.TotalPosts = app.db.GetUserPostsCount(p.User.ID)
279 lp, err := app.db.GetUserLastPostTime(p.User.ID)
280 if err != nil {
281 return impart.HTTPError{http.StatusInternalServerError, fmt.Sprintf("Could not get user's last post time: %v", err)}
282 }
283 if lp != nil {
284 p.LastPost = lp.Format("January 2, 2006, 3:04 PM")
285 }
286
287 colls, err := app.db.GetCollections(p.User, app.cfg.App.Host)
288 if err != nil {
289 return impart.HTTPError{http.StatusInternalServerError, fmt.Sprintf("Could not get user's collections: %v", err)}
290 }
291 for _, c := range *colls {

Callers

nothing calls this directly

Calls 13

NewAdminPageFunction · 0.85
getSessionFlashesFunction · 0.85
NewUserPageFunction · 0.85
showUserPageFunction · 0.85
EmailClearMethod · 0.80
GetUserPostsCountMethod · 0.80
FormatMethod · 0.80
GetUserForAuthMethod · 0.65
GetUserLastPostTimeMethod · 0.65
GetCollectionsMethod · 0.65
GetAPFollowersMethod · 0.65
GetPostsCountMethod · 0.65

Tested by

no test coverage detected