|
@@ -78,49 +78,55 @@ func Secure(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
func CheckLanguage(c *gin.Context) {
|
|
|
- ok := false
|
|
|
- language := c.Request.Header.Get("Language")
|
|
|
- for _, l := range common.MetadataConfig.GetLanguages() {
|
|
|
- if language == l.ToString() {
|
|
|
- ok = true
|
|
|
+ if strings.Contains(c.FullPath(), "/api/v1/auth") {
|
|
|
+ ok := false
|
|
|
+ language := c.Request.Header.Get("Language")
|
|
|
+ for _, l := range common.MetadataConfig.GetLanguages() {
|
|
|
+ if language == l.ToString() {
|
|
|
+ ok = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !ok {
|
|
|
+ c.AbortWithStatusJSON(200, common.ErrToH(common.InvalidLanguage, c.GetHeader("Language")))
|
|
|
+ } else {
|
|
|
+ c.Set("language", language)
|
|
|
}
|
|
|
- }
|
|
|
- if !ok {
|
|
|
- c.AbortWithStatusJSON(200, common.ErrToH(common.InvalidLanguage, c.GetHeader("Language")))
|
|
|
- } else {
|
|
|
- c.Set("language", language)
|
|
|
}
|
|
|
c.Next()
|
|
|
}
|
|
|
|
|
|
func CheckSource(c *gin.Context) {
|
|
|
- source := c.Request.Header.Get("Source")
|
|
|
- ok := false
|
|
|
- for _, s := range common.MetadataConfig.GetSources() {
|
|
|
- if source == s.ToString() {
|
|
|
- ok = true
|
|
|
+ if strings.Contains(c.FullPath(), "/api/v1/auth") {
|
|
|
+ source := c.Request.Header.Get("Source")
|
|
|
+ ok := false
|
|
|
+ for _, s := range common.MetadataConfig.GetSources() {
|
|
|
+ if source == s.ToString() {
|
|
|
+ ok = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !ok {
|
|
|
+ c.AbortWithStatusJSON(200, common.ErrToH(common.InvalidSource, c.GetHeader("Source")))
|
|
|
+ } else {
|
|
|
+ c.Set("source", source)
|
|
|
}
|
|
|
- }
|
|
|
- if !ok {
|
|
|
- c.AbortWithStatusJSON(200, common.ErrToH(common.InvalidSource, c.GetHeader("Source")))
|
|
|
- } else {
|
|
|
- c.Set("source", source)
|
|
|
}
|
|
|
c.Next()
|
|
|
}
|
|
|
|
|
|
func CheckProduct(c *gin.Context) {
|
|
|
- product := c.Request.Header.Get("Product")
|
|
|
- if strings.ToUpper(product) != common.MetadataConfig.GetProduct().ToString() {
|
|
|
- c.AbortWithStatusJSON(200, common.ErrToH(common.InvalidProduct, product))
|
|
|
- } else {
|
|
|
- c.Set("product", product)
|
|
|
+ if strings.Contains(c.FullPath(), "/api/v1/auth") {
|
|
|
+ product := c.Request.Header.Get("Product")
|
|
|
+ if strings.ToUpper(product) != common.MetadataConfig.GetProduct().ToString() {
|
|
|
+ c.AbortWithStatusJSON(200, common.ErrToH(common.InvalidProduct, product))
|
|
|
+ } else {
|
|
|
+ c.Set("product", product)
|
|
|
+ }
|
|
|
}
|
|
|
c.Next()
|
|
|
}
|
|
|
|
|
|
func CheckAuth(c *gin.Context) {
|
|
|
- if strings.HasPrefix(c.FullPath(), "/dr/api/v1/auth") {
|
|
|
+ if strings.Contains(c.FullPath(), "/api/v1/auth") {
|
|
|
token := c.Request.Header.Get("Authorization")
|
|
|
uid, username, err := common.ParseToken(strings.TrimPrefix(token, "Bearer "))
|
|
|
if err != nil {
|