Skip to content

Commit f4db15b

Browse files
committed
Address phone input bugs
2 parents 99ccd4c + b1ffb17 commit f4db15b

File tree

12 files changed

+86
-21
lines changed

12 files changed

+86
-21
lines changed

pkg/auth/handler/webapp/viewmodels/base.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ type FlashMessage interface {
8484
}
8585

8686
type BaseViewModeler struct {
87+
TrustProxy config.TrustProxy
8788
OAuth *config.OAuthConfig
8889
AuthUI *config.UIConfig
8990
AuthUIFeatureConfig *config.UIFeatureConfig
@@ -122,9 +123,12 @@ func (m *BaseViewModeler) ViewModel(r *http.Request, rw http.ResponseWriter) Bas
122123
}
123124

124125
geoipCountryCode := ""
125-
geoipInfo, ok := geoip.DefaultDatabase.IPString(r.RemoteAddr)
126-
if ok {
127-
geoipCountryCode = geoipInfo.CountryCode
126+
if !m.AuthUI.PhoneInput.PreselectByIPDisabled {
127+
requestIP := httputil.GetIP(r, bool(m.TrustProxy))
128+
geoipInfo, ok := geoip.DefaultDatabase.IPString(requestIP)
129+
if ok {
130+
geoipCountryCode = geoipInfo.CountryCode
131+
}
128132
}
129133

130134
model := BaseViewModel{

pkg/auth/wire_gen.go

Lines changed: 40 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/lib/config/ui.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,18 @@ var _ = Schema.Add("PhoneInputConfig", `
3535
"additionalProperties": false,
3636
"properties": {
3737
"allowlist": { "type": "array", "items": { "$ref": "#/$defs/ISO31661Alpha2" }, "minItems": 1 },
38-
"pinned_list": { "type": "array", "items": { "$ref": "#/$defs/ISO31661Alpha2" } }
38+
"pinned_list": { "type": "array", "items": { "$ref": "#/$defs/ISO31661Alpha2" } },
39+
"preselect_by_ip_disabled": { "type": "boolean" }
3940
}
4041
}
4142
`)
4243

4344
var _ = Schema.Add("ISO31661Alpha2", phone.JSONSchemaString)
4445

4546
type PhoneInputConfig struct {
46-
AllowList []string `json:"allowlist,omitempty"`
47-
PinnedList []string `json:"pinned_list,omitempty"`
47+
AllowList []string `json:"allowlist,omitempty"`
48+
PinnedList []string `json:"pinned_list,omitempty"`
49+
PreselectByIPDisabled bool `json:"preselect_by_ip_disabled,omitempty"`
4850
}
4951

5052
func (c *PhoneInputConfig) SetDefaults() {

0 commit comments

Comments
 (0)