1
0
mirror of https://github.com/moparisthebest/mail synced 2024-08-13 16:43:47 -04:00
mail/src/js/controller/login/add-account.js

75 lines
2.5 KiB
JavaScript
Raw Normal View History

2014-10-02 16:05:44 -04:00
'use strict';
2014-01-27 12:50:13 -05:00
var AddAccountCtrl = function($scope, $location, $routeParams, mailConfig, auth, dialog) {
!$routeParams.dev && !auth.isInitialized() && $location.path('/'); // init app
$scope.getAccountSettings = function() {
2014-10-02 16:05:44 -04:00
if ($scope.form.$invalid) {
$scope.errMsg = 'Please enter a valid email address!';
2014-10-02 16:05:44 -04:00
return;
}
$scope.busy = true;
$scope.errMsg = undefined; // reset error msg
return mailConfig.get($scope.emailAddress).then(function(config) {
$scope.busy = false;
$scope.state.login = {
mailConfig: config,
emailAddress: $scope.emailAddress
};
2014-10-02 16:05:44 -04:00
var hostname = config.imap.hostname;
if (auth.useOAuth(hostname)) {
// check for oauth support
$scope.oauthPossible();
} else {
// use standard password login
2014-11-10 12:36:26 -05:00
$scope.setCredentials();
2014-09-19 12:59:13 -04:00
}
2014-11-09 11:34:48 -05:00
}).catch(function() {
$scope.busy = false;
$scope.errMsg = 'Error fetching IMAP settings for that email address!';
2014-10-02 16:05:44 -04:00
});
};
$scope.oauthPossible = function() {
// ask user to use the platform's native OAuth api
dialog.confirm({
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) {
// query oauth token
getOAuthToken();
} else {
// use normal user/password login
$scope.setCredentials();
$scope.$apply();
2014-09-19 12:59:13 -04:00
}
}
});
function getOAuthToken() {
2014-11-10 12:36:26 -05:00
// fetches the email address from the chrome identity api
auth.getOAuthToken(function(err) {
2014-11-10 12:36:26 -05:00
if (err) {
return dialog.error(err);
2014-11-10 12:36:26 -05:00
}
$scope.setCredentials();
2014-11-10 12:36:26 -05:00
$scope.$apply();
});
}
};
2014-10-02 16:05:44 -04:00
$scope.setCredentials = function() {
$location.path('/login-set-credentials');
2014-11-10 12:36:26 -05:00
};
2014-10-02 16:05:44 -04:00
};
2014-01-27 12:50:13 -05:00
2014-10-08 06:34:34 -04:00
module.exports = AddAccountCtrl;