Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_register_account.py @ 4037:524856bd7b19
massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.
However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.
To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.
This is a massive change, and may result in some bugs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:54:42 +0200 |
parents | be6d91572633 |
children |
comparison
equal
deleted
inserted
replaced
4036:c4464d7ae97b | 4037:524856bd7b19 |
---|---|
47 | 47 |
48 def __init__(self, host): | 48 def __init__(self, host): |
49 log.info(_("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.register_callback( |
53 self.registerNewAccountCB, with_data=True, force_id="registerNewAccount" | 53 self.register_new_account_cb, with_data=True, force_id="register_new_account" |
54 ) | 54 ) |
55 self.__register_account_id = host.registerCallback( | 55 self.__register_account_id = host.register_callback( |
56 self._registerConfirmation, with_data=True | 56 self._register_confirmation, with_data=True |
57 ) | 57 ) |
58 | 58 |
59 def registerNewAccountCB(self, data, profile): | 59 def register_new_account_cb(self, data, profile): |
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 |
79 ) | 79 ) |
80 return {"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.new_session(session_data, profile=profile) |
85 form_ui = xml_tools.XMLUI( | 85 form_ui = xml_tools.XMLUI( |
86 "form", | 86 "form", |
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, |
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 |
98 def _registerConfirmation(self, data, profile): | 98 def _register_confirmation(self, data, profile): |
99 """Save the related parameters and proceed the registration.""" | 99 """Save the related parameters and proceed the registration.""" |
100 session_data = self._sessions.profileGet(data["session_id"], profile) | 100 session_data = self._sessions.profile_get(data["session_id"], profile) |
101 | 101 |
102 self.host.memory.setParam( | 102 self.host.memory.param_set( |
103 "JabberID", session_data["JabberID"], "Connection", profile_key=profile | 103 "JabberID", session_data["JabberID"], "Connection", profile_key=profile |
104 ) | 104 ) |
105 self.host.memory.setParam( | 105 self.host.memory.param_set( |
106 "Password", session_data["Password"], "Connection", profile_key=profile | 106 "Password", session_data["Password"], "Connection", profile_key=profile |
107 ) | 107 ) |
108 self.host.memory.setParam( | 108 self.host.memory.param_set( |
109 C.FORCE_SERVER_PARAM, | 109 C.FORCE_SERVER_PARAM, |
110 session_data[C.FORCE_SERVER_PARAM], | 110 session_data[C.FORCE_SERVER_PARAM], |
111 "Connection", | 111 "Connection", |
112 profile_key=profile, | 112 profile_key=profile, |
113 ) | 113 ) |
114 self.host.memory.setParam( | 114 self.host.memory.param_set( |
115 C.FORCE_PORT_PARAM, | 115 C.FORCE_PORT_PARAM, |
116 session_data[C.FORCE_PORT_PARAM], | 116 session_data[C.FORCE_PORT_PARAM], |
117 "Connection", | 117 "Connection", |
118 profile_key=profile, | 118 profile_key=profile, |
119 ) | 119 ) |
120 | 120 |
121 d = self._registerNewAccount( | 121 d = self._register_new_account( |
122 jid.JID(session_data["JabberID"]), | 122 jid.JID(session_data["JabberID"]), |
123 session_data["Password"], | 123 session_data["Password"], |
124 None, | 124 None, |
125 session_data["server"], | 125 session_data["server"], |
126 ) | 126 ) |
127 del self._sessions[data["session_id"]] | 127 del self._sessions[data["session_id"]] |
128 return d | 128 return d |
129 | 129 |
130 def _registerNewAccount(self, client, jid_, password, email, server): | 130 def _register_new_account(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 registered_cb(__): |
133 xmlui = xml_tools.XMLUI("popup", title=D_("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 registered_eb(failure): |
138 xmlui = xml_tools.XMLUI("popup", title=D_("Failure")) | 138 xmlui = xml_tools.XMLUI("popup", title=D_("Failure")) |
139 xmlui.addText(D_("Registration failed: %s") % failure.getErrorMessage()) | 139 xmlui.addText(D_("Registration failed: %s") % failure.getErrorMessage()) |
140 try: | 140 try: |
141 if failure.value.condition == "conflict": | 141 if failure.value.condition == "conflict": |
142 xmlui.addText( | 142 xmlui.addText( |
144 ) | 144 ) |
145 except AttributeError: | 145 except AttributeError: |
146 pass | 146 pass |
147 return {"xmlui": xmlui.toXml()} | 147 return {"xmlui": xmlui.toXml()} |
148 | 148 |
149 registered_d = self.host.plugins["XEP-0077"].registerNewAccount( | 149 registered_d = self.host.plugins["XEP-0077"].register_new_account( |
150 client, jid_, password, email=email, host=server, port=C.XMPP_C2S_PORT | 150 client, jid_, password, email=email, host=server, port=C.XMPP_C2S_PORT |
151 ) | 151 ) |
152 registered_d.addCallbacks(registeredCb, registeredEb) | 152 registered_d.addCallbacks(registered_cb, registered_eb) |
153 return registered_d | 153 return registered_d |