'use strict'; var ENCRYPTION_METHOD_NONE = 0; var ENCRYPTION_METHOD_STARTTLS = 1; var ENCRYPTION_METHOD_TLS = 2; var appCtrl = require('../app-controller'), config = require('../app-config').config; var SetCredentialsCtrl = function($scope, $location, $routeParams) { if (!appCtrl._auth && !$routeParams.dev) { $location.path('/'); // init app return; } var auth = appCtrl._auth; var doctor = appCtrl._doctor; // // Presets and Settings // var provider = $location.search().provider; $scope.hasProviderPreset = !!config[provider]; $scope.useOAuth = !!auth.oauthToken; $scope.showDetails = (provider === 'custom'); if ($scope.useOAuth) { $scope.emailAddress = auth.emailAddress; } else if ($scope.state.emailAddress) { $scope.emailAddress = $scope.state.emailAddress; } if ($scope.hasProviderPreset) { // use non-editable presets // 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; // transport encryption method if (config[provider].smtp.secure && !config[provider].smtp.ignoreTLS) { $scope.smtpEncryption = ENCRYPTION_METHOD_TLS; } else if (!config[provider].smtp.secure && !config[provider].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; // transport encryption method if (config[provider].imap.secure && !config[provider].imap.ignoreTLS) { $scope.imapEncryption = ENCRYPTION_METHOD_TLS; } else if (!config[provider].imap.secure && !config[provider].imap.ignoreTLS) { $scope.imapEncryption = ENCRYPTION_METHOD_STARTTLS; } else { $scope.imapEncryption = ENCRYPTION_METHOD_NONE; } } $scope.test = function() { // parse the