Add required config to signin context
This commit is contained in:
parent
2bb4a134b2
commit
2d2a8248c4
4 changed files with 23 additions and 12 deletions
|
|
@ -38,7 +38,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form method="POST" action="/signin">
|
<form method="POST" action="/signin">
|
||||||
<input type="hidden" name="next" value="{{ .Next }}" />
|
<input type="hidden" name="next" value="{{ .C.Next }}" />
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="username" class="form-label">Username</label>
|
<label for="username" class="form-label">Username</label>
|
||||||
<input
|
<input
|
||||||
|
|
@ -59,7 +59,7 @@
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ if .InvalidCredentials }}
|
{{ if .C.InvalidCredentials }}
|
||||||
<div class="alert alert-danger" role="alert">
|
<div class="alert alert-danger" role="alert">
|
||||||
The credentials you provided weren't recognized.
|
The credentials you provided weren't recognized.
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ type contentAuthenticated[T any] struct {
|
||||||
C T
|
C T
|
||||||
Config contentConfig
|
Config contentConfig
|
||||||
Organization *models.Organization
|
Organization *models.Organization
|
||||||
URL ContentURL
|
URL contentURL
|
||||||
User User
|
User User
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -158,6 +158,7 @@ func authenticatedHandler[T any](f handlerFunctionGet[T]) http.Handler {
|
||||||
}
|
}
|
||||||
html.RenderOrError(w, resp.template, contentAuthenticated[T]{
|
html.RenderOrError(w, resp.template, contentAuthenticated[T]{
|
||||||
C: resp.content,
|
C: resp.content,
|
||||||
|
Config: newContentConfig(),
|
||||||
Organization: org,
|
Organization: org,
|
||||||
URL: newContentURL(),
|
URL: newContentURL(),
|
||||||
User: userContent,
|
User: userContent,
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,11 @@ import (
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ContentSignin struct {
|
type contentSignin struct {
|
||||||
InvalidCredentials bool
|
InvalidCredentials bool
|
||||||
Next string
|
Next string
|
||||||
}
|
}
|
||||||
type ContentSignup struct{}
|
type contentSignup struct{}
|
||||||
|
|
||||||
func getSignin(w http.ResponseWriter, r *http.Request) {
|
func getSignin(w http.ResponseWriter, r *http.Request) {
|
||||||
errorCode := r.URL.Query().Get("error")
|
errorCode := r.URL.Query().Get("error")
|
||||||
|
|
@ -30,7 +30,7 @@ func getSignout(w http.ResponseWriter, r *http.Request, user *models.User) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSignup(w http.ResponseWriter, r *http.Request) {
|
func getSignup(w http.ResponseWriter, r *http.Request) {
|
||||||
data := ContentSignup{}
|
data := contentSignup{}
|
||||||
html.RenderOrError(w, "sync/signup.html", data)
|
html.RenderOrError(w, "sync/signup.html", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,13 +96,23 @@ func postSignup(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type contentUnauthenticated[T any] struct {
|
||||||
|
C T
|
||||||
|
Config contentConfig
|
||||||
|
URL contentURL
|
||||||
|
}
|
||||||
|
|
||||||
func signin(w http.ResponseWriter, errorCode string, next string) {
|
func signin(w http.ResponseWriter, errorCode string, next string) {
|
||||||
if next == "" {
|
if next == "" {
|
||||||
next = "/"
|
next = "/"
|
||||||
}
|
}
|
||||||
data := ContentSignin{
|
data := contentUnauthenticated[contentSignin]{
|
||||||
InvalidCredentials: errorCode == "invalid-credentials",
|
C: contentSignin{
|
||||||
Next: next,
|
InvalidCredentials: errorCode == "invalid-credentials",
|
||||||
|
Next: next,
|
||||||
|
},
|
||||||
|
Config: newContentConfig(),
|
||||||
|
URL: newContentURL(),
|
||||||
}
|
}
|
||||||
html.RenderOrError(w, "sync/signin.html", data)
|
html.RenderOrError(w, "sync/signin.html", data)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ContentURL struct {
|
type contentURL struct {
|
||||||
OAuthRefreshArcGIS string
|
OAuthRefreshArcGIS string
|
||||||
Root string
|
Root string
|
||||||
Route string
|
Route string
|
||||||
|
|
@ -20,8 +20,8 @@ type ContentURL struct {
|
||||||
UploadCSVPool string
|
UploadCSVPool string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newContentURL() ContentURL {
|
func newContentURL() contentURL {
|
||||||
return ContentURL{
|
return contentURL{
|
||||||
OAuthRefreshArcGIS: config.MakeURLNidus("/arcgis/oauth/begin"),
|
OAuthRefreshArcGIS: config.MakeURLNidus("/arcgis/oauth/begin"),
|
||||||
Root: config.MakeURLNidus("/"),
|
Root: config.MakeURLNidus("/"),
|
||||||
Route: config.MakeURLNidus("/route"),
|
Route: config.MakeURLNidus("/route"),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue