MM-54182 - add correct information to session table from mobile devices (#24353)

* MM-54182 - add correct information to session table from mobile devices

* improve comments around helper function

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Pablo Andrés Vélez Vidal
2023-09-01 14:25:07 +02:00
коммит произвёл GitHub
родитель 8c2fc88471
Коммит 4f0f3845e4
5 изменённых файлов: 67 добавлений и 4 удалений

Просмотреть файл

@@ -208,6 +208,25 @@ func IsValidMobileAuthRedirectURL(config *model.Config, redirectURL string) bool
return false
}
// This will only return TRUE if the request comes from a mobile running the Mobile App.
// If the request comes from a mobile using the browser, it will return FALSE.
func IsMobileRequest(r *http.Request) bool {
userAgent := r.UserAgent()
if userAgent == "" {
return false
}
// Check if the User-Agent contain keywords found in mobile devices running the mobile App
mobileKeywords := []string{"Mobile", "Android", "iOS", "iPhone", "iPad"}
for _, keyword := range mobileKeywords {
if strings.Contains(userAgent, keyword) {
return true
}
}
return false
}
// RoundOffToZeroes converts all digits to 0 except the 1st one.
// Special case: If there is only 1 digit, then returns 0.
func RoundOffToZeroes(n float64) int64 {