✨ Added HTTP delivery for client package
This commit is contained in:
parent
32e9618730
commit
4a7d6cc4b5
6 changed files with 636 additions and 156 deletions
71
internal/client/delivery/http/home_http.go
Normal file
71
internal/client/delivery/http/home_http.go
Normal file
|
@ -0,0 +1,71 @@
|
|||
package http
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"strings"
|
||||
|
||||
"github.com/fasthttp/router"
|
||||
http "github.com/valyala/fasthttp"
|
||||
"golang.org/x/text/language"
|
||||
"golang.org/x/text/message"
|
||||
|
||||
"source.toby3d.me/website/oauth/internal/common"
|
||||
"source.toby3d.me/website/oauth/internal/domain"
|
||||
"source.toby3d.me/website/oauth/internal/random"
|
||||
"source.toby3d.me/website/oauth/web"
|
||||
)
|
||||
|
||||
type RequestHandler struct {
|
||||
client *domain.Client
|
||||
config *domain.Config
|
||||
matcher language.Matcher
|
||||
}
|
||||
|
||||
const DefaultStateLength int = 64
|
||||
|
||||
func NewRequestHandler(config *domain.Config, client *domain.Client, matcher language.Matcher) *RequestHandler {
|
||||
return &RequestHandler{
|
||||
client: client,
|
||||
config: config,
|
||||
matcher: matcher,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *RequestHandler) Register(r *router.Router) {
|
||||
r.GET("/", h.read)
|
||||
}
|
||||
|
||||
func (h *RequestHandler) read(ctx *http.RequestCtx) {
|
||||
ctx.SetContentType(common.MIMETextHTMLCharsetUTF8)
|
||||
|
||||
// TODO(toby3d): save state for checking it at the end of flow?
|
||||
state, err := random.Bytes(DefaultStateLength)
|
||||
if err != nil {
|
||||
ctx.Error(err.Error(), http.StatusInternalServerError)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
redirectUri := make([]string, len(h.client.RedirectURI))
|
||||
for i := range h.client.RedirectURI {
|
||||
redirectUri[i] = h.client.RedirectURI[i].String()
|
||||
}
|
||||
|
||||
tags, _, _ := language.ParseAcceptLanguage(string(ctx.Request.Header.Peek(http.HeaderAcceptLanguage)))
|
||||
tag, _, _ := h.matcher.Match(tags...)
|
||||
|
||||
ctx.Response.Header.Set(
|
||||
http.HeaderLink, `<`+strings.Join(redirectUri, `>; rel="redirect_uri", `)+`>; rel="redirect_uri"`,
|
||||
)
|
||||
web.WriteTemplate(ctx, &web.HomePage{
|
||||
BaseOf: web.BaseOf{
|
||||
Config: h.config,
|
||||
Language: tag,
|
||||
Printer: message.NewPrinter(tag),
|
||||
},
|
||||
RedirectURI: h.client.RedirectURI,
|
||||
AuthEndpoint: "/authorize",
|
||||
Client: h.client,
|
||||
State: base64.RawURLEncoding.EncodeToString(state),
|
||||
})
|
||||
}
|
37
internal/client/delivery/http/home_http_test.go
Normal file
37
internal/client/delivery/http/home_http_test.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package http_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/fasthttp/router"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
http "github.com/valyala/fasthttp"
|
||||
"golang.org/x/text/language"
|
||||
"golang.org/x/text/message"
|
||||
|
||||
delivery "source.toby3d.me/website/oauth/internal/client/delivery/http"
|
||||
"source.toby3d.me/website/oauth/internal/domain"
|
||||
"source.toby3d.me/website/oauth/internal/testing/httptest"
|
||||
)
|
||||
|
||||
func TestRead(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := router.New()
|
||||
delivery.NewRequestHandler(
|
||||
domain.TestConfig(t), domain.TestClient(t), language.NewMatcher(message.DefaultCatalog.Languages()),
|
||||
).Register(r)
|
||||
|
||||
client, _, cleanup := httptest.New(t, r.Handler)
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "https://app.example.com/", nil)
|
||||
defer http.ReleaseRequest(req)
|
||||
|
||||
resp := http.AcquireResponse()
|
||||
defer http.ReleaseResponse(resp)
|
||||
|
||||
require.NoError(t, client.Do(req, resp))
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode())
|
||||
}
|
|
@ -1,33 +1,88 @@
|
|||
{% import (
|
||||
"golang.org/x/text/language"
|
||||
"golang.org/x/text/message"
|
||||
|
||||
"source.toby3d.me/website/oauth/internal/domain"
|
||||
) %}
|
||||
|
||||
{% interface Page {
|
||||
Body()
|
||||
Head()
|
||||
Lang()
|
||||
Title()
|
||||
Head()
|
||||
Body()
|
||||
Title()
|
||||
} %}
|
||||
|
||||
{% code
|
||||
type BaseOf struct {}
|
||||
type BaseOf struct {
|
||||
Config *domain.Config
|
||||
Language language.Tag
|
||||
Printer *message.Printer
|
||||
}
|
||||
%}
|
||||
|
||||
{% func (p *BaseOf) Lang() %}en{% endfunc %}
|
||||
{% stripspace %}
|
||||
{% func (p *BaseOf) Lang() %}
|
||||
{% if p.Language != language.Und %}
|
||||
{%s p.Language.String() %}
|
||||
{% else %}
|
||||
en
|
||||
{% endif %}
|
||||
{% endfunc %}
|
||||
{% endstripspace %}
|
||||
|
||||
{% func (p *BaseOf) Title() %}Title{% endfunc %}
|
||||
{% collapsespace %}
|
||||
{% func (p *BaseOf) Title() %}
|
||||
{%s p.Config.Name %}
|
||||
{% endfunc %}
|
||||
|
||||
{% func (p *BaseOf) Head() %}{% endfunc %}
|
||||
{% func (p *BaseOf) Head() %}
|
||||
{% comment %}https://evilmartians.com/chronicles/how-to-favicon-in-2021-six-files-that-fit-most-needs{% endcomment %}
|
||||
<link
|
||||
rel="icon"
|
||||
href="{%s p.Config.Server.StaticURLPrefix %}/favicon.ico"
|
||||
sizes="any">
|
||||
|
||||
<link
|
||||
rel="icon"
|
||||
href="{%s p.Config.Server.StaticURLPrefix %}/icon.svg"
|
||||
type="image/svg+xml">
|
||||
|
||||
<link
|
||||
rel="apple-touch-icon"
|
||||
href="{%s p.Config.Server.StaticURLPrefix %}/apple-touch-icon.png">
|
||||
|
||||
<link
|
||||
rel="manifest"
|
||||
href="{%s p.Config.Server.StaticURLPrefix %}/manifest.webmanifest">
|
||||
{% endfunc %}
|
||||
|
||||
{% func (p *BaseOf) Body() %}{% endfunc %}
|
||||
|
||||
{% func PageTemplate(p Page) %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="{%= p.Lang() %}">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{%= p.Title() %}</title>
|
||||
{%= p.Head() %}
|
||||
</head>
|
||||
<body>
|
||||
{%= p.Body() %}
|
||||
</body>
|
||||
</html>
|
||||
{% endfunc %}
|
||||
{% func Template(p Page) %}
|
||||
<!DOCTYPE html>
|
||||
<html
|
||||
class="page"
|
||||
lang="{%= p.Lang() %}">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1.0">
|
||||
|
||||
{%= p.Head() %}
|
||||
<title>{%= p.Title() %}</title>
|
||||
</head>
|
||||
<body class="page__body body">
|
||||
{%= p.Body() %}
|
||||
</body>
|
||||
</html>
|
||||
{% endfunc %}
|
||||
|
||||
{% func (p *BaseOf) T(str string, args ...interface{}) %}
|
||||
{% code
|
||||
result := p.Printer.Sprintf(str, args...)
|
||||
%}
|
||||
{%s result %}
|
||||
{% endfunc %}
|
||||
{% endcollapsespace %}
|
||||
|
|
|
@ -1,240 +1,313 @@
|
|||
// Code generated by qtc from "baseof.qtpl". DO NOT EDIT.
|
||||
// See https://github.com/valyala/quicktemplate for details.
|
||||
|
||||
//line ../../web/baseof.qtpl:1
|
||||
//line web/baseof.qtpl:1
|
||||
package web
|
||||
|
||||
//line ../../web/baseof.qtpl:1
|
||||
//line web/baseof.qtpl:1
|
||||
import (
|
||||
"golang.org/x/text/language"
|
||||
"golang.org/x/text/message"
|
||||
|
||||
"source.toby3d.me/website/oauth/internal/domain"
|
||||
)
|
||||
|
||||
//line web/baseof.qtpl:8
|
||||
import (
|
||||
qtio422016 "io"
|
||||
|
||||
qt422016 "github.com/valyala/quicktemplate"
|
||||
)
|
||||
|
||||
//line ../../web/baseof.qtpl:1
|
||||
//line web/baseof.qtpl:8
|
||||
var (
|
||||
_ = qtio422016.Copy
|
||||
_ = qt422016.AcquireByteBuffer
|
||||
)
|
||||
|
||||
//line ../../web/baseof.qtpl:1
|
||||
//line web/baseof.qtpl:8
|
||||
type Page interface {
|
||||
//line ../../web/baseof.qtpl:1
|
||||
Lang() string
|
||||
//line ../../web/baseof.qtpl:1
|
||||
StreamLang(qw422016 *qt422016.Writer)
|
||||
//line ../../web/baseof.qtpl:1
|
||||
WriteLang(qq422016 qtio422016.Writer)
|
||||
//line ../../web/baseof.qtpl:1
|
||||
Title() string
|
||||
//line ../../web/baseof.qtpl:1
|
||||
StreamTitle(qw422016 *qt422016.Writer)
|
||||
//line ../../web/baseof.qtpl:1
|
||||
WriteTitle(qq422016 qtio422016.Writer)
|
||||
//line ../../web/baseof.qtpl:1
|
||||
Head() string
|
||||
//line ../../web/baseof.qtpl:1
|
||||
StreamHead(qw422016 *qt422016.Writer)
|
||||
//line ../../web/baseof.qtpl:1
|
||||
WriteHead(qq422016 qtio422016.Writer)
|
||||
//line ../../web/baseof.qtpl:1
|
||||
//line web/baseof.qtpl:8
|
||||
Body() string
|
||||
//line ../../web/baseof.qtpl:1
|
||||
//line web/baseof.qtpl:8
|
||||
StreamBody(qw422016 *qt422016.Writer)
|
||||
//line ../../web/baseof.qtpl:1
|
||||
//line web/baseof.qtpl:8
|
||||
WriteBody(qq422016 qtio422016.Writer)
|
||||
//line ../../web/baseof.qtpl:1
|
||||
//line web/baseof.qtpl:8
|
||||
Head() string
|
||||
//line web/baseof.qtpl:8
|
||||
StreamHead(qw422016 *qt422016.Writer)
|
||||
//line web/baseof.qtpl:8
|
||||
WriteHead(qq422016 qtio422016.Writer)
|
||||
//line web/baseof.qtpl:8
|
||||
Lang() string
|
||||
//line web/baseof.qtpl:8
|
||||
StreamLang(qw422016 *qt422016.Writer)
|
||||
//line web/baseof.qtpl:8
|
||||
WriteLang(qq422016 qtio422016.Writer)
|
||||
//line web/baseof.qtpl:8
|
||||
Title() string
|
||||
//line web/baseof.qtpl:8
|
||||
StreamTitle(qw422016 *qt422016.Writer)
|
||||
//line web/baseof.qtpl:8
|
||||
WriteTitle(qq422016 qtio422016.Writer)
|
||||
//line web/baseof.qtpl:8
|
||||
}
|
||||
|
||||
//line ../../web/baseof.qtpl:9
|
||||
type BaseOf struct{}
|
||||
//line web/baseof.qtpl:16
|
||||
type BaseOf struct {
|
||||
Config *domain.Config
|
||||
Language language.Tag
|
||||
Printer *message.Printer
|
||||
}
|
||||
|
||||
//line ../../web/baseof.qtpl:12
|
||||
//line web/baseof.qtpl:24
|
||||
func (p *BaseOf) StreamLang(qw422016 *qt422016.Writer) {
|
||||
//line ../../web/baseof.qtpl:12
|
||||
qw422016.N().S(`en`)
|
||||
//line ../../web/baseof.qtpl:12
|
||||
//line web/baseof.qtpl:25
|
||||
if p.Language != language.Und {
|
||||
//line web/baseof.qtpl:26
|
||||
qw422016.E().S(p.Language.String())
|
||||
//line web/baseof.qtpl:27
|
||||
} else {
|
||||
//line web/baseof.qtpl:27
|
||||
qw422016.N().S(`en`)
|
||||
//line web/baseof.qtpl:29
|
||||
}
|
||||
//line web/baseof.qtpl:30
|
||||
}
|
||||
|
||||
//line ../../web/baseof.qtpl:12
|
||||
//line web/baseof.qtpl:30
|
||||
func (p *BaseOf) WriteLang(qq422016 qtio422016.Writer) {
|
||||
//line ../../web/baseof.qtpl:12
|
||||
//line web/baseof.qtpl:30
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line ../../web/baseof.qtpl:12
|
||||
//line web/baseof.qtpl:30
|
||||
p.StreamLang(qw422016)
|
||||
//line ../../web/baseof.qtpl:12
|
||||
//line web/baseof.qtpl:30
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line ../../web/baseof.qtpl:12
|
||||
//line web/baseof.qtpl:30
|
||||
}
|
||||
|
||||
//line ../../web/baseof.qtpl:12
|
||||
//line web/baseof.qtpl:30
|
||||
func (p *BaseOf) Lang() string {
|
||||
//line ../../web/baseof.qtpl:12
|
||||
//line web/baseof.qtpl:30
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line ../../web/baseof.qtpl:12
|
||||
//line web/baseof.qtpl:30
|
||||
p.WriteLang(qb422016)
|
||||
//line ../../web/baseof.qtpl:12
|
||||
//line web/baseof.qtpl:30
|
||||
qs422016 := string(qb422016.B)
|
||||
//line ../../web/baseof.qtpl:12
|
||||
//line web/baseof.qtpl:30
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line ../../web/baseof.qtpl:12
|
||||
//line web/baseof.qtpl:30
|
||||
return qs422016
|
||||
//line ../../web/baseof.qtpl:12
|
||||
//line web/baseof.qtpl:30
|
||||
}
|
||||
|
||||
//line ../../web/baseof.qtpl:14
|
||||
//line web/baseof.qtpl:34
|
||||
func (p *BaseOf) StreamTitle(qw422016 *qt422016.Writer) {
|
||||
//line ../../web/baseof.qtpl:14
|
||||
qw422016.N().S(`Title`)
|
||||
//line ../../web/baseof.qtpl:14
|
||||
//line web/baseof.qtpl:34
|
||||
qw422016.N().S(` `)
|
||||
//line web/baseof.qtpl:35
|
||||
qw422016.E().S(p.Config.Name)
|
||||
//line web/baseof.qtpl:35
|
||||
qw422016.N().S(` `)
|
||||
//line web/baseof.qtpl:36
|
||||
}
|
||||
|
||||
//line ../../web/baseof.qtpl:14
|
||||
//line web/baseof.qtpl:36
|
||||
func (p *BaseOf) WriteTitle(qq422016 qtio422016.Writer) {
|
||||
//line ../../web/baseof.qtpl:14
|
||||
//line web/baseof.qtpl:36
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line ../../web/baseof.qtpl:14
|
||||
//line web/baseof.qtpl:36
|
||||
p.StreamTitle(qw422016)
|
||||
//line ../../web/baseof.qtpl:14
|
||||
//line web/baseof.qtpl:36
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line ../../web/baseof.qtpl:14
|
||||
//line web/baseof.qtpl:36
|
||||
}
|
||||
|
||||
//line ../../web/baseof.qtpl:14
|
||||
//line web/baseof.qtpl:36
|
||||
func (p *BaseOf) Title() string {
|
||||
//line ../../web/baseof.qtpl:14
|
||||
//line web/baseof.qtpl:36
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line ../../web/baseof.qtpl:14
|
||||
//line web/baseof.qtpl:36
|
||||
p.WriteTitle(qb422016)
|
||||
//line ../../web/baseof.qtpl:14
|
||||
//line web/baseof.qtpl:36
|
||||
qs422016 := string(qb422016.B)
|
||||
//line ../../web/baseof.qtpl:14
|
||||
//line web/baseof.qtpl:36
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line ../../web/baseof.qtpl:14
|
||||
//line web/baseof.qtpl:36
|
||||
return qs422016
|
||||
//line ../../web/baseof.qtpl:14
|
||||
//line web/baseof.qtpl:36
|
||||
}
|
||||
|
||||
//line ../../web/baseof.qtpl:16
|
||||
//line web/baseof.qtpl:38
|
||||
func (p *BaseOf) StreamHead(qw422016 *qt422016.Writer) {
|
||||
//line ../../web/baseof.qtpl:16
|
||||
//line web/baseof.qtpl:38
|
||||
qw422016.N().S(` `)
|
||||
//line web/baseof.qtpl:39
|
||||
qw422016.N().S(` <link rel="icon" href="`)
|
||||
//line web/baseof.qtpl:42
|
||||
qw422016.E().S(p.Config.Server.StaticURLPrefix)
|
||||
//line web/baseof.qtpl:42
|
||||
qw422016.N().S(`/favicon.ico" sizes="any"> <link rel="icon" href="`)
|
||||
//line web/baseof.qtpl:47
|
||||
qw422016.E().S(p.Config.Server.StaticURLPrefix)
|
||||
//line web/baseof.qtpl:47
|
||||
qw422016.N().S(`/icon.svg" type="image/svg+xml"> <link rel="apple-touch-icon" href="`)
|
||||
//line web/baseof.qtpl:52
|
||||
qw422016.E().S(p.Config.Server.StaticURLPrefix)
|
||||
//line web/baseof.qtpl:52
|
||||
qw422016.N().S(`/apple-touch-icon.png"> <link rel="manifest" href="`)
|
||||
//line web/baseof.qtpl:56
|
||||
qw422016.E().S(p.Config.Server.StaticURLPrefix)
|
||||
//line web/baseof.qtpl:56
|
||||
qw422016.N().S(`/manifest.webmanifest"> `)
|
||||
//line web/baseof.qtpl:57
|
||||
}
|
||||
|
||||
//line ../../web/baseof.qtpl:16
|
||||
//line web/baseof.qtpl:57
|
||||
func (p *BaseOf) WriteHead(qq422016 qtio422016.Writer) {
|
||||
//line ../../web/baseof.qtpl:16
|
||||
//line web/baseof.qtpl:57
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line ../../web/baseof.qtpl:16
|
||||
//line web/baseof.qtpl:57
|
||||
p.StreamHead(qw422016)
|
||||
//line ../../web/baseof.qtpl:16
|
||||
//line web/baseof.qtpl:57
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line ../../web/baseof.qtpl:16
|
||||
//line web/baseof.qtpl:57
|
||||
}
|
||||
|
||||
//line ../../web/baseof.qtpl:16
|
||||
//line web/baseof.qtpl:57
|
||||
func (p *BaseOf) Head() string {
|
||||
//line ../../web/baseof.qtpl:16
|
||||
//line web/baseof.qtpl:57
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line ../../web/baseof.qtpl:16
|
||||
//line web/baseof.qtpl:57
|
||||
p.WriteHead(qb422016)
|
||||
//line ../../web/baseof.qtpl:16
|
||||
//line web/baseof.qtpl:57
|
||||
qs422016 := string(qb422016.B)
|
||||
//line ../../web/baseof.qtpl:16
|
||||
//line web/baseof.qtpl:57
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line ../../web/baseof.qtpl:16
|
||||
//line web/baseof.qtpl:57
|
||||
return qs422016
|
||||
//line ../../web/baseof.qtpl:16
|
||||
//line web/baseof.qtpl:57
|
||||
}
|
||||
|
||||
//line ../../web/baseof.qtpl:18
|
||||
//line web/baseof.qtpl:59
|
||||
func (p *BaseOf) StreamBody(qw422016 *qt422016.Writer) {
|
||||
//line ../../web/baseof.qtpl:18
|
||||
//line web/baseof.qtpl:59
|
||||
}
|
||||
|
||||
//line ../../web/baseof.qtpl:18
|
||||
//line web/baseof.qtpl:59
|
||||
func (p *BaseOf) WriteBody(qq422016 qtio422016.Writer) {
|
||||
//line ../../web/baseof.qtpl:18
|
||||
//line web/baseof.qtpl:59
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line ../../web/baseof.qtpl:18
|
||||
//line web/baseof.qtpl:59
|
||||
p.StreamBody(qw422016)
|
||||
//line ../../web/baseof.qtpl:18
|
||||
//line web/baseof.qtpl:59
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line ../../web/baseof.qtpl:18
|
||||
//line web/baseof.qtpl:59
|
||||
}
|
||||
|
||||
//line ../../web/baseof.qtpl:18
|
||||
//line web/baseof.qtpl:59
|
||||
func (p *BaseOf) Body() string {
|
||||
//line ../../web/baseof.qtpl:18
|
||||
//line web/baseof.qtpl:59
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line ../../web/baseof.qtpl:18
|
||||
//line web/baseof.qtpl:59
|
||||
p.WriteBody(qb422016)
|
||||
//line ../../web/baseof.qtpl:18
|
||||
//line web/baseof.qtpl:59
|
||||
qs422016 := string(qb422016.B)
|
||||
//line ../../web/baseof.qtpl:18
|
||||
//line web/baseof.qtpl:59
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line ../../web/baseof.qtpl:18
|
||||
//line web/baseof.qtpl:59
|
||||
return qs422016
|
||||
//line ../../web/baseof.qtpl:18
|
||||
//line web/baseof.qtpl:59
|
||||
}
|
||||
|
||||
//line ../../web/baseof.qtpl:20
|
||||
func StreamPageTemplate(qw422016 *qt422016.Writer, p Page) {
|
||||
//line ../../web/baseof.qtpl:20
|
||||
qw422016.N().S(`
|
||||
<!DOCTYPE html>
|
||||
<html lang="`)
|
||||
//line ../../web/baseof.qtpl:22
|
||||
//line web/baseof.qtpl:61
|
||||
func StreamTemplate(qw422016 *qt422016.Writer, p Page) {
|
||||
//line web/baseof.qtpl:61
|
||||
qw422016.N().S(` <!DOCTYPE html> <html class="page" lang="`)
|
||||
//line web/baseof.qtpl:65
|
||||
p.StreamLang(qw422016)
|
||||
//line ../../web/baseof.qtpl:22
|
||||
qw422016.N().S(`">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>`)
|
||||
//line ../../web/baseof.qtpl:26
|
||||
p.StreamTitle(qw422016)
|
||||
//line ../../web/baseof.qtpl:26
|
||||
qw422016.N().S(`</title>
|
||||
`)
|
||||
//line ../../web/baseof.qtpl:27
|
||||
//line web/baseof.qtpl:65
|
||||
qw422016.N().S(`"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> `)
|
||||
//line web/baseof.qtpl:73
|
||||
p.StreamHead(qw422016)
|
||||
//line ../../web/baseof.qtpl:27
|
||||
qw422016.N().S(`
|
||||
</head>
|
||||
<body>
|
||||
`)
|
||||
//line ../../web/baseof.qtpl:30
|
||||
//line web/baseof.qtpl:73
|
||||
qw422016.N().S(` <title>`)
|
||||
//line web/baseof.qtpl:74
|
||||
p.StreamTitle(qw422016)
|
||||
//line web/baseof.qtpl:74
|
||||
qw422016.N().S(`</title> </head> <body class="page__body body"> `)
|
||||
//line web/baseof.qtpl:77
|
||||
p.StreamBody(qw422016)
|
||||
//line ../../web/baseof.qtpl:30
|
||||
qw422016.N().S(`
|
||||
</body>
|
||||
</html>
|
||||
`)
|
||||
//line ../../web/baseof.qtpl:33
|
||||
//line web/baseof.qtpl:77
|
||||
qw422016.N().S(` </body> </html> `)
|
||||
//line web/baseof.qtpl:80
|
||||
}
|
||||
|
||||
//line ../../web/baseof.qtpl:33
|
||||
func WritePageTemplate(qq422016 qtio422016.Writer, p Page) {
|
||||
//line ../../web/baseof.qtpl:33
|
||||
//line web/baseof.qtpl:80
|
||||
func WriteTemplate(qq422016 qtio422016.Writer, p Page) {
|
||||
//line web/baseof.qtpl:80
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line ../../web/baseof.qtpl:33
|
||||
StreamPageTemplate(qw422016, p)
|
||||
//line ../../web/baseof.qtpl:33
|
||||
//line web/baseof.qtpl:80
|
||||
StreamTemplate(qw422016, p)
|
||||
//line web/baseof.qtpl:80
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line ../../web/baseof.qtpl:33
|
||||
//line web/baseof.qtpl:80
|
||||
}
|
||||
|
||||
//line ../../web/baseof.qtpl:33
|
||||
func PageTemplate(p Page) string {
|
||||
//line ../../web/baseof.qtpl:33
|
||||
//line web/baseof.qtpl:80
|
||||
func Template(p Page) string {
|
||||
//line web/baseof.qtpl:80
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line ../../web/baseof.qtpl:33
|
||||
WritePageTemplate(qb422016, p)
|
||||
//line ../../web/baseof.qtpl:33
|
||||
//line web/baseof.qtpl:80
|
||||
WriteTemplate(qb422016, p)
|
||||
//line web/baseof.qtpl:80
|
||||
qs422016 := string(qb422016.B)
|
||||
//line ../../web/baseof.qtpl:33
|
||||
//line web/baseof.qtpl:80
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line ../../web/baseof.qtpl:33
|
||||
//line web/baseof.qtpl:80
|
||||
return qs422016
|
||||
//line ../../web/baseof.qtpl:33
|
||||
//line web/baseof.qtpl:80
|
||||
}
|
||||
|
||||
//line web/baseof.qtpl:82
|
||||
func (p *BaseOf) StreamT(qw422016 *qt422016.Writer, str string, args ...interface{}) {
|
||||
//line web/baseof.qtpl:82
|
||||
qw422016.N().S(` `)
|
||||
//line web/baseof.qtpl:84
|
||||
result := p.Printer.Sprintf(str, args...)
|
||||
|
||||
//line web/baseof.qtpl:85
|
||||
qw422016.N().S(` `)
|
||||
//line web/baseof.qtpl:86
|
||||
qw422016.E().S(result)
|
||||
//line web/baseof.qtpl:86
|
||||
qw422016.N().S(` `)
|
||||
//line web/baseof.qtpl:87
|
||||
}
|
||||
|
||||
//line web/baseof.qtpl:87
|
||||
func (p *BaseOf) WriteT(qq422016 qtio422016.Writer, str string, args ...interface{}) {
|
||||
//line web/baseof.qtpl:87
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line web/baseof.qtpl:87
|
||||
p.StreamT(qw422016, str, args...)
|
||||
//line web/baseof.qtpl:87
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line web/baseof.qtpl:87
|
||||
}
|
||||
|
||||
//line web/baseof.qtpl:87
|
||||
func (p *BaseOf) T(str string, args ...interface{}) string {
|
||||
//line web/baseof.qtpl:87
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line web/baseof.qtpl:87
|
||||
p.WriteT(qb422016, str, args...)
|
||||
//line web/baseof.qtpl:87
|
||||
qs422016 := string(qb422016.B)
|
||||
//line web/baseof.qtpl:87
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line web/baseof.qtpl:87
|
||||
return qs422016
|
||||
//line web/baseof.qtpl:87
|
||||
}
|
||||
|
|
79
web/home.qtpl
Normal file
79
web/home.qtpl
Normal file
|
@ -0,0 +1,79 @@
|
|||
{% import "source.toby3d.me/website/oauth/internal/domain" %}
|
||||
|
||||
{% code
|
||||
type HomePage struct {
|
||||
BaseOf
|
||||
RedirectURI []*domain.URL
|
||||
Client *domain.Client
|
||||
AuthEndpoint,
|
||||
State string
|
||||
}
|
||||
%}
|
||||
|
||||
{% collapsespace %}
|
||||
{% func (p *HomePage) Head() %}
|
||||
{%= p.BaseOf.Head() %}
|
||||
{% for i := range p.RedirectURI %}
|
||||
<link rel="redirect_uri" href="{%s p.RedirectURI[i].String() %}">
|
||||
{% endfor %}
|
||||
{% endfunc %}
|
||||
|
||||
{% func (p *HomePage) Body() %}
|
||||
<div class="h-app h-x-app">
|
||||
<img
|
||||
class="u-logo"
|
||||
src="{%s p.Client.Logo[0].String() %}"
|
||||
alt="{%s p.Client.Name[0] %}"
|
||||
crossorigin="anonymous"
|
||||
decoding="async"
|
||||
height="140"
|
||||
importance="high"
|
||||
referrerpolicy="no-referrer-when-downgrade"
|
||||
width="140">
|
||||
|
||||
<h1>
|
||||
<a
|
||||
class="p-name u-url"
|
||||
href="{%s p.Client.URL[0].String() %}">
|
||||
|
||||
{%s p.Client.Name[0] %}
|
||||
</a>
|
||||
</h1>
|
||||
|
||||
<form
|
||||
method="get"
|
||||
action="{%s p.AuthEndpoint %}"
|
||||
enctype="application/x-www-form-urlencoded"
|
||||
accept-charset="utf-8"
|
||||
target="_self">
|
||||
|
||||
{% for name, value := range map[string]string {
|
||||
"client_id": p.Client.ID.String(),
|
||||
"redirect_uri": p.Client.RedirectURI[0].String(),
|
||||
"response_type": "code",
|
||||
"state": p.State,
|
||||
} %}
|
||||
<input
|
||||
type="hidden"
|
||||
name="{%s name %}"
|
||||
value="{%s value %}">
|
||||
{% endfor %}
|
||||
|
||||
<input
|
||||
type="hidden"
|
||||
name="scope"
|
||||
value="{%s domain.ScopeProfile.String() %} {%s domain.ScopeEmail.String() %}">
|
||||
|
||||
<input
|
||||
type="url"
|
||||
name="me"
|
||||
placeholder="https://example.com/"
|
||||
inputmode="url"
|
||||
autocomplete="url"
|
||||
required>
|
||||
|
||||
<button type="submit">{%= p.T("Sign In") %}</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endfunc %}
|
||||
{% endcollapsespace %}
|
165
web/home.qtpl.go
Normal file
165
web/home.qtpl.go
Normal file
|
@ -0,0 +1,165 @@
|
|||
// Code generated by qtc from "home.qtpl". DO NOT EDIT.
|
||||
// See https://github.com/valyala/quicktemplate for details.
|
||||
|
||||
//line web/home.qtpl:1
|
||||
package web
|
||||
|
||||
//line web/home.qtpl:1
|
||||
import "source.toby3d.me/website/oauth/internal/domain"
|
||||
|
||||
//line web/home.qtpl:3
|
||||
import (
|
||||
qtio422016 "io"
|
||||
|
||||
qt422016 "github.com/valyala/quicktemplate"
|
||||
)
|
||||
|
||||
//line web/home.qtpl:3
|
||||
var (
|
||||
_ = qtio422016.Copy
|
||||
_ = qt422016.AcquireByteBuffer
|
||||
)
|
||||
|
||||
//line web/home.qtpl:4
|
||||
type HomePage struct {
|
||||
BaseOf
|
||||
RedirectURI []*domain.URL
|
||||
Client *domain.Client
|
||||
AuthEndpoint,
|
||||
State string
|
||||
}
|
||||
|
||||
//line web/home.qtpl:14
|
||||
func (p *HomePage) StreamHead(qw422016 *qt422016.Writer) {
|
||||
//line web/home.qtpl:14
|
||||
qw422016.N().S(` `)
|
||||
//line web/home.qtpl:15
|
||||
p.BaseOf.StreamHead(qw422016)
|
||||
//line web/home.qtpl:15
|
||||
qw422016.N().S(` `)
|
||||
//line web/home.qtpl:16
|
||||
for i := range p.RedirectURI {
|
||||
//line web/home.qtpl:16
|
||||
qw422016.N().S(` <link rel="redirect_uri" href="`)
|
||||
//line web/home.qtpl:17
|
||||
qw422016.E().S(p.RedirectURI[i].String())
|
||||
//line web/home.qtpl:17
|
||||
qw422016.N().S(`"> `)
|
||||
//line web/home.qtpl:18
|
||||
}
|
||||
//line web/home.qtpl:18
|
||||
qw422016.N().S(` `)
|
||||
//line web/home.qtpl:19
|
||||
}
|
||||
|
||||
//line web/home.qtpl:19
|
||||
func (p *HomePage) WriteHead(qq422016 qtio422016.Writer) {
|
||||
//line web/home.qtpl:19
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line web/home.qtpl:19
|
||||
p.StreamHead(qw422016)
|
||||
//line web/home.qtpl:19
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line web/home.qtpl:19
|
||||
}
|
||||
|
||||
//line web/home.qtpl:19
|
||||
func (p *HomePage) Head() string {
|
||||
//line web/home.qtpl:19
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line web/home.qtpl:19
|
||||
p.WriteHead(qb422016)
|
||||
//line web/home.qtpl:19
|
||||
qs422016 := string(qb422016.B)
|
||||
//line web/home.qtpl:19
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line web/home.qtpl:19
|
||||
return qs422016
|
||||
//line web/home.qtpl:19
|
||||
}
|
||||
|
||||
//line web/home.qtpl:21
|
||||
func (p *HomePage) StreamBody(qw422016 *qt422016.Writer) {
|
||||
//line web/home.qtpl:21
|
||||
qw422016.N().S(` <div class="h-app h-x-app"> <img class="u-logo" src="`)
|
||||
//line web/home.qtpl:25
|
||||
qw422016.E().S(p.Client.Logo[0].String())
|
||||
//line web/home.qtpl:25
|
||||
qw422016.N().S(`" alt="`)
|
||||
//line web/home.qtpl:26
|
||||
qw422016.E().S(p.Client.Name[0])
|
||||
//line web/home.qtpl:26
|
||||
qw422016.N().S(`" crossorigin="anonymous" decoding="async" height="140" importance="high" referrerpolicy="no-referrer-when-downgrade" width="140"> <h1> <a class="p-name u-url" href="`)
|
||||
//line web/home.qtpl:37
|
||||
qw422016.E().S(p.Client.URL[0].String())
|
||||
//line web/home.qtpl:37
|
||||
qw422016.N().S(`"> `)
|
||||
//line web/home.qtpl:39
|
||||
qw422016.E().S(p.Client.Name[0])
|
||||
//line web/home.qtpl:39
|
||||
qw422016.N().S(` </a> </h1> <form method="get" action="`)
|
||||
//line web/home.qtpl:45
|
||||
qw422016.E().S(p.AuthEndpoint)
|
||||
//line web/home.qtpl:45
|
||||
qw422016.N().S(`" enctype="application/x-www-form-urlencoded" accept-charset="utf-8" target="_self"> `)
|
||||
//line web/home.qtpl:50
|
||||
for name, value := range map[string]string{
|
||||
"client_id": p.Client.ID.String(),
|
||||
"redirect_uri": p.Client.RedirectURI[0].String(),
|
||||
"response_type": "code",
|
||||
"state": p.State,
|
||||
} {
|
||||
//line web/home.qtpl:55
|
||||
qw422016.N().S(` <input type="hidden" name="`)
|
||||
//line web/home.qtpl:58
|
||||
qw422016.E().S(name)
|
||||
//line web/home.qtpl:58
|
||||
qw422016.N().S(`" value="`)
|
||||
//line web/home.qtpl:59
|
||||
qw422016.E().S(value)
|
||||
//line web/home.qtpl:59
|
||||
qw422016.N().S(`"> `)
|
||||
//line web/home.qtpl:60
|
||||
}
|
||||
//line web/home.qtpl:60
|
||||
qw422016.N().S(` <input type="hidden" name="scope" value="`)
|
||||
//line web/home.qtpl:65
|
||||
qw422016.E().S(domain.ScopeProfile.String())
|
||||
//line web/home.qtpl:65
|
||||
qw422016.N().S(` `)
|
||||
//line web/home.qtpl:65
|
||||
qw422016.E().S(domain.ScopeEmail.String())
|
||||
//line web/home.qtpl:65
|
||||
qw422016.N().S(`"> <input type="url" name="me" placeholder="https://example.com/" inputmode="url" autocomplete="url" required> <button type="submit">`)
|
||||
//line web/home.qtpl:75
|
||||
p.StreamT(qw422016, "Sign In")
|
||||
//line web/home.qtpl:75
|
||||
qw422016.N().S(`</button> </form> </div> `)
|
||||
//line web/home.qtpl:78
|
||||
}
|
||||
|
||||
//line web/home.qtpl:78
|
||||
func (p *HomePage) WriteBody(qq422016 qtio422016.Writer) {
|
||||
//line web/home.qtpl:78
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line web/home.qtpl:78
|
||||
p.StreamBody(qw422016)
|
||||
//line web/home.qtpl:78
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line web/home.qtpl:78
|
||||
}
|
||||
|
||||
//line web/home.qtpl:78
|
||||
func (p *HomePage) Body() string {
|
||||
//line web/home.qtpl:78
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line web/home.qtpl:78
|
||||
p.WriteBody(qb422016)
|
||||
//line web/home.qtpl:78
|
||||
qs422016 := string(qb422016.B)
|
||||
//line web/home.qtpl:78
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line web/home.qtpl:78
|
||||
return qs422016
|
||||
//line web/home.qtpl:78
|
||||
}
|
Loading…
Reference in a new issue