-
Notifications
You must be signed in to change notification settings - Fork 9
/
app_settings.go
62 lines (54 loc) · 2.47 KB
/
app_settings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package api
import (
"net/http"
l "github.com/madappgang/identifo/v2/localization"
"github.com/madappgang/identifo/v2/model"
"github.com/madappgang/identifo/v2/web/middleware"
)
type appSettings struct {
AnonymousRegistrationAllowed bool `json:"anonymousRegistrationAllowed"`
Active bool `json:"active"`
Description string `json:"description"`
ID string `json:"id"`
NewUserDefaultRole string `json:"newUserDefaultRole"`
Offline bool `json:"offline"`
RegistrationForbidden bool `json:"registrationForbidden"`
TfaType string `json:"tfaType"`
TfaStatus string `json:"tfaStatus"`
TfaResendTimeout int `json:"tfaResendTimeout"`
LoginWith model.LoginWith `json:"loginWith"`
FederatedProviders []string `json:"federatedProviders"`
CustomEmailTemplates bool `json:"customEmailTemplates"`
FederatedOIDCInitURL string `json:"federatedOIDCInitURL"`
}
// GetAppSettings return app settings
func (ar *Router) GetAppSettings() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
locale := r.Header.Get("Accept-Language")
app := middleware.AppFromContext(r.Context())
if len(app.ID) == 0 {
ar.Error(w, locale, http.StatusBadRequest, l.ErrorAPIAPPNoAPPInContext)
return
}
result := appSettings{
AnonymousRegistrationAllowed: app.AnonymousRegistrationAllowed,
Active: app.Active,
Description: app.Description,
ID: app.ID,
NewUserDefaultRole: app.NewUserDefaultRole,
Offline: app.Offline,
RegistrationForbidden: app.RegistrationForbidden,
TfaType: string(ar.tfaType),
TfaStatus: string(app.TFAStatus),
TfaResendTimeout: ar.tfaResendTimeout,
LoginWith: ar.SupportedLoginWays,
FederatedProviders: make([]string, 0, len(app.FederatedProviders)),
CustomEmailTemplates: app.CustomEmailTemplates,
FederatedOIDCInitURL: app.OIDCSettings.InitURL,
}
for k := range app.FederatedProviders {
result.FederatedProviders = append(result.FederatedProviders, k)
}
ar.ServeJSON(w, locale, http.StatusOK, result)
}
}