Allow a whitelist of email addresses
This commit is contained in:

committed by
Thom Seddon

parent
36fffd2382
commit
eaad0a9054
@ -38,6 +38,7 @@ type ForwardAuth struct {
|
||||
CookieSecure bool
|
||||
|
||||
Domain []string
|
||||
Whitelist []string
|
||||
|
||||
Direct bool
|
||||
|
||||
@ -86,12 +87,12 @@ func (f *ForwardAuth) ValidateCookie(r *http.Request, c *http.Cookie) (bool, str
|
||||
|
||||
// Validate email
|
||||
func (f *ForwardAuth) ValidateEmail(email string) bool {
|
||||
found := false
|
||||
if len(f.Domain) > 0 {
|
||||
parts := strings.Split(email, "@")
|
||||
if len(parts) < 2 {
|
||||
return false
|
||||
}
|
||||
found := false
|
||||
for _, domain := range f.Domain {
|
||||
if domain == parts[1] {
|
||||
found = true
|
||||
@ -100,6 +101,15 @@ func (f *ForwardAuth) ValidateEmail(email string) bool {
|
||||
if !found {
|
||||
return false
|
||||
}
|
||||
} else if len(f.Whitelist) > 0 {
|
||||
for _, wlEmail := range f.Whitelist {
|
||||
if wlEmail == email {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
|
Reference in New Issue
Block a user