Convert RenderButtonTemplate to TemplateContext

This commit is contained in:
Melon 2025-01-26 01:47:46 +00:00
parent db0ad159fb
commit 7760129db2
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
2 changed files with 13 additions and 10 deletions

View File

@ -11,7 +11,6 @@ import (
"github.com/1f349/lavender/url"
"github.com/google/uuid"
"golang.org/x/oauth2"
"html/template"
"net/http"
"time"
)
@ -101,11 +100,16 @@ func (o OAuthLogin) OAuthCallback(rw http.ResponseWriter, req *http.Request, inf
redirect(rw, req)
}
func (o OAuthLogin) ButtonName() string { return o.Name() }
func (o OAuthLogin) RenderButtonTemplate(ctx context.Context, req *http.Request) template.HTML {
func (o OAuthLogin) RenderButtonTemplate(ctx authContext.TemplateContext) {
// o.authUrlBase("button")
return "<div>OAuth Login Template</div>"
// provide something non-nil
ctx.Render(struct {
Href string
ButtonName string
}{
Href: o.authUrlBase("button").String(),
ButtonName: "Login with Unknown OAuth Button", // TODO: actually get the service name
})
}
type oauthServiceLogin int

View File

@ -1,10 +1,8 @@
package providers
import (
"context"
"github.com/1f349/lavender/auth"
"html/template"
"net/http"
"github.com/1f349/lavender/auth/authContext"
)
type passkeyLoginDB interface {
@ -24,6 +22,7 @@ func (p *PasskeyLogin) AccessState() auth.State { return auth.StateUnauthorized
func (p *PasskeyLogin) Name() string { return "passkey" }
func (p *PasskeyLogin) RenderButtonTemplate(ctx context.Context, req *http.Request) template.HTML {
return "<div>Passkey Button</div>"
func (p *PasskeyLogin) RenderButtonTemplate(ctx authContext.TemplateContext) {
// provide something non-nil
ctx.Render(struct{}{})
}