Add dynamic admin panel for managing entities (#108)

This commit is contained in:
Mike Stefanello 2025-04-22 08:26:35 -04:00 committed by GitHub
parent 60009df0bf
commit 1a6874fd82
47 changed files with 2173 additions and 320 deletions

View file

@ -39,10 +39,10 @@ func (h *Auth) Init(c *services.Container) error {
}
func (h *Auth) Routes(g *echo.Group) {
g.GET("/logout", h.Logout, middleware.RequireAuthentication()).Name = routenames.Logout
g.GET("/logout", h.Logout, middleware.RequireAuthentication).Name = routenames.Logout
g.GET("/email/verify/:token", h.VerifyEmail).Name = routenames.VerifyEmail
noAuth := g.Group("/user", middleware.RequireNoAuthentication())
noAuth := g.Group("/user", middleware.RequireNoAuthentication)
noAuth.GET("/login", h.LoginPage).Name = routenames.Login
noAuth.POST("/login", h.LoginSubmit).Name = routenames.LoginSubmit
noAuth.GET("/register", h.RegisterPage).Name = routenames.Register
@ -206,18 +206,12 @@ func (h *Auth) RegisterSubmit(ctx echo.Context) error {
return err
}
// Hash the password.
pwHash, err := h.auth.HashPassword(input.Password)
if err != nil {
return fail(err, "unable to hash password")
}
// Attempt creating the user.
u, err := h.orm.User.
Create().
SetName(input.Name).
SetEmail(input.Email).
SetPassword(pwHash).
SetPassword(input.Password).
Save(ctx.Request().Context())
switch err.(type) {
@ -305,19 +299,13 @@ func (h *Auth) ResetPasswordSubmit(ctx echo.Context) error {
return err
}
// Hash the new password.
hash, err := h.auth.HashPassword(input.Password)
if err != nil {
return fail(err, "unable to hash password")
}
// Get the requesting user.
usr := ctx.Get(context.UserKey).(*ent.User)
// Update the user.
_, err = usr.
Update().
SetPassword(hash).
SetPassword(input.Password).
Save(ctx.Request().Context())
if err != nil {