2016-07-27 04:05:47 +00:00
|
|
|
# Copyright 2015 Canonical, Ltd.
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
2017-02-03 01:20:05 +00:00
|
|
|
from urwid import Text
|
2016-07-27 10:15:22 +00:00
|
|
|
from subiquitycore.ui.buttons import done_btn, cancel_btn
|
2017-02-03 01:20:05 +00:00
|
|
|
from subiquitycore.ui.container import Columns, ListBox, Pile
|
2016-07-27 10:15:22 +00:00
|
|
|
from subiquitycore.ui.interactive import EmailEditor
|
|
|
|
from subiquitycore.ui.utils import Padding, Color
|
|
|
|
from subiquitycore.view import BaseView
|
2016-07-27 04:05:47 +00:00
|
|
|
|
|
|
|
log = logging.getLogger("console_conf.views.identity")
|
|
|
|
|
|
|
|
|
2016-07-27 10:15:22 +00:00
|
|
|
'''
|
|
|
|
+---------------------------------------------------+
|
|
|
|
| |
|
|
|
|
| Enter the email address of the account in the |
|
|
|
|
| store |
|
|
|
|
| |
|
|
|
|
| +-------------------------+ |
|
|
|
|
| Email address: | | |
|
|
|
|
| +-------------------------+ |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| +--------+ |
|
|
|
|
| | Done | |
|
|
|
|
| +--------+ |
|
|
|
|
| | Cancel | |
|
|
|
|
| +--------+ |
|
|
|
|
| |
|
|
|
|
+---------------------------------------------------+
|
|
|
|
'''
|
|
|
|
|
2016-09-09 04:08:37 +00:00
|
|
|
|
2016-07-27 10:15:22 +00:00
|
|
|
class IdentityView(BaseView):
|
|
|
|
|
2016-10-10 23:48:28 +00:00
|
|
|
def __init__(self, model, controller, opts, loop):
|
2016-07-27 10:15:22 +00:00
|
|
|
self.model = model
|
2016-10-10 23:48:28 +00:00
|
|
|
self.controller = controller
|
2016-07-27 10:15:22 +00:00
|
|
|
self.opts = opts
|
2016-07-28 02:34:48 +00:00
|
|
|
self.loop = loop
|
2016-07-27 10:15:22 +00:00
|
|
|
self.items = []
|
2017-02-14 02:22:43 +00:00
|
|
|
self.email = EmailEditor()
|
2016-07-27 10:15:22 +00:00
|
|
|
self.error = Text("", align="center")
|
2016-07-28 02:34:48 +00:00
|
|
|
self.progress = Text("", align="center")
|
2016-07-27 10:15:22 +00:00
|
|
|
|
|
|
|
body = [
|
|
|
|
Padding.center_90(self._build_model_inputs()),
|
|
|
|
Padding.line_break(""),
|
2016-11-10 00:47:15 +00:00
|
|
|
Padding.center_79(Color.info_minor(Text("If you do not have an account, visit https://login.ubuntu.com to create one."))),
|
|
|
|
Padding.line_break(""),
|
2016-07-27 10:15:22 +00:00
|
|
|
Padding.center_90(Color.info_error(self.error)),
|
2016-07-28 02:34:48 +00:00
|
|
|
Padding.center_90(self.progress),
|
2016-07-27 10:15:22 +00:00
|
|
|
Padding.line_break(""),
|
|
|
|
Padding.fixed_10(self._build_buttons()),
|
|
|
|
]
|
|
|
|
super().__init__(ListBox(body))
|
|
|
|
|
2017-02-14 02:22:43 +00:00
|
|
|
def keypress(self, size, key):
|
|
|
|
if key == 'enter':
|
|
|
|
self.done(None)
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return super().keypress(size, key)
|
|
|
|
|
2016-07-27 10:15:22 +00:00
|
|
|
def _build_model_inputs(self):
|
|
|
|
sl = [
|
|
|
|
Columns(
|
|
|
|
[
|
|
|
|
("weight", 0.2, Text("Email address:", align="right")),
|
2017-02-08 02:37:18 +00:00
|
|
|
("weight", 0.3, Color.string_input(self.email)),
|
2016-07-27 10:15:22 +00:00
|
|
|
],
|
|
|
|
dividechars=4
|
|
|
|
),
|
|
|
|
]
|
|
|
|
return Pile(sl)
|
|
|
|
|
|
|
|
def _build_buttons(self):
|
|
|
|
cancel = cancel_btn(on_press=self.cancel)
|
|
|
|
done = done_btn(on_press=self.done)
|
|
|
|
|
|
|
|
buttons = [
|
2017-02-08 02:37:18 +00:00
|
|
|
Color.button(done),
|
|
|
|
Color.button(cancel),
|
2016-07-27 10:15:22 +00:00
|
|
|
]
|
|
|
|
return Pile(buttons)
|
|
|
|
|
|
|
|
def cancel(self, button):
|
2016-10-10 23:48:28 +00:00
|
|
|
self.controller.cancel()
|
2016-07-27 10:15:22 +00:00
|
|
|
|
|
|
|
def done(self, button):
|
|
|
|
if len(self.email.value) < 1:
|
|
|
|
self.error.set_text("Please enter an email address.")
|
|
|
|
return
|
2016-10-10 23:48:28 +00:00
|
|
|
self.controller.identity_done(self.email.value)
|