1
0
mirror of https://github.com/moparisthebest/mail synced 2024-10-31 15:25:01 -04:00
mail/src/js/controller/login/login-set-credentials.js

102 lines
3.3 KiB
JavaScript
Raw Normal View History

2014-10-02 16:05:44 -04:00
'use strict';
var ENCRYPTION_METHOD_NONE = 0;
var ENCRYPTION_METHOD_STARTTLS = 1;
var ENCRYPTION_METHOD_TLS = 2;
var SetCredentialsCtrl = function($scope, $location, $routeParams, auth, connectionDoctor) {
!$routeParams.dev && !auth.isInitialized() && $location.path('/'); // init app
2014-10-02 16:05:44 -04:00
//
// Presets and Settings
//
var mailConfig = $scope.state.login.mailConfig;
2014-10-02 16:05:44 -04:00
$scope.useOAuth = !!auth.oauthToken;
$scope.showDetails = (mailConfig.imap.source === 'guess');
2014-10-02 16:05:44 -04:00
// set email address
2014-10-02 16:05:44 -04:00
if ($scope.useOAuth) {
$scope.emailAddress = auth.emailAddress;
} else {
$scope.emailAddress = $scope.state.login.emailAddress;
2014-10-02 16:05:44 -04:00
}
// SMTP config
$scope.smtpHost = mailConfig.smtp.hostname;
$scope.smtpPort = parseInt(mailConfig.smtp.port, 10);
// transport encryption method
if (mailConfig.smtp.secure && !mailConfig.smtp.ignoreTLS) {
$scope.smtpEncryption = ENCRYPTION_METHOD_TLS;
} else if (!mailConfig.smtp.secure && !mailConfig.smtp.ignoreTLS) {
$scope.smtpEncryption = ENCRYPTION_METHOD_STARTTLS;
} else {
$scope.smtpEncryption = ENCRYPTION_METHOD_NONE;
2014-10-02 16:05:44 -04:00
}
// IMAP config
$scope.imapHost = mailConfig.imap.hostname;
$scope.imapPort = parseInt(mailConfig.imap.port, 10);
// transport encryption method
if (mailConfig.imap.secure && !mailConfig.imap.ignoreTLS) {
$scope.imapEncryption = ENCRYPTION_METHOD_TLS;
} else if (!mailConfig.imap.secure && !mailConfig.imap.ignoreTLS) {
$scope.imapEncryption = ENCRYPTION_METHOD_STARTTLS;
} else {
$scope.imapEncryption = ENCRYPTION_METHOD_NONE;
}
//
// Scope functions
//
2014-10-02 16:05:44 -04:00
$scope.test = function() {
// parse the <select> dropdown lists
var imapEncryption = parseInt($scope.imapEncryption, 10);
var smtpEncryption = parseInt($scope.smtpEncryption, 10);
// build credentials object
var credentials = {
emailAddress: $scope.emailAddress,
username: $scope.username || $scope.emailAddress,
realname: $scope.realname,
password: $scope.password,
xoauth2: auth.oauthToken,
imap: {
host: $scope.imapHost.toLowerCase(),
port: $scope.imapPort,
secure: imapEncryption === ENCRYPTION_METHOD_TLS,
ignoreTLS: imapEncryption === ENCRYPTION_METHOD_NONE
2014-10-02 16:05:44 -04:00
},
smtp: {
host: $scope.smtpHost.toLowerCase(),
port: $scope.smtpPort,
secure: smtpEncryption === ENCRYPTION_METHOD_TLS,
ignoreTLS: smtpEncryption === ENCRYPTION_METHOD_NONE
}
2014-10-02 16:05:44 -04:00
};
2014-10-02 16:05:44 -04:00
// use the credentials in the connection doctor
connectionDoctor.configure(credentials);
2014-10-02 16:05:44 -04:00
// run connection doctor test suite
$scope.busy = true;
connectionDoctor.check(function(err) {
2014-10-02 16:05:44 -04:00
if (err) {
// display the error in the settings UI
$scope.connectionError = err;
} else {
2014-10-02 16:05:44 -04:00
// persists the credentials and forwards to /login
auth.setCredentials(credentials);
$location.path('/login');
}
2014-10-02 16:05:44 -04:00
$scope.busy = false;
$scope.$apply();
});
};
2014-10-02 16:05:44 -04:00
};
2014-10-08 06:34:34 -04:00
module.exports = SetCredentialsCtrl;