aboutsummaryrefslogtreecommitdiff
path: root/pkg/view
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/view')
-rw-r--r--pkg/view/auth.go20
-rw-r--r--pkg/view/settings.go42
2 files changed, 32 insertions, 30 deletions
diff --git a/pkg/view/auth.go b/pkg/view/auth.go
index 5c83eba..d44424d 100644
--- a/pkg/view/auth.go
+++ b/pkg/view/auth.go
@@ -64,23 +64,6 @@ func (v *AuthView) Login(ctx *fasthttp.RequestCtx) error {
return nil
}
-func (v *AuthView) RegisterView(ctx *fasthttp.RequestCtx) error {
- return img.Render[interface{}](ctx, "register.html", nil)
-}
-
-func (v *AuthView) Register(ctx *fasthttp.RequestCtx) error {
- username := ctx.FormValue("username")
- password := ctx.FormValue("password")
-
- err := v.userController.Register(ctx, username, password)
- if err != nil {
- return err
- }
-
- ctx.Redirect("/login", 307)
- return nil
-}
-
func Index(ctx *fasthttp.RequestCtx) {
ctx.Redirect("/login", 307)
}
@@ -89,9 +72,6 @@ func (v *AuthView) SetMyselfIn(r *ext.Router) {
r.GET("/login", v.LoginView)
r.POST("/login", v.Login)
- r.GET("/register", v.RegisterView)
- r.POST("/register", v.Register)
-
r.GET("/logout", v.Logout)
r.POST("/logout", v.Logout)
}
diff --git a/pkg/view/settings.go b/pkg/view/settings.go
index 746dee4..e5acb1b 100644
--- a/pkg/view/settings.go
+++ b/pkg/view/settings.go
@@ -5,28 +5,50 @@ import (
"git.sr.ht/~gabrielgio/img"
"git.sr.ht/~gabrielgio/img/pkg/components/settings"
+ "git.sr.ht/~gabrielgio/img/pkg/components/user"
"git.sr.ht/~gabrielgio/img/pkg/ext"
)
-type SettingsView struct {
- // there is not need to create a controller for this
- repository settings.Repository
-}
+type (
+ SettingsView struct {
+ // there is not need to create a controller for this
+ settingsRepository settings.Repository
+ userRepository user.Repository
+ }
+
+ SettingsPage struct {
+ Settings *settings.Settings
+ Users []*user.User
+ }
+)
-func NewSettingsView(respository settings.Repository) *SettingsView {
+func NewSettingsView(
+ settingsRespository settings.Repository,
+ userRepository user.Repository,
+) *SettingsView {
return &SettingsView{
- repository: respository,
+ settingsRepository: settingsRespository,
+ userRepository: userRepository,
}
}
func (self *SettingsView) Index(ctx *fasthttp.RequestCtx) error {
- s, err := self.repository.Load(ctx)
+ s, err := self.settingsRepository.Load(ctx)
if err != nil {
return err
}
- return img.Render(ctx, "settings.html", &img.HTMLView[*settings.Settings]{
+
+ users, err := self.userRepository.List(ctx)
+ if err != nil {
+ return err
+ }
+
+ return img.Render(ctx, "settings.html", &img.HTMLView[*SettingsPage]{
Title: "Settings",
- Data: s,
+ Data: &SettingsPage{
+ Settings: s,
+ Users: users,
+ },
})
}
@@ -36,7 +58,7 @@ func (self *SettingsView) Save(ctx *fasthttp.RequestCtx) error {
showOwner = string(ctx.FormValue("showOwner")) == "on"
)
- err := self.repository.Save(ctx, &settings.Settings{
+ err := self.settingsRepository.Save(ctx, &settings.Settings{
ShowMode: showMode,
ShowOwner: showOwner,
})