Start adding memory login provider

This commit is contained in:
Melon 2025-01-25 16:08:59 +00:00
parent 0df2cf6681
commit 3fbe905cb2
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
2 changed files with 37 additions and 0 deletions

33
auth/providers/memory.go Normal file
View File

@ -0,0 +1,33 @@
package providers
import (
"github.com/1f349/lavender/auth"
"github.com/1f349/lavender/auth/authContext"
"github.com/1f349/lavender/web"
)
var _ auth.Provider = (*MemoryLogin)(nil)
type MemoryLogin struct{}
func (m *MemoryLogin) AccessState() auth.State { return auth.StateUnauthorized }
func (m *MemoryLogin) Name() string { return "memory" }
func (m *MemoryLogin) RenderTemplate(ctx authContext.TemplateContext) error {
cookie, err := ctx.Request().Cookie("lavender-user-memory")
if err == nil && cookie.Valid() == nil {
ctx.Render(struct {
ServiceName string
LoginName string
Redirect string
}{
ServiceName: ,
})
}
}
func (m *MemoryLogin) AttemptLogin(ctx authContext.TemplateContext) error {
//TODO implement me
panic("implement me")
}

View File

@ -91,6 +91,8 @@ func (h *httpServer) loginGet(rw http.ResponseWriter, req *http.Request, _ httpr
return
}
// TODO: some of this should be more like tulip
cookie, err := req.Cookie("lavender-login-name")
if err == nil && cookie.Valid() == nil {
user, err := h.db.GetUser(req.Context(), userAuth.Subject)
@ -158,6 +160,8 @@ func (h *httpServer) loginPost(rw http.ResponseWriter, req *http.Request, _ http
return
}
// TODO: some of this should be more like tulip
if req.PostFormValue("not-you") == "1" {
http.SetCookie(rw, &http.Cookie{
Name: "lavender-login-name",