Added user registrations page

This commit is contained in:
2018-04-16 15:17:23 +02:00
parent b49496fe16
commit 802273b7c3
6 changed files with 79 additions and 0 deletions

View File

@ -2,6 +2,7 @@ component AdminTabs
.tabs
Tab("Server", "server", "/admin")
Tab("WebDev", "html5", "/admin/webdev")
Tab("Registrations", "user-plus", "/admin/registrations")
Tab("Purchases", "shopping-cart", "/admin/purchases")
.corner-buttons

View File

@ -0,0 +1,56 @@
package admin
import (
"net/http"
"sort"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
"github.com/fatih/color"
)
// UserRegistrations ...
func UserRegistrations(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
}
if user.Role != "admin" {
return ctx.Error(http.StatusUnauthorized, "Not authorized", nil)
}
yearInfo := map[int]utils.YearRegistrations{}
years := []int{}
for user := range arn.StreamUsers() {
if user.Registered == "" {
color.Red("%s %s", user.ID, user.Nick)
user.Registered = user.LastLogin
user.Save()
}
registered := user.RegisteredTime()
year := registered.Year()
yearRegistrations := yearInfo[year]
yearRegistrations.Total++
if yearRegistrations.Months == nil {
yearRegistrations.Months = map[int]int{}
}
yearRegistrations.Months[int(registered.Month())]++
yearInfo[year] = yearRegistrations
}
for year := range yearInfo {
years = append(years, year)
}
sort.Ints(years)
return ctx.HTML(components.UserRegistrations(years, yearInfo))
}

View File

@ -0,0 +1,11 @@
component UserRegistrations(years []int, yearInfo map[int]utils.YearRegistrations)
AdminTabs
h1.page-title User registrations
for _, year := range years
h3.mountable= year
h4.mountable= strconv.Itoa(yearInfo[year].Total) + " registrations"
for month := 1; month <= 12; month++
p.mountable
strong= time.Month(month).String() + ": "
span= strconv.Itoa(yearInfo[year].Months[month])