Merge lp:~canonical-platform-qa/checkbox/easing-login-pain into lp:checkbox

Proposed by Christopher Lee
Status: Work in progress
Proposed branch: lp:~canonical-platform-qa/checkbox/easing-login-pain
Merge into: lp:checkbox
Prerequisite: lp:~canonical-platform-qa/checkbox/lbuilding-on-oauth-community-testing
Diff against target: 132 lines (+79/-0)
2 files modified
checkbox-touch/sso-login.qml (+8/-0)
checkbox-touch/sso_login.py (+71/-0)
To merge this branch: bzr merge lp:~canonical-platform-qa/checkbox/easing-login-pain
Reviewer Review Type Date Requested Status
Checkbox Developers Pending
Review via email: mp+272867@code.launchpad.net

Commit message

make entering login details easier (pre-populate email address).

Description of the change

make entering login details easier (pre-populate email address).

To post a comment you must log in.

Unmerged revisions

4017. By Christopher Lee

Merge pre-req.

4016. By Christopher Lee

Cache succesful email address and prepopulate dialog.

4015. By Christopher Lee

Minor fix for sso qml

4014. By Christopher Lee

Use the correct service url in the json settings.

4013. By Christopher Lee

Small niceity, tabbing between email and password fields.

4012. By Christopher Lee

QML Dialog behaves better (greys out during request, closes properly).

4011. By Christopher Lee

Working against staging. Still needs qml error fixed/

4010. By Christopher Lee

Working initial workflow (without actuall signing/authentication)

4009. By Christopher Lee

Merge changes in trunk.

4008. By Maciej Kisielewski

fix for sso-login dialog

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'checkbox-touch/sso-login.qml'
2--- checkbox-touch/sso-login.qml 2015-09-30 06:19:15 +0000
3+++ checkbox-touch/sso-login.qml 2015-09-30 06:19:16 +0000
4@@ -37,6 +37,7 @@
5 property alias dialogComponent: component
6
7 property string prompt: ""
8+ property string cachedEmailAddress: ""
9
10 property bool needOtp: false
11
12@@ -52,6 +53,12 @@
13 addImportPath(Qt.resolvedUrl('.'));
14 py.importModule("sso_login", function() {
15 console.info("Successfully loaded sso login library.")
16+
17+ // prepopulate email address
18+ py.call('sso_login.get_email_address_from_cache', [], function(response) {
19+ cachedEmailAddress = response;
20+ });
21+ initiated();
22 }, function() {
23 console.error("Unable to load sso login library!")
24 });
25@@ -125,6 +132,7 @@
26 TextField {
27 id: emailBox
28 placeholderText: i18n.tr("email address")
29+ text: cachedEmailAddress
30 visible: !otpBox.visible
31 enabled: !dlgloading
32 Keys.onTabPressed: passwordBox.forceActiveFocus();
33
34=== modified file 'checkbox-touch/sso_login.py'
35--- checkbox-touch/sso_login.py 2015-09-30 06:19:15 +0000
36+++ checkbox-touch/sso_login.py 2015-09-30 06:19:16 +0000
37@@ -16,13 +16,18 @@
38 # You should have received a copy of the GNU General Public License
39 # along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
40
41+import configparser
42 import json
43+import logging
44 import os
45 import requests
46
47 from plainbox.impl.transport import TransportError
48
49
50+logger = logging.getLogger('checkbox.touch.sso_login')
51+
52+
53 class TwoFactorRequiredError(RuntimeError):
54 """Second factor authentication required."""
55
56@@ -109,6 +114,12 @@
57 except Exception as e:
58 return dict(code=500, message=str(e))
59
60+ try:
61+ logger.info('Caching email address.')
62+ cache_user_email_address(email)
63+ except Exception as e:
64+ logger.error('Failed to cache email address', str(e))
65+
66 return dict(
67 code=200,
68 message='Successfully authenticated.',
69@@ -144,3 +155,63 @@
70 return '\n'.join(reason_strings)
71 else:
72 return unknown_error_msg
73+
74+
75+def cache_user_email_address(email_address):
76+ """Writes email address to file."""
77+ parser = configparser.ConfigParser()
78+ parser.read(_get_email_storage_cache_file())
79+ with open(_get_email_storage_cache_file(), 'w') as f:
80+ if 'user_details' in parser.sections():
81+ parser['user_details']['email'] = email_address
82+ else:
83+ parser['user_details'] = dict(email=email_address)
84+ parser.write(f)
85+
86+
87+def get_email_address_from_cache():
88+ """Return email that has been cached.
89+
90+ Returns '' (empty string) if no email has been cached.
91+ """
92+ parser = configparser.ConfigParser()
93+ parser.read(_get_email_storage_cache_file())
94+ try:
95+ return parser['user_details']['email']
96+ except KeyError:
97+ return ''
98+
99+
100+def _get_email_storage_cache_file():
101+ return os.path.join(_get_app_cache_directory(), 'sso-login.cache')
102+
103+
104+def _get_app_cache_directory():
105+ # Based from checkbox_touch.py
106+ xdg_cache_home = os.environ.get(
107+ 'XDG_CACHE_HOME',
108+ os.path.expanduser('~/.cache')
109+ )
110+ try:
111+ app_id = os.environ['APP_ID']
112+ # Applications will always have write access to directories they
113+ # own as determined by the XDG base directory specification.
114+ # Specifically: XDG_CACHE_HOME/<APP_PKGNAME>
115+ # XDG_RUNTIME_DIR/<APP_PKGNAME>
116+ # XDG_RUNTIME_DIR/confined/<APP_PKGNAME> (for TMPDIR)
117+ # XDG_DATA_HOME/<APP_PKGNAME>
118+ # XDG_CONFIG_HOME/<APP_PKGNAME>
119+ # Note that <APP_PKGNAME> is not the APP_ID. In order to easily
120+ # handle upgrades and sharing data between executables in the same
121+ # app, we use the unversioned app package name for the writable
122+ # directories.
123+ return os.path.join(xdg_cache_home, app_id.split('_')[0])
124+ except KeyError:
125+ path = os.path.join(xdg_cache_home, "com.ubuntu.checkbox")
126+ if not os.path.exists(path):
127+ os.makedirs(path)
128+ elif not os.path.isdir(path):
129+ # as unlikely as it is, situation where path exists and is a
130+ # regular file neeeds to be signalled
131+ raise IOError("{} exists and is not a directory".format(path))
132+ return path

Subscribers

People subscribed via source and target branches