-
-
Notifications
You must be signed in to change notification settings - Fork 410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to override domains and whitelist in rules #63
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,31 +56,51 @@ func ValidateCookie(r *http.Request, c *http.Cookie) (string, error) { | |
} | ||
|
||
// Validate email | ||
func ValidateEmail(email string) bool { | ||
func ValidateEmail(email string, rule string) bool { | ||
found := false | ||
if len(config.Whitelist) > 0 { | ||
for _, whitelist := range config.Whitelist { | ||
if email == whitelist { | ||
found = true | ||
} | ||
} | ||
|
||
_, ruleExists := config.Rules[rule] | ||
if ruleExists && len(config.Rules[rule].Whitelist) > 0 { | ||
found = ValidateWhitelist(email, config.Rules[rule].Whitelist) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On reflection, we don't actually need the |
||
} else if ruleExists && len(config.Rules[rule].Domains) > 0 { | ||
found = ValidateDomains(email, config.Rules[rule].Domains) | ||
} else if len(config.Whitelist) > 0 { | ||
found = ValidateWhitelist(email, config.Whitelist) | ||
} else if len(config.Domains) > 0 { | ||
parts := strings.Split(email, "@") | ||
if len(parts) < 2 { | ||
return false | ||
} | ||
for _, domain := range config.Domains { | ||
if domain == parts[1] { | ||
found = true | ||
} | ||
} | ||
found = ValidateDomains(email, config.Domains) | ||
} else { | ||
return true | ||
} | ||
|
||
return found | ||
} | ||
|
||
// Validate email is in whitelist | ||
func ValidateWhitelist(email string, whitelist CommaSeparatedList) bool { | ||
found := false | ||
for _, whitelist := range whitelist { | ||
if email == whitelist { | ||
found = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this is now a separate function we don't need the temporary |
||
} | ||
} | ||
return found | ||
} | ||
|
||
// Validate email match a domains | ||
func ValidateDomains(email string, domains CommaSeparatedList) bool { | ||
found := false | ||
parts := strings.Split(email, "@") | ||
if len(parts) < 2 { | ||
return false | ||
} | ||
for _, domain := range domains { | ||
if domain == parts[1] { | ||
found = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, this can just return here |
||
} | ||
} | ||
return found | ||
} | ||
|
||
// OAuth Methods | ||
|
||
// Get login url | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make the following code shorter, could you rename the function parameter to
ruleName
and then assign the first return argument of this function into a variablerule
: