annotate sat_frontends/jp/cmd_account.py @ 2866:8ce5748bfe97

plugin XEP-0363: updated to namespace "urn:xmpp:http:upload:0", handle headers
author Goffi <goffi@goffi.org>
date Fri, 22 Mar 2019 19:26:08 +0100
parents 003b8b4b56a7
children ab2696e34d29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
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
2771
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2765
diff changeset
5 # Copyright (C) 2009-2019 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
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat.core.log import getLogger
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
24
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
25 log = getLogger(__name__)
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.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
27 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
28 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
29
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
30 __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
31
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
32
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
33 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
34 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
35 super(AccountCreate, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
36 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
37 "create",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
38 use_profile=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
39 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
40 help=_(u"create a XMPP account"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
41 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
42 self.need_loop = True
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
43
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
44 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
45 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
46 "jid", type=base.unicode_decoder, help=_(u"jid to create")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
47 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
48 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 "password", type=base.unicode_decoder, help=_(u"password of the account")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
50 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
51 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
52 "-p",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
53 "--profile",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
54 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55 help=_(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
56 u"create a profile to use this account (default: don't create profile)"
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 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
63 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 help=_(u"email (usage depends of XMPP server)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
65 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
66 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
67 "-H",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 "--host",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
69 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 help=_(u"server host (IP address or domain, default: use localhost)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
72 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
74 "-P",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
75 "--port",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
76 type=int,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
77 default=0,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
78 help=_(u"server port (IP address or domain, default: use localhost)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
80
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
81 def _setParamCb(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
82 self.host.bridge.setParam(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
83 "Password",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
84 self.args.password,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
85 "Connection",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
86 profile_key=self.args.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
87 callback=self.host.quit,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
88 errback=self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
89 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
90
2765
378188abe941 misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
91 def _session_started(self, __):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
92 self.host.bridge.setParam(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
93 "JabberID",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 self.args.jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 "Connection",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
96 profile_key=self.args.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
97 callback=self._setParamCb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
98 errback=self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
99 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
100
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
101 def _profileCreateCb(self):
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
102 self.disp(_(u"profile created"), 1)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
103 self.host.bridge.profileStartSession(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
104 self.args.password,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
105 self.args.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
106 callback=self._session_started,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
107 errback=self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
108 )
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
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
110 def _profileCreateEb(self, failure_):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
111 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
112 _(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
113 u"Can't create profile {profile} to associate with jid {jid}: {msg}"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
114 ).format(profile=self.args.profile, jid=self.args.jid, msg=failure_),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
115 error=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
116 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
117 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
118
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
119 def accountNewCb(self):
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
120 self.disp(_(u"XMPP account created"), 1)
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
121 if self.args.profile is not None:
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
122 self.disp(_(u"creating profile"), 2)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
123 self.host.bridge.profileCreate(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
124 self.args.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
125 self.args.password,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
126 "",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
127 callback=self._profileCreateCb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
128 errback=self._profileCreateEb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
129 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
130 else:
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
131 self.host.quit()
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
132
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
133 def accountNewEb(self, failure_):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
134 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
135 _(u"Can't create new account on server {host} with jid {jid}: {msg}").format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
136 host=self.args.host or u"localhost", jid=self.args.jid, msg=failure_
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
137 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
138 error=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
139 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
140 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
141
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
142 def start(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
143 self.host.bridge.inBandAccountNew(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
144 self.args.jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
145 self.args.password,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
146 self.args.email,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
147 self.args.host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
148 self.args.port,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
149 callback=self.accountNewCb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
150 errback=self.accountNewEb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
151 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
152
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
153
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
154 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
155 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
156 super(AccountModify, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
157 host, "modify", help=_(u"change password for XMPP account")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
158 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
159 self.need_loop = True
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
160
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
161 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
162 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
163 "password", type=base.unicode_decoder, help=_(u"new XMPP password")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
164 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
165
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
166 def start(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
167 self.host.bridge.inBandPasswordChange(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
168 self.args.password,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169 self.args.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
170 callback=self.host.quit,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
171 errback=self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
172 )
2180
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
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
175 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
176 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
177 super(AccountDelete, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
178 host, "delete", help=_(u"delete a XMPP account")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
179 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
180 self.need_loop = True
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
181
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
182 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
183 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
184 "-f",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
185 "--force",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
186 action="store_true",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
187 help=_(u"delete account without confirmation"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
188 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
189
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
190 def _got_jid(self, 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
191 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
192 if not self.args.force:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
193 message = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
194 u"You are about to delete the XMPP account with jid {jid_}\n"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
195 u'This is the XMPP account of profile "{profile}"\n'
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
196 u"Are you sure that you want to delete this account ?".format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
197 jid_=jid_, profile=self.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
198 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
199 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
200 res = raw_input("{} (y/N)? ".format(message))
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
201 if res not in ("y", "Y"):
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
202 self.disp(_(u"Account deletion cancelled"))
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
203 self.host.quit(2)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
204 self.host.bridge.inBandUnregister(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
205 jid_.domain, self.args.profile, callback=self.host.quit, errback=self.errback
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
206 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
207
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
208 def start(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
209 self.host.bridge.asyncGetParamA(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
210 "JabberID",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
211 "Connection",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
212 profile_key=self.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
213 callback=self._got_jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
214 errback=self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
215 )
2180
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
216
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
217
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
218 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
219 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
220
be54e1c3394c jp (account): command to handle XMPP account creation/password change/deletion using in-band registration
Goffi <goffi@goffi.org>
parents:
diff changeset
221 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
222 super(Account, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
223 host, "account", use_profile=False, help=(u"XMPP account management")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
224 )