Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_register_account.py @ 3028:ab2696e34d29
Python 3 port:
/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time
This patch port backend, bridge and frontends to Python 3.
Roughly this has been done this way:
- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:08:41 +0200 |
parents | 003b8b4b56a7 |
children | 9d0df638c8b4 |
comparison
equal
deleted
inserted
replaced
3027:ff5bcb12ae60 | 3028:ab2696e34d29 |
---|---|
1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python3 |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 | 3 |
4 # SàT plugin for registering a new XMPP account | 4 # SàT plugin for registering a new XMPP account |
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) | 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) |
6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org) | 6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org) |
36 C.PI_PROTOCOLS: [], | 36 C.PI_PROTOCOLS: [], |
37 C.PI_DEPENDENCIES: ["XEP-0077"], | 37 C.PI_DEPENDENCIES: ["XEP-0077"], |
38 C.PI_RECOMMENDATIONS: [], | 38 C.PI_RECOMMENDATIONS: [], |
39 C.PI_MAIN: "RegisterAccount", | 39 C.PI_MAIN: "RegisterAccount", |
40 C.PI_HANDLER: "no", | 40 C.PI_HANDLER: "no", |
41 C.PI_DESCRIPTION: _(u"""Register XMPP account"""), | 41 C.PI_DESCRIPTION: _("""Register XMPP account"""), |
42 } | 42 } |
43 | 43 |
44 | 44 |
45 class RegisterAccount(object): | 45 class RegisterAccount(object): |
46 # FIXME: this plugin is messy and difficult to read, it needs to be cleaned up and documented | 46 # FIXME: this plugin is messy and difficult to read, it needs to be cleaned up and documented |
47 | 47 |
48 def __init__(self, host): | 48 def __init__(self, host): |
49 log.info(_(u"Plugin Register Account initialization")) | 49 log.info(_("Plugin Register Account initialization")) |
50 self.host = host | 50 self.host = host |
51 self._sessions = Sessions() | 51 self._sessions = Sessions() |
52 host.registerCallback( | 52 host.registerCallback( |
53 self.registerNewAccountCB, with_data=True, force_id="registerNewAccount" | 53 self.registerNewAccountCB, with_data=True, force_id="registerNewAccount" |
54 ) | 54 ) |
60 """Called when the user click on the "New account" button.""" | 60 """Called when the user click on the "New account" button.""" |
61 session_data = {} | 61 session_data = {} |
62 | 62 |
63 # FIXME: following loop is overcomplicated, hard to read | 63 # FIXME: following loop is overcomplicated, hard to read |
64 # FIXME: while used with parameters, hashed password is used and overwrite clear one | 64 # FIXME: while used with parameters, hashed password is used and overwrite clear one |
65 for param in (u"JabberID", u"Password", C.FORCE_PORT_PARAM, C.FORCE_SERVER_PARAM): | 65 for param in ("JabberID", "Password", C.FORCE_PORT_PARAM, C.FORCE_SERVER_PARAM): |
66 try: | 66 try: |
67 session_data[param] = data[ | 67 session_data[param] = data[ |
68 SAT_FORM_PREFIX + u"Connection" + SAT_PARAM_SEPARATOR + param | 68 SAT_FORM_PREFIX + "Connection" + SAT_PARAM_SEPARATOR + param |
69 ] | 69 ] |
70 except KeyError: | 70 except KeyError: |
71 if param in (C.FORCE_PORT_PARAM, C.FORCE_SERVER_PARAM): | 71 if param in (C.FORCE_PORT_PARAM, C.FORCE_SERVER_PARAM): |
72 session_data[param] = "" | 72 session_data[param] = "" |
73 | 73 |
74 for param in (u"JabberID", u"Password"): | 74 for param in ("JabberID", "Password"): |
75 if not session_data[param]: | 75 if not session_data[param]: |
76 form_ui = xml_tools.XMLUI(u"popup", title=D_(u"Missing values")) | 76 form_ui = xml_tools.XMLUI("popup", title=D_("Missing values")) |
77 form_ui.addText( | 77 form_ui.addText( |
78 D_(u"No user JID or password given: can't register new account.") | 78 D_("No user JID or password given: can't register new account.") |
79 ) | 79 ) |
80 return {u"xmlui": form_ui.toXml()} | 80 return {"xmlui": form_ui.toXml()} |
81 | 81 |
82 session_data["user"], host, resource = jid.parse(session_data["JabberID"]) | 82 session_data["user"], host, resource = jid.parse(session_data["JabberID"]) |
83 session_data["server"] = session_data[C.FORCE_SERVER_PARAM] or host | 83 session_data["server"] = session_data[C.FORCE_SERVER_PARAM] or host |
84 session_id, __ = self._sessions.newSession(session_data, profile=profile) | 84 session_id, __ = self._sessions.newSession(session_data, profile=profile) |
85 form_ui = xml_tools.XMLUI( | 85 form_ui = xml_tools.XMLUI( |
87 title=D_("Register new account"), | 87 title=D_("Register new account"), |
88 submit_id=self.__register_account_id, | 88 submit_id=self.__register_account_id, |
89 session_id=session_id, | 89 session_id=session_id, |
90 ) | 90 ) |
91 form_ui.addText( | 91 form_ui.addText( |
92 D_(u"Do you want to register a new XMPP account {jid}?").format( | 92 D_("Do you want to register a new XMPP account {jid}?").format( |
93 jid=session_data["JabberID"] | 93 jid=session_data["JabberID"] |
94 ) | 94 ) |
95 ) | 95 ) |
96 return {"xmlui": form_ui.toXml()} | 96 return {"xmlui": form_ui.toXml()} |
97 | 97 |
128 return d | 128 return d |
129 | 129 |
130 def _registerNewAccount(self, client, jid_, password, email, server): | 130 def _registerNewAccount(self, client, jid_, password, email, server): |
131 # FIXME: port is not set here | 131 # FIXME: port is not set here |
132 def registeredCb(__): | 132 def registeredCb(__): |
133 xmlui = xml_tools.XMLUI(u"popup", title=D_(u"Confirmation")) | 133 xmlui = xml_tools.XMLUI("popup", title=D_("Confirmation")) |
134 xmlui.addText(D_("Registration successful.")) | 134 xmlui.addText(D_("Registration successful.")) |
135 return {"xmlui": xmlui.toXml()} | 135 return {"xmlui": xmlui.toXml()} |
136 | 136 |
137 def registeredEb(failure): | 137 def registeredEb(failure): |
138 xmlui = xml_tools.XMLUI("popup", title=D_("Failure")) | 138 xmlui = xml_tools.XMLUI("popup", title=D_("Failure")) |