mirror of
https://github.com/haiwen/seahub.git
synced 2025-10-20 10:20:42 +00:00
change user scalable in different devices (#6051)
This commit is contained in:
@@ -98,3 +98,82 @@ class ForcePasswdChangeMiddleware(MiddlewareMixin):
|
||||
if request.session.get('force_passwd_change', False):
|
||||
if self._request_in_black_list(request):
|
||||
return HttpResponseRedirect(reverse('auth_password_change'))
|
||||
|
||||
class UserAgentMiddleWare(MiddlewareMixin):
|
||||
user_agents_test_match = (
|
||||
"w3c ", "acs-", "alav", "alca", "amoi", "audi",
|
||||
"avan", "benq", "bird", "blac", "blaz", "brew",
|
||||
"cell", "cldc", "cmd-", "dang", "doco", "eric",
|
||||
"hipt", "inno", "ipaq", "java", "jigs", "kddi",
|
||||
"keji", "leno", "lg-c", "lg-d", "lg-g", "lge-",
|
||||
"maui", "maxo", "midp", "mits", "mmef", "mobi",
|
||||
"mot-", "moto", "mwbp", "nec-", "newt", "noki",
|
||||
"xda", "palm", "pana", "pant", "phil", "play",
|
||||
"port", "prox", "qwap", "sage", "sams", "sany",
|
||||
"sch-", "sec-", "send", "seri", "sgh-", "shar",
|
||||
"sie-", "siem", "smal", "smar", "sony", "sph-",
|
||||
"symb", "t-mo", "teli", "tim-", "tosh", "tsm-",
|
||||
"upg1", "upsi", "vk-v", "voda", "wap-", "wapa",
|
||||
"wapi", "wapp", "wapr", "webc", "winw", "xda-",)
|
||||
user_agents_test_search = u"(?:%s)" % u'|'.join((
|
||||
'up.browser', 'up.link', 'mmp', 'symbian', 'smartphone', 'midp',
|
||||
'wap', 'phone', 'windows ce', 'pda', 'mobile', 'mini', 'palm',
|
||||
'netfront', 'opera mobi',
|
||||
))
|
||||
user_agents_exception_search = u"(?:%s)" % u'|'.join((
|
||||
'ipad',
|
||||
))
|
||||
http_accept_regex = re.compile("application/vnd\.wap\.xhtml\+xml", re.IGNORECASE)
|
||||
user_agents_android_search = u"(?:android)"
|
||||
user_agents_mobile_search = u"(?:mobile)"
|
||||
user_agents_tablets_search = u"(?:%s)" % u'|'.join(('ipad', 'tablet', ))
|
||||
|
||||
def __init__(self, get_response=None):
|
||||
self.get_response = get_response
|
||||
|
||||
# these for detect mobile
|
||||
user_agents_test_match = r'^(?:%s)' % '|'.join(self.user_agents_test_match)
|
||||
self.user_agents_test_match_regex = re.compile(user_agents_test_match, re.IGNORECASE)
|
||||
self.user_agents_test_search_regex = re.compile(self.user_agents_test_search, re.IGNORECASE)
|
||||
self.user_agents_exception_search_regex = re.compile(self.user_agents_exception_search, re.IGNORECASE)
|
||||
|
||||
# these three used to detect tablet
|
||||
self.user_agents_android_search_regex = re.compile(self.user_agents_android_search, re.IGNORECASE)
|
||||
self.user_agents_mobile_search_regex = re.compile(self.user_agents_mobile_search, re.IGNORECASE)
|
||||
self.user_agents_tablets_search_regex = re.compile(self.user_agents_tablets_search, re.IGNORECASE)
|
||||
|
||||
def process_request(self, request):
|
||||
is_mobile = False
|
||||
is_tablet = False
|
||||
|
||||
if 'HTTP_USER_AGENT' in request.META:
|
||||
user_agent = request.META['HTTP_USER_AGENT']
|
||||
|
||||
# Test common mobile values.
|
||||
if self.user_agents_test_search_regex.search(user_agent) and \
|
||||
not self.user_agents_exception_search_regex.search(user_agent):
|
||||
is_mobile = True
|
||||
else:
|
||||
# Nokia like test for WAP browsers.
|
||||
# http://www.developershome.com/wap/xhtmlmp/xhtml_mp_tutorial.asp?page=mimeTypesFileExtension
|
||||
|
||||
if 'HTTP_ACCEPT' in request.META:
|
||||
http_accept = request.META['HTTP_ACCEPT']
|
||||
if self.http_accept_regex.search(http_accept):
|
||||
is_mobile = True
|
||||
|
||||
if not is_mobile:
|
||||
# Now we test the user_agent from a big list.
|
||||
if self.user_agents_test_match_regex.match(user_agent):
|
||||
is_mobile = True
|
||||
|
||||
# Ipad or Blackberry
|
||||
if self.user_agents_tablets_search_regex.search(user_agent):
|
||||
is_tablet = True
|
||||
# Android-device. If User-Agent doesn't contain Mobile, then it's a tablet
|
||||
elif (self.user_agents_android_search_regex.search(user_agent) and
|
||||
not self.user_agents_mobile_search_regex.search(user_agent)):
|
||||
is_tablet = True
|
||||
|
||||
request.is_mobile = is_mobile
|
||||
request.is_tablet = is_tablet
|
||||
|
@@ -139,6 +139,7 @@ MIDDLEWARE = [
|
||||
'seahub.two_factor.middleware.ForceTwoFactorAuthMiddleware',
|
||||
'seahub.trusted_ip.middleware.LimitIpMiddleware',
|
||||
'seahub.organizations.middleware.RedirectMiddleware',
|
||||
'seahub.base.middleware.UserAgentMiddleWare',
|
||||
]
|
||||
|
||||
SITE_ROOT_URLCONF = 'seahub.urls'
|
||||
|
@@ -8,7 +8,11 @@
|
||||
<meta name="keywords" content="{% trans "File, Collaboration, Team, Organization" %}" />
|
||||
{% if site_description != '' %}<meta name="description" content="{{ site_description }}" />{% endif %}
|
||||
{% block viewport %}
|
||||
{% if request.is_mobile or request.is_tablet %}
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
|
||||
{% else %}
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge" />
|
||||
<link rel="icon" href="{{ MEDIA_URL }}{{ favicon_path }}" type="image/x-icon">
|
||||
|
@@ -9,7 +9,11 @@
|
||||
<meta name="keywords" content="{% trans "File, Collaboration, Team, Organization" %}" />
|
||||
{% if site_description != '' %}<meta name="description" content="{{ site_description }}" />{% endif %}
|
||||
{% block viewport %}
|
||||
{% if request.is_mobile or request.is_tablet %}
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
|
||||
{% else %}
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block extra_ogp_tags %}{% endblock %}
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge" />
|
||||
|
@@ -4,7 +4,11 @@
|
||||
<html lang="{{ LANGUAGE_CODE }}">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
{% if request.is_mobile or request.is_tablet %}
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
|
||||
{% else %}
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
{% endif %}
|
||||
<title>{{ filename }}</title>
|
||||
|
||||
<link rel="icon" href="{{ MEDIA_URL }}{{ favicon_path }}" id="favicon" />
|
||||
|
@@ -4,7 +4,11 @@
|
||||
<html lang="{{ LANGUAGE_CODE }}">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
{% if request.is_mobile or request.is_tablet %}
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
|
||||
{% else %}
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
{% endif %}
|
||||
<title>{{ filename }}</title>
|
||||
|
||||
<link rel="icon" href="{{ MEDIA_URL }}{{ favicon_path }}" id="favicon" />
|
||||
|
@@ -2,7 +2,11 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>{% block title %}{% endblock %}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
{% if request.is_mobile or request.is_tablet %}
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
|
||||
{% else %}
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
{% endif %}
|
||||
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.2/css/bootstrap.min.css" rel="stylesheet" media="screen">
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7/html5shiv.js"></script>
|
||||
|
Reference in New Issue
Block a user