1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-10 06:08:34 +02:00
bitwarden-browser/src/app/vault/vaultAddLoginController.js

73 lines
2.5 KiB
JavaScript
Raw Normal View History

2015-12-09 04:35:05 +01:00
angular
.module('bit.vault')
2017-03-25 21:09:06 +01:00
.controller('vaultAddLoginController', function ($scope, apiService, $uibModalInstance, cryptoService, cipherService,
2017-07-07 15:11:45 +02:00
passwordService, selectedFolder, $analytics, checkedFavorite, $rootScope, authService, $uibModal) {
2017-01-03 04:26:32 +01:00
$analytics.eventTrack('vaultAddLoginController', { category: 'Modal' });
2017-04-14 18:35:46 +02:00
$scope.folders = $rootScope.vaultFolders;
2017-01-03 04:26:32 +01:00
$scope.login = {
2017-03-25 21:09:06 +01:00
folderId: selectedFolder ? selectedFolder.id : null,
favorite: checkedFavorite === true
2015-12-09 04:35:05 +01:00
};
2017-07-07 06:13:26 +02:00
authService.getUserProfile().then(function (profile) {
2017-07-07 18:12:08 +02:00
$scope.useTotp = profile.premium;
2017-07-07 06:13:26 +02:00
});
2015-12-09 04:35:05 +01:00
$scope.savePromise = null;
$scope.save = function (model) {
2017-01-03 04:26:32 +01:00
var login = cipherService.encryptLogin(model);
$scope.savePromise = apiService.logins.post(login, function (loginResponse) {
$analytics.eventTrack('Created Login');
var decLogin = cipherService.decryptLogin(loginResponse);
$uibModalInstance.close(decLogin);
2015-12-09 04:35:05 +01:00
}).$promise;
};
$scope.generatePassword = function () {
2017-01-03 04:26:32 +01:00
if (!$scope.login.password || confirm('Are you sure you want to overwrite the current password?')) {
$analytics.eventTrack('Generated Password From Add');
$scope.login.password = passwordService.generatePassword({ length: 12, special: true });
2015-12-09 04:35:05 +01:00
}
};
$scope.clipboardSuccess = function (e) {
e.clearSelection();
selectPassword(e);
};
$scope.clipboardError = function (e, password) {
if (password) {
selectPassword(e);
}
alert('Your web browser does not support easy clipboard copying. Copy it manually instead.');
};
$scope.folderSort = function (item) {
if (!item.id) {
return '';
}
return item.name.toLowerCase();
};
2015-12-09 04:35:05 +01:00
function selectPassword(e) {
var target = $(e.trigger).parent().prev();
if (target.attr('type') === 'text') {
2015-12-09 04:35:05 +01:00
target.select();
}
}
$scope.close = function () {
$uibModalInstance.dismiss('close');
};
2017-07-07 15:11:45 +02:00
2017-07-07 18:12:08 +02:00
$scope.showUpgrade = function () {
2017-07-07 15:11:45 +02:00
$uibModal.open({
animation: true,
templateUrl: 'app/views/premiumRequired.html',
controller: 'premiumRequiredController'
});
};
2015-12-09 04:35:05 +01:00
});