diff options
author | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-06-25 19:09:54 +0200 |
---|---|---|
committer | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-06-25 19:51:55 +0200 |
commit | 249ee195ce52ee4a4defeb67a33ef353919d3a11 (patch) | |
tree | 24ffcfa3a852b0464fc0344cfc79bc5efb272a3e /pkg/view | |
parent | 91d413b3a15a15fd8b710d8f5a1532d2e3de6f05 (diff) | |
download | lens-249ee195ce52ee4a4defeb67a33ef353919d3a11.tar.gz lens-249ee195ce52ee4a4defeb67a33ef353919d3a11.tar.bz2 lens-249ee195ce52ee4a4defeb67a33ef353919d3a11.zip |
feat: Add user list UI
Fill user settings UI with actual data.
Diffstat (limited to 'pkg/view')
-rw-r--r-- | pkg/view/auth.go | 20 | ||||
-rw-r--r-- | pkg/view/settings.go | 42 |
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, }) |