summaryrefslogtreecommitdiffstats
path: root/py-bin/setup.py
diff options
context:
space:
mode:
Diffstat (limited to 'py-bin/setup.py')
-rw-r--r--py-bin/setup.py140
1 files changed, 140 insertions, 0 deletions
diff --git a/py-bin/setup.py b/py-bin/setup.py
new file mode 100644
index 0000000..1978dd1
--- /dev/null
+++ b/py-bin/setup.py
@@ -0,0 +1,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
+ \ No newline at end of file