From 074914044de92b07d2856de73da23323d0f174fb Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Sat, 8 Nov 2014 13:02:24 +0100 Subject: [PATCH] Add faq links and rework google/password login workflow --- src/js/controller/add-account.js | 75 +++++++++++++++------- src/js/controller/login-set-credentials.js | 34 +++++----- src/tpl/add-account.html | 9 +-- src/tpl/create-account.html | 2 +- src/tpl/login-set-credentials.html | 16 ++--- 5 files changed, 85 insertions(+), 51 deletions(-) diff --git a/src/js/controller/add-account.js b/src/js/controller/add-account.js index dd5a9cd..0580601 100644 --- a/src/js/controller/add-account.js +++ b/src/js/controller/add-account.js @@ -22,49 +22,80 @@ var AddAccountCtrl = function($scope, $location, $routeParams, $http) { $http.get(url).success(function(config) { $scope.busy = false; - $scope.state.mailConfig = config; - $scope.state.emailAddress = $scope.emailAddress; + $scope.state.login = { + mailConfig: config, + emailAddress: $scope.emailAddress + }; - // check for gmail/oauth server var hostname = config.imap.hostname; - if (hostname.match(/.gmail.com$/) || hostname.match(/.googlemail.com$/)) { + if (hostname && hostname.match(/.gmail.com$/) || hostname.match(/.googlemail.com$/)) { + // check for gmail/oauth support $scope.connectToGoogle(); - return; + } else if (config.imap.source === 'guess') { + // use standard password login... show config details due to guess + setCredentials('custom'); + } else { + // use standard password login... hide config details + setCredentials(); } }).error(function() { $scope.busy = false; - $scope.errMsg = 'Error getting IMAP settings for that email address!'; + $scope.errMsg = 'Error fetching IMAP settings for that email address!'; }); }; $scope.connectToGoogle = function() { // test for oauth support if (appCtrl._auth._oauth.isSupported()) { - // fetches the email address from the chrome identity api - appCtrl._auth.getOAuthToken(function(err) { - if (err) { - return $scope.onError(err); + // ask user to use the platform's native OAuth api + $scope.onError({ + title: 'Google Account Login', + message: 'You are signing into a Google account. Would you like to sign in with Google or just continue with a password login?', + positiveBtnStr: 'Google sign in', + negativeBtnStr: 'Password', + showNegativeBtn: true, + faqLink: 'https://github.com/whiteout-io/mail-html5/wiki/FAQ#how-does-sign-in-with-google-work', + callback: function(granted) { + if (granted) { + useOAuth(); + } else { + setGmailPassword(); + $scope.$apply(); + } } - $location.path('/login-set-credentials').search({ - provider: 'gmail' - }); - $scope.$apply(); }); - return; + } else { + // no oauth support + setGmailPassword(); } - - // use normal user/password login - $location.path('/login-set-credentials').search({ - provider: 'gmail' - }); }; - $scope.connectTo = function(provider) { + // + // Helper functions + // + + function useOAuth() { + // fetches the email address from the chrome identity api + appCtrl._auth.getOAuthToken(function(err) { + if (err) { + return $scope.onError(err); + } + setCredentials('gmail'); + $scope.$apply(); + }); + } + + function setGmailPassword() { + // use normal user/password login + setCredentials('gmail'); + } + + function setCredentials(provider) { $location.path('/login-set-credentials').search({ provider: provider }); - }; + } }; module.exports = AddAccountCtrl; \ No newline at end of file diff --git a/src/js/controller/login-set-credentials.js b/src/js/controller/login-set-credentials.js index 9a208ab..a8c6d97 100644 --- a/src/js/controller/login-set-credentials.js +++ b/src/js/controller/login-set-credentials.js @@ -21,44 +21,46 @@ var SetCredentialsCtrl = function($scope, $location, $routeParams) { // var provider = $location.search().provider; - $scope.hasProviderPreset = !!config[provider]; + $scope.hasProviderPreset = ($scope.state.login && $scope.state.login.mailConfig); $scope.useOAuth = !!auth.oauthToken; $scope.showDetails = (provider === 'custom'); + // set email address if ($scope.useOAuth) { $scope.emailAddress = auth.emailAddress; - } else if ($scope.state.emailAddress) { - $scope.emailAddress = $scope.state.emailAddress; + } else if ($scope.state.login) { + $scope.emailAddress = $scope.state.login.emailAddress; } if ($scope.hasProviderPreset) { - // use non-editable presets + // use editable presets + var mailConfig = $scope.state.login.mailConfig; // SMTP config - $scope.smtpHost = config[provider].smtp.host; - $scope.smtpPort = config[provider].smtp.port; - $scope.smtpCert = config[provider].smtp.ca; - $scope.smtpPinned = config[provider].smtp.pinned; + $scope.smtpHost = mailConfig.smtp.hostname; + $scope.smtpPort = parseInt(mailConfig.smtp.port, 10); + // $scope.smtpCert = config[provider].smtp.ca; + // $scope.smtpPinned = config[provider].smtp.pinned; // transport encryption method - if (config[provider].smtp.secure && !config[provider].smtp.ignoreTLS) { + if (mailConfig.smtp.secure && !mailConfig.smtp.ignoreTLS) { $scope.smtpEncryption = ENCRYPTION_METHOD_TLS; - } else if (!config[provider].smtp.secure && !config[provider].smtp.ignoreTLS) { + } else if (!mailConfig.smtp.secure && !mailConfig.smtp.ignoreTLS) { $scope.smtpEncryption = ENCRYPTION_METHOD_STARTTLS; } else { $scope.smtpEncryption = ENCRYPTION_METHOD_NONE; } // IMAP config - $scope.imapHost = config[provider].imap.host; - $scope.imapPort = config[provider].imap.port; - $scope.imapCert = config[provider].imap.ca; - $scope.imapPinned = config[provider].imap.pinned; + $scope.imapHost = mailConfig.imap.hostname; + $scope.imapPort = parseInt(mailConfig.imap.port, 10); + // $scope.imapCert = config[provider].imap.ca; + // $scope.imapPinned = config[provider].imap.pinned; // transport encryption method - if (config[provider].imap.secure && !config[provider].imap.ignoreTLS) { + if (mailConfig.imap.secure && !mailConfig.imap.ignoreTLS) { $scope.imapEncryption = ENCRYPTION_METHOD_TLS; - } else if (!config[provider].imap.secure && !config[provider].imap.ignoreTLS) { + } else if (!mailConfig.imap.secure && !mailConfig.imap.ignoreTLS) { $scope.imapEncryption = ENCRYPTION_METHOD_STARTTLS; } else { $scope.imapEncryption = ENCRYPTION_METHOD_NONE; diff --git a/src/tpl/add-account.html b/src/tpl/add-account.html index 345f263..e65d033 100644 --- a/src/tpl/add-account.html +++ b/src/tpl/add-account.html @@ -4,14 +4,15 @@ whiteout.io
-

Connect email account

-

Connect the Whiteout Mail client to your existing email account via IMAP for easy to use end-to-end encryption. We cannot read your password or messages. Learn more

+

Connect your email account

+

Connect the Whiteout Mail client to your existing email account via IMAP for easy to use end-to-end encryption. We cannot read your password or messages. Learn more

{{errMsg}}

-

Please fill out all required fields!

+

Please enter a valid email address!

- +
diff --git a/src/tpl/create-account.html b/src/tpl/create-account.html index ea46e7b..f5364b3 100644 --- a/src/tpl/create-account.html +++ b/src/tpl/create-account.html @@ -5,7 +5,7 @@

Create Whiteout account

-

Please fill out the following form. You will need a beta access code during the private beta period.

+

Please fill out the following form. You will need a beta access code during the private beta period. To participate in the private beta just get in touch.

{{errMsg}}

Please fill out all required fields!

diff --git a/src/tpl/login-set-credentials.html b/src/tpl/login-set-credentials.html index 1a1695c..cf3374f 100644 --- a/src/tpl/login-set-credentials.html +++ b/src/tpl/login-set-credentials.html @@ -6,10 +6,10 @@

Login

- Please enter your email address and password. The password is used to authenticate with your mail provider over an encrypted connection. We cannot read your password. Learn more + Please enter your password. The password is used to authenticate with your mail provider over an encrypted connection. We cannot read your password. Learn more

- Please confirm your email address. Your account will authenticate with your mail provider over an encrypted connection. Learn more + Please confirm the Google account your device is currently logged into. If you have multiple Google accounts and need help, please click here.

@@ -61,19 +61,19 @@ IMAP
-
-