38 lines
765 B
Go
38 lines
765 B
Go
package routes
|
|
|
|
import (
|
|
"dk/internal/middleware"
|
|
"dk/internal/router"
|
|
"dk/internal/template/components"
|
|
"dk/internal/users"
|
|
"fmt"
|
|
|
|
"github.com/valyala/fasthttp"
|
|
)
|
|
|
|
func Index(ctx router.Ctx, _ []string) {
|
|
currentUser := middleware.GetCurrentUser(ctx)
|
|
var username string
|
|
if currentUser != nil {
|
|
username = currentUser.Username
|
|
user, _ := users.Find(currentUser.ID)
|
|
|
|
if user.Currently == "In Town" {
|
|
ctx.Redirect("/town", 303)
|
|
}
|
|
} else {
|
|
username = "Guest"
|
|
}
|
|
|
|
pageData := components.NewPageData(
|
|
"Dragon Knight",
|
|
fmt.Sprintf("Hello %s!", username),
|
|
)
|
|
|
|
if err := components.RenderPage(ctx, pageData, nil); err != nil {
|
|
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
|
|
fmt.Fprintf(ctx, "Template error: %v", err)
|
|
return
|
|
}
|
|
}
|