summaryrefslogtreecommitdiffstats
path: root/py-bin/setup.py
blob: 1978dd16e134e1c2f715f42142f6e4e0bd46b1fd (plain)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#jabber setup
from lib.jon.cgi import html_encode, url_encode
import config

class SetupMixIn:
	def setup_main(self, req):
		user = self.__authenticate(req)
		if not user:
			return
		
		paras = dict(user_id=user.get_user_id(), jabber_id=user.get_default_jabber_id())
		acc_list = map(self.__get_delete_tuple, user.get_extra_account_list())
		self.render_template(req, "setup_main.em", paras, dict(account_list=acc_list))
	setup_main.web_callable = True
	
	def __get_delete_tuple(self, account):
		url = self.make_url([("cmd","delete_account_ask"), ("account",account)])
		return (html_encode(account), url)
	
	def set_pw_form(self, req):
		user = self.__authenticate(req)
		if not user:
			return
		
		last_error = req.params.get("error", "")
		self.render_template(req, "set_pw_form.em",
			dict(user_id=user.get_user_id(), error=last_error))
	set_pw_form.web_callable = True
		
	def set_pw_process(self, req):
		user = self.__authenticate(req)
		if not user:
			return
		
		password = req.params.get("password", "")
		password2 = req.params.get("password2", "")
			
		ok, status = self.jman.is_acceptable_password(password, password2)
		if not ok:
			url = self.make_url([("cmd","set_pw_form"), ("error", status)])
			self.redirect_to(req, url)
			return
		
		self.jman.change_password(password)
		self.__redirect_to_main(req)
	set_pw_process.web_callable = True
	
	def add_account_form(self, req):
		user = self.__authenticate(req)
		if not user:
			return
			
		last_err = req.params.get("error", "")
		domains = config.extra_domains
		
		self.render_template(req, "add_account_form.em",
			dict(user_id=user.get_user_id(), domains=domains, error=last_err))
	add_account_form.web_callable = True
	
	def add_account_process(self, req):
		user = self.__authenticate(req)
		if not user:
			return
		
		domain = req.params.get("domain", "")
		account = req.params.get("name", "") + "@" + domain
		
		if domain not in config.extra_domains:
			self.error_page(req, "Zugriff verweigert.")
			return
		
		ok, status = self.jman.add_account(account)
		if not ok:
			url = self.make_url([("cmd","add_account_form"), ("error", status)])
			self.redirect_to(req, url)
			return
		
		self.__redirect_to_main(req)
	add_account_process.web_callable = True
	
	def delete_account_ask(self, req):
		user = self.__authenticate(req)
		if not user:
			return
		
		account = req.params.get("account", "")
		
		raw = dict(account_urlenc = url_encode(account))
		self.render_template(req, "delete_account_ask.em",
			dict(account=account, user_id=user.get_user_id()), raw)
	delete_account_ask.web_callable = True

	def delete_account_process(self, req):
		user = self.__authenticate(req)
		if not user:
			return
			
		account = req.params.get("account", "")
		
		ok, status = self.jman.remove_account(account)
		if not ok:
			self.error_page(req, status)
			return
		
		self.__redirect_to_main(req)
	delete_account_process.web_callable = True
	
	def help(self, req):
		user = self.__authenticate(req)
		if not user:
			return
		
		self.render_template(req, "setup_help.em",
			dict(user_id=user.get_user_id(),jabber_id=user.get_default_jabber_id()))
	help.web_callable = True
	
	def logout(self, req):
		user = self.__authenticate(req)
		if not user:
			return
		
		self.jman.logout()
		self.render_template(req, "logged_out.em")
	logout.web_callable = True
	
	def test(self, req):
		ctx = dict(user_id="alice@immerda.ch")
		self.render_template(req, "test.em", ctx)
	test.web_callable = True
	
	def __redirect_to_main(self, req):
		self.redirect_to(req, self.make_url([("cmd","setup_main")]))
	
	def __authenticate(self, req):
		ok, status_or_user = self.jman.authenticate()
		if not ok:
			self.redirect_to(req, config.script_url)
			return None
		return status_or_user