Skip to content

Commit 1818f4d

Browse files
committed
Reduce complexity of fetching help mail
1 parent 7f98ea4 commit 1818f4d

File tree

6 files changed

+26
-23
lines changed

6 files changed

+26
-23
lines changed

internal/data/config.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,14 @@ func SetHelpMail(helpMail string) error {
218218
return err
219219
}
220220

221-
func GetHelpMail() (string, error) {
222-
return getGeneric(helpMailKey)
221+
func GetHelpMail() string {
222+
223+
mail, err := getGeneric(helpMailKey)
224+
if err != nil {
225+
return "Server Error"
226+
}
227+
228+
return mail
223229
}
224230

225231
func SetExternalAddress(externalAddress string) error {

internal/webserver/authenticators/init.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ func resultMessage(err error) (string, int) {
2525
return "Success", http.StatusOK
2626
}
2727

28-
mail, err := data.GetHelpMail()
29-
if err != nil {
30-
mail = "Server Error"
31-
}
28+
mail := data.GetHelpMail()
3229

3330
msg := "Validation failed"
3431
if strings.Contains(err.Error(), "account is locked") {

internal/webserver/authenticators/oidc.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,8 @@ func (o *Oidc) AuthorisationAPI(w http.ResponseWriter, r *http.Request) {
210210

211211
w.WriteHeader(http.StatusUnauthorized)
212212

213-
mail, err := data.GetHelpMail()
214-
if err != nil {
215-
log.Println("Error getting help mail: ", err)
216-
http.Error(w, "Server Error", http.StatusInternalServerError)
217-
return
218-
}
219213
err = resources.Render("oidc_error.html", w, &resources.Msg{
220-
HelpMail: mail,
214+
HelpMail: data.GetHelpMail(),
221215
NumMethods: NumberOfMethods(),
222216
Message: msg,
223217
URL: rp.GetEndSessionEndpoint(),

internal/webserver/authenticators/pam.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"fmt"
99

10-
"github.com/NHAS/wag/internal/config"
1110
"github.com/NHAS/wag/internal/data"
1211
"github.com/NHAS/wag/internal/router"
1312
"github.com/NHAS/wag/internal/users"
@@ -184,7 +183,7 @@ func (t *Pam) AuthoriseFunc(w http.ResponseWriter, r *http.Request) types.Authen
184183

185184
func (t *Pam) MFAPromptUI(w http.ResponseWriter, r *http.Request, username, ip string) {
186185
if err := resources.Render("prompt_mfa_pam.html", w, &resources.Msg{
187-
HelpMail: config.Values().HelpMail,
186+
HelpMail: data.GetHelpMail(),
188187
NumMethods: NumberOfMethods(),
189188
}); err != nil {
190189
log.Println(username, ip, "unable to render pam prompt template: ", err)
@@ -193,7 +192,7 @@ func (t *Pam) MFAPromptUI(w http.ResponseWriter, r *http.Request, username, ip s
193192

194193
func (t *Pam) RegistrationUI(w http.ResponseWriter, r *http.Request, username, ip string) {
195194
if err := resources.Render("register_mfa_pam.html", w, &resources.Msg{
196-
HelpMail: config.Values().HelpMail,
195+
HelpMail: data.GetHelpMail(),
197196
NumMethods: NumberOfMethods(),
198197
}); err != nil {
199198
log.Println(username, ip, "unable to render pam mfa template: ", err)

internal/webserver/authenticators/totp.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"sync"
1111
"time"
1212

13-
"github.com/NHAS/wag/internal/config"
1413
"github.com/NHAS/wag/internal/data"
1514
"github.com/NHAS/wag/internal/router"
1615
"github.com/NHAS/wag/internal/users"
@@ -73,8 +72,15 @@ func (t *Totp) RegistrationAPI(w http.ResponseWriter, r *http.Request) {
7372
switch r.Method {
7473
case "GET":
7574

75+
issuer, err := data.GetIssuer()
76+
if err != nil {
77+
log.Println(user.Username, clientTunnelIp, "unable to get issuer from datastore")
78+
79+
http.Error(w, "Bad request", 400)
80+
return
81+
}
7682
key, err := totp.Generate(totp.GenerateOpts{
77-
Issuer: config.Values().Authenticators.Issuer,
83+
Issuer: issuer,
7884
AccountName: user.Username,
7985
})
8086
if err != nil {
@@ -210,17 +216,19 @@ func (t *Totp) AuthoriseFunc(w http.ResponseWriter, r *http.Request) types.Authe
210216
}
211217

212218
func (t *Totp) MFAPromptUI(w http.ResponseWriter, r *http.Request, username, ip string) {
219+
213220
if err := resources.Render("prompt_mfa_totp.html", w, &resources.Msg{
214-
HelpMail: config.Values().HelpMail,
221+
HelpMail: data.GetHelpMail(),
215222
NumMethods: NumberOfMethods(),
216223
}); err != nil {
217224
log.Println(username, ip, "unable to render totp prompt template: ", err)
218225
}
219226
}
220227

221228
func (t *Totp) RegistrationUI(w http.ResponseWriter, r *http.Request, username, ip string) {
229+
222230
if err := resources.Render("register_mfa_totp.html", w, &resources.Msg{
223-
HelpMail: config.Values().HelpMail,
231+
HelpMail: data.GetHelpMail(),
224232
NumMethods: NumberOfMethods(),
225233
}); err != nil {
226234
log.Println(username, ip, "unable to render totp mfa template: ", err)

internal/webserver/authenticators/webauthn.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"time"
1212

1313
"github.com/NHAS/session"
14-
"github.com/NHAS/wag/internal/config"
1514
"github.com/NHAS/wag/internal/data"
1615
"github.com/NHAS/wag/internal/router"
1716
"github.com/NHAS/wag/internal/users"
@@ -284,7 +283,7 @@ func (wa *Webauthn) AuthorisationAPI(w http.ResponseWriter, r *http.Request) {
284283
func (wa *Webauthn) MFAPromptUI(w http.ResponseWriter, r *http.Request, username, ip string) {
285284

286285
if err := resources.Render("prompt_mfa_webauthn.html", w, &resources.Msg{
287-
HelpMail: config.Values().HelpMail,
286+
HelpMail: data.GetHelpMail(),
288287
NumMethods: NumberOfMethods(),
289288
}); err != nil {
290289
log.Println(username, ip, "unable to render weauthn prompt template: ", err)
@@ -294,7 +293,7 @@ func (wa *Webauthn) MFAPromptUI(w http.ResponseWriter, r *http.Request, username
294293
func (wa *Webauthn) RegistrationUI(w http.ResponseWriter, r *http.Request, username, ip string) {
295294

296295
if err := resources.Render("register_mfa_webauthn.html", w, &resources.Msg{
297-
HelpMail: config.Values().HelpMail,
296+
HelpMail: data.GetHelpMail(),
298297
NumMethods: NumberOfMethods(),
299298
}); err != nil {
300299
log.Println(username, ip, "unable to render weauthn prompt template: ", err)

0 commit comments

Comments
 (0)