Remove fiber ctx
This commit is contained in:
@ -1,11 +1,8 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fiber-sessions/app/data"
|
||||
"fiber-sessions/app/router/requests"
|
||||
"fiber-sessions/app/templates"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
var pcLogin templates.PageContext = templates.PageContext{
|
||||
@ -13,19 +10,16 @@ var pcLogin templates.PageContext = templates.PageContext{
|
||||
ActivePage: "login",
|
||||
}
|
||||
|
||||
func Login(ctx *fiber.Ctx) error {
|
||||
request := requests.NewRequest(ctx, data.UsersStorage)
|
||||
Render(ctx, templates.RenderLogin(request, pcLogin))
|
||||
func Login(request *requests.Request) error {
|
||||
Render(request.Ctx, templates.RenderLogin(request, pcLogin))
|
||||
return nil
|
||||
}
|
||||
|
||||
func LoginSubmit(ctx *fiber.Ctx) error {
|
||||
request := requests.NewRequest(ctx, data.UsersStorage)
|
||||
|
||||
func LoginSubmit(request *requests.Request) error {
|
||||
content := templates.LoginFormValidationContent{
|
||||
Validated: true,
|
||||
Username: ctx.FormValue("username"),
|
||||
Password: ctx.FormValue("password"),
|
||||
Username: request.Ctx.FormValue("username"),
|
||||
Password: request.Ctx.FormValue("password"),
|
||||
}
|
||||
hasError := false
|
||||
|
||||
@ -42,12 +36,12 @@ func LoginSubmit(ctx *fiber.Ctx) error {
|
||||
if !hasError {
|
||||
err := request.LoginUser(content.Username, content.Password)
|
||||
if err == nil {
|
||||
ctx.Set("HX-Location", "/")
|
||||
request.Ctx.Set("HX-Location", "/")
|
||||
return nil
|
||||
}
|
||||
content.LoginError = "Invalid username or password"
|
||||
}
|
||||
|
||||
Render(ctx, templates.LoginFormContent(content))
|
||||
Render(request.Ctx, templates.LoginFormContent(content))
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user