Skip to content

Commit

Permalink
Add InDevelopment flag and improve conditional rendering
Browse files Browse the repository at this point in the history
In the register.go file, an InDevelopment boolean field was added to the HomePageData struct. Utilized this flag to conditionally render parts of the login.html and home.html files based on the application's development status. Also, corrected the missing element error message in main.js.

Signed-off-by: Christian Roessner <c@roessner.co>
  • Loading branch information
Christian Roessner committed May 7, 2024
1 parent 1f52aec commit 48a84ad
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions server/core/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type TOTPPageData struct {
}

type HomePageData struct {
InDevelopment bool
WantWelcome bool
WantPolicy bool
WantTos bool
Expand Down Expand Up @@ -555,6 +556,7 @@ func register2FAHomeHandler(ctx *gin.Context) {
LanguageTag: session.Get(global.CookieLang).(string),
LanguageCurrentName: languageCurrentName,
LanguagePassive: languagePassive,
InDevelopment: tags.IsDevelopment,
}

ctx.HTML(http.StatusOK, "home.html", homeData)
Expand Down
6 changes: 6 additions & 0 deletions static/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ <h1 class="center">{{ .Welcome }}</h1>
<button type="submit" id="register_totp" name="totp" value="totp" data-endpointtotp="{{ .EndpointTOTP }}" data-havetotp="{{ .HaveTOTP }}">
{{ .RegisterTOTP }}
</button>
{{ if .InDevelopment }}
<p class="text center vs-5">{{ .Or }}</p>
<div class="vs-15"></div>
<!--suppress XmlDuplicatedId -->
<button type="submit" id="register_device" name="device" value="device">
{{ .RegisterWebAuthn }}
</button>
{{ else }}
<!--suppress XmlDuplicatedId -->
<div id="register_device" style="display: none;"></div>
{{ end }}
</article>
</section>
</main>
Expand Down
2 changes: 1 addition & 1 deletion static/js/home/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (have_totp === "true") {

const device = document.getElementById("register_device");
if (device === null) {
throw new Error("Missing element 'device'");
throw new Error("Missing element 'register_device'");
}

const register_totp = (event) => {
Expand Down
2 changes: 2 additions & 0 deletions static/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ <h2 class="center">{{ .ApplicationName }}</h2>
{{ if .InDevelopment }}
<p class="text center vs-5">{{ .Or }}</p>
<div class="vs-15"></div>
<!--suppress XmlDuplicatedId -->
<button class="device" type="submit" id="device" name="device" value="{{ .Device }}" data-deviceurl="{{ .DeviceLoginEndpoint }}">
{{ .Device }}
</button>
{{ else }}
<!--suppress XmlDuplicatedId -->
<div id="device" style="display: none;"></div>
{{ end }}
{{ if .WantRemember }}
Expand Down

0 comments on commit 48a84ad

Please sign in to comment.