Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_account.py @ 3454:ddff0ade14d6
doc (jp/message): typo
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 02 Jan 2021 17:08:11 +0100 |
parents | df775db4c49b |
children | be6d91572633 |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
2180
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # jp: a SAT command line tool |
3136 | 5 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) |
2180
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 """This module permits to manage XMPP accounts using in-band registration (XEP-0077)""" |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from sat_frontends.jp.constants import Const as C |
3435
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
23 from sat_frontends.bridge.bridge_frontend import BridgeException |
2180
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from sat.core.log import getLogger |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from sat.core.i18n import _ |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from sat_frontends.jp import base |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from sat_frontends.tools import jid |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
3435
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
29 |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
30 log = getLogger(__name__) |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
31 |
2180
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 __commands__ = ["Account"] |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 class AccountCreate(base.CommandBase): |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
37 super(AccountCreate, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
38 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
39 "create", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
40 use_profile=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
41 use_verbose=True, |
3028 | 42 help=_("create a XMPP account"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
43 ) |
2180
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
46 self.parser.add_argument( |
3028 | 47 "jid", help=_("jid to create") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
48 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
49 self.parser.add_argument( |
3028 | 50 "password", help=_("password of the account") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
51 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
52 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
53 "-p", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
54 "--profile", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
55 help=_( |
3028 | 56 "create a profile to use this account (default: don't create profile)" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
57 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
58 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
59 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
60 "-e", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
61 "--email", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
62 default="", |
3028 | 63 help=_("email (usage depends of XMPP server)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
64 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
65 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
66 "-H", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
67 "--host", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
68 default="", |
3028 | 69 help=_("server host (IP address or domain, default: use localhost)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
70 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
71 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
72 "-P", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
73 "--port", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
74 type=int, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
75 default=0, |
3040 | 76 help=_(f"server port (default: {C.XMPP_C2S_PORT})"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
77 ) |
2180
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 |
3040 | 79 async def start(self): |
80 try: | |
81 await self.host.bridge.inBandAccountNew( | |
82 self.args.jid, | |
83 self.args.password, | |
84 self.args.email, | |
85 self.args.host, | |
86 self.args.port, | |
87 ) | |
3435
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
88 |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
89 except BridgeException as e: |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
90 if e.condition == 'conflict': |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
91 self.disp( |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
92 f"The account {self.args.jid} already exists", |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
93 error=True |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
94 ) |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
95 self.host.quit(C.EXIT_CONFLICT) |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
96 else: |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
97 self.disp( |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
98 f"can't create account on {self.args.host or 'localhost'!r} with jid " |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
99 f"{self.args.jid!r} using In-Band Registration: {e}", error=True) |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
100 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
3040 | 101 except Exception as e: |
3435
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
102 self.disp(f"Internal error: {e}", error=True) |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
103 self.host.quit(C.EXIT_INTERNAL_ERROR) |
2180
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 |
3040 | 105 self.disp(_("XMPP account created"), 1) |
106 | |
107 if self.args.profile is None: | |
108 self.host.quit() | |
2180
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 |
3040 | 110 |
111 self.disp(_("creating profile"), 2) | |
112 try: | |
113 await self.host.bridge.profileCreate( | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
114 self.args.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
115 self.args.password, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
116 "", |
3040 | 117 ) |
3435
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
118 except BridgeException as e: |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
119 if e.condition == 'conflict': |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
120 self.disp( |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
121 f"The profile {self.args.profile} already exists", |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
122 error=True |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
123 ) |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
124 self.host.quit(C.EXIT_CONFLICT) |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
125 else: |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
126 self.disp( |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
127 _(f"Can't create profile {self.args.profile} to associate with jid " |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
128 f"{self.args.jid}: {e}"), |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
129 error=True, |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
130 ) |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
131 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
3040 | 132 except Exception as e: |
3435
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
133 self.disp(f"Internal error: {e}", error=True) |
df775db4c49b
jp (account): better exit code handling
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
134 self.host.quit(C.EXIT_INTERNAL_ERROR) |
3040 | 135 |
136 self.disp(_("profile created"), 1) | |
137 try: | |
138 await self.host.bridge.profileStartSession( | |
139 self.args.password, | |
140 self.args.profile, | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
141 ) |
3040 | 142 except Exception as e: |
143 self.disp(f"can't start profile session: {e}", error=True) | |
144 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2180
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 |
3040 | 146 try: |
147 await self.host.bridge.setParam( | |
148 "JabberID", | |
149 self.args.jid, | |
150 "Connection", | |
151 profile_key=self.args.profile, | |
152 ) | |
153 except Exception as e: | |
154 self.disp(f"can't set JabberID parameter: {e}", error=True) | |
155 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
156 | |
157 try: | |
158 await self.host.bridge.setParam( | |
159 "Password", | |
160 self.args.password, | |
161 "Connection", | |
162 profile_key=self.args.profile, | |
163 ) | |
164 except Exception as e: | |
165 self.disp(f"can't set Password parameter: {e}", error=True) | |
166 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
167 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
168 self.disp( |
3040 | 169 f"profile {self.args.profile} successfully created and associated to the new " |
170 f"account", 1) | |
171 self.host.quit() | |
2180
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 class AccountModify(base.CommandBase): |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
176 super(AccountModify, self).__init__( |
3028 | 177 host, "modify", help=_("change password for XMPP account") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
178 ) |
2180
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
181 self.parser.add_argument( |
3028 | 182 "password", help=_("new XMPP password") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
183 ) |
2180
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 |
3040 | 185 async def start(self): |
186 try: | |
187 await self.host.bridge.inBandPasswordChange( | |
188 self.args.password, | |
189 self.args.profile, | |
190 ) | |
191 except Exception as e: | |
192 self.disp(f"can't change XMPP password: {e}", error=True) | |
193 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
194 else: | |
195 self.host.quit() | |
2180
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 class AccountDelete(base.CommandBase): |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
200 super(AccountDelete, self).__init__( |
3028 | 201 host, "delete", help=_("delete a XMPP account") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
202 ) |
2180
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
205 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
206 "-f", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
207 "--force", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
208 action="store_true", |
3028 | 209 help=_("delete account without confirmation"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
210 ) |
2180
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 |
3040 | 212 async def start(self): |
213 try: | |
214 jid_str = await self.host.bridge.asyncGetParamA( | |
215 "JabberID", | |
216 "Connection", | |
217 profile_key=self.profile, | |
218 ) | |
219 except Exception as e: | |
220 self.disp(f"can't get JID of the profile: {e}", error=True) | |
221 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
222 | |
2180
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 jid_ = jid.JID(jid_str) |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 if not self.args.force: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
225 message = ( |
3040 | 226 f"You are about to delete the XMPP account with jid {jid_!r}\n" |
227 f"This is the XMPP account of profile {self.profile!r}\n" | |
228 f"Are you sure that you want to delete this account?" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
229 ) |
3040 | 230 await self.host.confirmOrQuit(message, _("Account deletion cancelled")) |
2180
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 |
3040 | 232 try: |
233 await self.host.bridge.inBandUnregister(jid_.domain, self.args.profile) | |
234 except Exception as e: | |
235 self.disp(f"can't delete XMPP account with jid {jid_!r}: {e}", error=True) | |
236 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
237 | |
238 self.host.quit() | |
2180
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 class Account(base.CommandBase): |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 subcommands = (AccountCreate, AccountModify, AccountDelete) |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 |
be54e1c3394c
jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
245 super(Account, self).__init__( |
3028 | 246 host, "account", use_profile=False, help=("XMPP account management") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
247 ) |