-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
daemon_get_login.py
96 lines (90 loc) · 3.8 KB
/
daemon_get_login.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
__filename__ = "daemon_get_login.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.5.0"
__maintainer__ = "Bob Mottram"
__email__ = "[email protected]"
__status__ = "Production"
__module_group__ = "Core GET"
from utils import get_instance_url
from utils import string_ends_with
from utils import string_contains
from httpcodes import write2
from httpheaders import login_headers
from httpheaders import redirect_headers
from fitnessFunctions import fitness_performance
from webapp_login import html_login
def redirect_to_login_screen(self, calling_domain: str, path: str,
http_prefix: str, domain_full: str,
onion_domain: str, i2p_domain: str,
getreq_start_time,
authorized: bool, debug: bool,
news_instance: bool, fitness: {}) -> bool:
"""Redirects to the login screen if necessary
"""
divert_to_login_screen = False
non_login_paths = ('/media/', '/ontologies/', '/data/', '/sharefiles/',
'/statuses/', '/emoji/', '/tags/', '/tagmaps/',
'/avatars/', '/favicons/', '/headers/', '/fonts/',
'/icons/')
if not string_contains(path, non_login_paths):
divert_to_login_screen = True
if path.startswith('/users/'):
nick_str = path.split('/users/')[1]
if '/' not in nick_str and '?' not in nick_str:
divert_to_login_screen = False
else:
possible_endings = ('/following', '/followers',
'/skills', '/roles', '/wanted', '/shares')
if string_ends_with(path, possible_endings):
divert_to_login_screen = False
if divert_to_login_screen and not authorized:
divert_path = '/login'
if news_instance:
# for news instances if not logged in then show the
# front page
divert_path = '/users/news'
if debug:
print('DEBUG: divert_to_login_screen=' +
str(divert_to_login_screen))
print('DEBUG: authorized=' + str(authorized))
print('DEBUG: path=' + path)
redirect_url = \
get_instance_url(calling_domain,
http_prefix, domain_full,
onion_domain, i2p_domain) + \
divert_path
redirect_headers(self, redirect_url, None, calling_domain, 303)
fitness_performance(getreq_start_time, fitness,
'_GET', '_redirect_to_login_screen',
debug)
return True
return False
def show_login_screen(path: str, authorized: bool,
news_instance: bool,
translate: {},
base_dir: str,
http_prefix: str,
domain_full: str,
system_language: str,
ua_str: str, theme_name: str,
calling_domain: str,
getreq_start_time,
fitness: {}, debug: bool,
self) -> bool:
""" Shows the login screen
"""
if path.startswith('/login') or \
(path == '/' and not authorized and not news_instance):
# request basic auth
msg = html_login(translate, base_dir,
http_prefix, domain_full,
system_language, True, ua_str,
theme_name).encode('utf-8')
msglen = len(msg)
login_headers(self, 'text/html', msglen, calling_domain)
write2(self, msg)
fitness_performance(getreq_start_time, fitness,
'_GET', 'login shown', debug)
return True
return False