Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Remove more remaining user agents check

Roland Geider44905c806e49
diff --git a/wger/core/templates/manifest.webapp b/wger/core/templates/manifest.webapp
deleted file mode 100644
index 71ec3ce67..000000000
--- a/wger/core/templates/manifest.webapp
+++ /dev/null
@@ -1,36 +0,0 @@
-{% load staticfiles %}
-{
- "name": "wger Workout Manager",
- "version": "{{version}}",
- "description": "wger Workout Manager is a free, open source application that manages your exercises, workouts and nutrition.",
- "launch_path": "/dashboard",
- "icons": {
- "16": "{% static 'images/logos/logo-marketplace-16.png' %}",
- "32": "{% static 'images/logos/logo-marketplace-32.png' %}",
- "30": "{% static 'images/logos/logo-marketplace-30.png' %}",
- "48": "{% static 'images/logos/logo-marketplace-48.png' %}",
- "60": "{% static 'images/logos/logo-marketplace-60.png' %}",
- "64": "{% static 'images/logos/logo-marketplace-64.png' %}",
- "128": "{% static 'images/logos/logo-marketplace-128.png' %}",
- "256": "{% static 'images/logos/logo-marketplace-256.png' %}"
- },
- "developer": {
- "name": "Roland Geider",
- "url": "https://github.com/wger-project/wger"
- },
- "default_locale": "en",
- "locales": {
- "de": {
- "description": "wger Workout Manager ist eine freie, quelloffene Applikation die deine Trainings- und Ernährungsplanmanager sowie Gewichtslogbücher verwaltet."
- },
- "es": {
- "description": "wger Workout Manager es una aplicación gratis de código abierto que administra tus rutinas, ejercicios, peso y dietas."
- },
- "ru": {
- "description": "Менеджер Тренировок wger - это бесплатное приложение с открытым программным обеспечением, которое управляет вашими упражнениями, тренировками, весом и планом питания."
- },
- "pt": {
- "description": "wger Gerenciador de Treinos é uma aplicação livre, gratuita e opensource que gerencia seus exercícios, treinos, peso e suas dietas."
- }
- }
-}
diff --git a/wger/core/views/user.py b/wger/core/views/user.py
index f6d7bd859..3ad6f4d9c 100644
--- a/wger/core/views/user.py
+++ b/wger/core/views/user.py
@@ -99,10 +99,6 @@ from wger.utils.generic_views import (
WgerFormMixin,
WgerMultiplePermissionRequiredMixin
)
-from wger.utils.user_agents import (
- check_request_amazon,
- check_request_android
-)
from wger.weight.models import WeightEntry
@@ -242,13 +238,8 @@ def registration(request):
template_data = {}
template_data.update(csrf(request))
- # Don't use captcha when registering through an app
- is_app = check_request_amazon(request) or check_request_android(request)
- FormClass = RegistrationFormNoCaptcha if is_app else RegistrationForm
-
# Don't show captcha if the global parameter is false
- if not settings.WGER_SETTINGS['USE_RECAPTCHA']:
- FormClass = RegistrationFormNoCaptcha
+ FormClass = RegistrationForm if settings.WGER_SETTINGS['USE_RECAPTCHA'] else RegistrationFormNoCaptcha
# Redirect regular users, in case they reached the registration page
if request.user.is_authenticated and not request.user.userprofile.is_temporary:
diff --git a/wger/urls.py b/wger/urls.py
index bba734895..192fc6af7 100644
--- a/wger/urls.py
+++ b/wger/urls.py
@@ -36,10 +36,7 @@ from wger.exercises.sitemap import ExercisesSitemap
from wger.manager.api import views as manager_api_views
from wger.nutrition.api import views as nutrition_api_views
from wger.nutrition.sitemap import NutritionSitemap
-from wger.utils.generic_views import (
- TextTemplateView,
- WebappManifestView
-)
+from wger.utils.generic_views import TextTemplateView
from wger.weight.api import views as weight_api_views
@@ -127,8 +124,6 @@ urlpatterns += [
url(r'^robots\.txt$',
TextTemplateView.as_view(template_name="robots.txt"),
name='robots'),
- url(r'^manifest\.webapp$', WebappManifestView.as_view(template_name="manifest.webapp")),
- url(r'^amazon-manifest\.webapp$', WebappManifestView.as_view(template_name="amazon-manifest.webapp")),
# API
url(r'^api/v2/exercise/search/$',
diff --git a/wger/utils/generic_views.py b/wger/utils/generic_views.py
index 310f6347f..80335961d 100644
--- a/wger/utils/generic_views.py
+++ b/wger/utils/generic_views.py
@@ -339,17 +339,3 @@ class TextTemplateView(TemplateView):
resp = super().dispatch(request, args, kwargs)
resp['Content-Type'] = 'text/plain'
return resp
-
-
-class WebappManifestView(TemplateView):
- """
- A regular templateView that sets the mime type as application/x-web-app-manifest+json
-
- This is used in the mozilla market place
- """
- template_name = 'manifest.webapp'
-
- def dispatch(request, *args, **kwargs):
- resp = super().dispatch(request, args, kwargs)
- resp['Content-Type'] = 'application/x-web-app-manifest+json'
- return resp
diff --git a/wger/utils/tests/test_user_agents.py b/wger/utils/tests/test_user_agents.py
deleted file mode 100644
index b1ddd9b02..000000000
--- a/wger/utils/tests/test_user_agents.py
+++ /dev/null
@@ -1,139 +0,0 @@
-# This file is part of wger Workout Manager.
-#
-# wger Workout Manager is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# wger Workout Manager is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-
-
-# wger
-from wger.core.tests.base_testcase import WgerTestCase
-from wger.utils import user_agents
-
-
-class AmazonUserAgentTestCase(WgerTestCase):
- """
- Tests the amazon WebApp user agent detector
- """
-
- def test_user_agent_3rd_generation(self):
- """
- Tests 3rd generation user agents
- """
-
- agent = "Mozilla/5.0 (Linux; Android 4.2.2; <device> Build/<build>) AppleWebKit/ "\
- "<webkit> (KHTML, like Gecko) Chrome/<chrome> Mobile Safari/<safari> "\
- "AmazonWebAppPlatform/<version> "
- self.assertTrue(user_agents.is_amazon_webview(agent))
-
- def test_user_agent_2nd_generation(self):
- """
- Tests 2nd generation user agents
- """
-
- agent = "Mozilla/5.0 (Linux; Android 4.0.3; <device> Build/<build>) AppleWebKit/<webkit>" \
- "(KHTML, like Gecko) Chrome/<chrome> Mobile Safari/<safari> AmazonWebAppPlatform"\
- "/<version>"
- self.assertTrue(user_agents.is_amazon_webview(agent))
-
- def test_user_agent_1st_generation(self):
- """
- Tests 1st generation user agents
- """
-
- agent = "Mozilla/5.0 (Linux; U; Android 2.3.4; <locale>; Kindle Fire Build/GINGERBREAD) "\
- "AppleWebKit/<webkit> (KHTML, like Gecko) Version/4.0 Safari/<safari> "\
- "AmazonWebAppPlatform/<version> "
- self.assertTrue(user_agents.is_amazon_webview(agent))
-
- def test_user_agent_generic_android(self):
- """
- Tests generic android, from amazon app store
- """
-
- agent = "Mozilla/5.0 (Linux; U; Android <version>; <locale>; Build/<build>) AppleWebKit/"\
- "<webkit> (KHTML, like Gecko) Version/4.0 Safari/<safari> AmazonWebAppPlatform/"\
- "<version>"
- self.assertTrue(user_agents.is_amazon_webview(agent))
-
- def test_user_agent_firefox(self):
- """
- Tests vanilla firefox user agent
- """
-
- agent = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0"
- self.assertFalse(user_agents.is_amazon_webview(agent))
-
- agent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0"
- self.assertFalse(user_agents.is_amazon_webview(agent))
-
- def test_user_agent_chrome(self):
- """
- Tests vanilla chrome user agent
- """
-
- agent = "Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)"\
- "Chrome/32.0.1667.0 Safari/537.36"
- self.assertFalse(user_agents.is_amazon_webview(agent))
-
- agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like "\
- "Gecko) Chrome/32.0.1664.3 Safari/537.36"
- self.assertFalse(user_agents.is_amazon_webview(agent))
-
-
-class AndroidUserAgentTestCase(WgerTestCase):
- """
- Tests the android WebApp user agent detector
-
- https://developers.google.com/chrome/mobile/docs/webview/overview
- """
-
- def test_user_agent_old_ua(self):
- """
- Tests the old webview user agent
- """
-
- agent = "Mozilla/5.0 (Linux; U; Android 4.1.1; en-gb; Build/KLP) AppleWebKit/534.30 "\
- "(KHTML, like Gecko) Version/4.0 Safari/534.30 WgerAndroidWebApp"
- self.assertTrue(user_agents.is_android_webview(agent))
-
- def test_user_agent_new_ua(self):
- """
- Tests the old webview user agent
- """
-
- agent = "Mozilla/5.0 (Linux; Android 4.4; Nexus 5 Build/BuildID) AppleWebKit/537.36 "\
- "(KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36 "\
- "WgerAndroidWebApp"
- self.assertTrue(user_agents.is_android_webview(agent))
-
- def test_user_agent_firefox(self):
- """
- Tests vanilla firefox user agent
- """
-
- agent = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0"
- self.assertFalse(user_agents.is_android_webview(agent))
-
- agent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0"
- self.assertFalse(user_agents.is_android_webview(agent))
-
- def test_user_agent_chrome(self):
- """
- Tests vanilla chrome user agent
- """
-
- agent = "Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)"\
- "Chrome/32.0.1667.0 Safari/537.36"
- self.assertFalse(user_agents.is_android_webview(agent))
-
- agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like "\
- "Gecko) Chrome/32.0.1664.3 Safari/537.36"
- self.assertFalse(user_agents.is_android_webview(agent))
diff --git a/wger/utils/user_agents.py b/wger/utils/user_agents.py
deleted file mode 100644
index b902061fc..000000000
--- a/wger/utils/user_agents.py
+++ /dev/null
@@ -1,72 +0,0 @@
-# This file is part of wger Workout Manager.
-#
-# wger Workout Manager is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# wger Workout Manager is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-
-# Standard Library
-import logging
-
-
-logger = logging.getLogger(__name__)
-
-
-def is_amazon_webview(user_agent):
- """
- Check if the client is an Amazon WebView.
-
- See the amazon developer page for specific user agents:
- https://developer.amazon.com/sdk/webapps/faq.html#distribution
-
- :param user_agent A string with the user agent to check
- :return boolean
- """
- if 'amazonwebapp' in user_agent.lower():
- return True
- else:
- return False
-
-
-def check_request_amazon(request):
- """
-
- :param request:
- :return: boolean
- """
- if request.META.get('HTTP_USER_AGENT'):
- return is_amazon_webview(request.META.get('HTTP_USER_AGENT'))
- else:
- return False
-
-
-def is_android_webview(user_agent):
- """
- Check if the client is an Android WebView.
-
- :param user_agent A string with the user agent to check
- :return boolean
- """
- if 'wgerandroidwebapp' in user_agent.lower():
- return True
- else:
- return False
-
-
-def check_request_android(request):
- """
-
- :param request:
- :return: boolean
- """
- if request.META.get('HTTP_USER_AGENT'):
- return is_android_webview(request.META.get('HTTP_USER_AGENT'))
- else:
- return False