summaryrefslogtreecommitdiffstats
path: root/model/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'model/utils.go')
-rw-r--r--model/utils.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/model/utils.go b/model/utils.go
index 17d1c6317..04b92947b 100644
--- a/model/utils.go
+++ b/model/utils.go
@@ -32,6 +32,7 @@ type AppError struct {
RequestId string `json:"request_id"` // The RequestId that's also set in the header
StatusCode int `json:"status_code"` // The http status code
Where string `json:"-"` // The function where it happened in the form of Struct.Func
+ IsOAuth bool `json:"is_oauth"` // Whether the error is OAuth specific
}
func (er *AppError) Error() string {
@@ -65,6 +66,7 @@ func NewAppError(where string, message string, details string) *AppError {
ap.Where = where
ap.DetailedError = details
ap.StatusCode = 500
+ ap.IsOAuth = false
return ap
}
@@ -202,7 +204,7 @@ func GetSubDomain(s string) (string, string) {
func IsValidChannelIdentifier(s string) bool {
- if !IsValidAlphaNum(s) {
+ if !IsValidAlphaNum(s, true) {
return false
}
@@ -213,10 +215,16 @@ func IsValidChannelIdentifier(s string) bool {
return true
}
+var validAlphaNumUnderscore = regexp.MustCompile(`^[a-z0-9]+([a-z\-\_0-9]+|(__)?)[a-z0-9]+$`)
var validAlphaNum = regexp.MustCompile(`^[a-z0-9]+([a-z\-0-9]+|(__)?)[a-z0-9]+$`)
-func IsValidAlphaNum(s string) bool {
- match := validAlphaNum.MatchString(s)
+func IsValidAlphaNum(s string, allowUnderscores bool) bool {
+ var match bool
+ if allowUnderscores {
+ match = validAlphaNumUnderscore.MatchString(s)
+ } else {
+ match = validAlphaNum.MatchString(s)
+ }
if !match {
return false