1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-20 07:40:57 +02:00
bitwarden-browser/src/popup/app/vault/vaultViewLoginController.js

93 lines
2.9 KiB
JavaScript
Raw Normal View History

2016-09-22 20:16:24 +02:00
angular
2016-09-06 05:43:56 +02:00
.module('bit.vault')
.controller('vaultViewLoginController', function ($scope, $state, $stateParams, loginService, toastr, $q,
$analytics, i18nService, utilsService) {
2016-10-18 14:10:40 +02:00
$scope.i18n = i18nService;
2016-12-07 06:07:01 +01:00
var from = $stateParams.from;
2017-01-04 00:40:07 +01:00
$scope.login = null;
loginService.get($stateParams.loginId, function (login) {
if (!login) {
2016-09-22 20:16:24 +02:00
return;
}
2017-01-04 00:40:07 +01:00
$q.when(login.decrypt()).then(function (model) {
$scope.login = model;
2016-09-11 05:50:51 +02:00
if (model.password) {
var maskedPassword = '';
for (var i = 0; i < model.password.length; i++) {
maskedPassword += '•';
}
2017-01-04 00:40:07 +01:00
$scope.login.maskedPassword = maskedPassword;
2016-09-11 05:50:51 +02:00
}
if (model.uri) {
2017-01-04 00:40:07 +01:00
$scope.login.showLaunch = model.uri.startsWith('http://') || model.uri.startsWith('https://');
var domain = utilsService.getDomain(model.uri);
if (domain) {
2017-01-04 00:40:07 +01:00
$scope.login.website = domain;
}
else {
2017-01-04 00:40:07 +01:00
$scope.login.website = model.uri;
}
}
else {
2017-01-04 00:40:07 +01:00
$scope.login.showLaunch = false;
}
});
});
2017-01-04 00:40:07 +01:00
$scope.edit = function (login) {
$state.go('editLogin', {
2016-09-13 06:14:49 +02:00
animation: 'in-slide-up',
2017-01-04 00:40:07 +01:00
loginId: login.id,
2016-09-13 06:14:49 +02:00
fromView: true,
2016-12-07 06:07:01 +01:00
from: from
2016-09-13 06:14:49 +02:00
});
};
2016-09-13 06:14:49 +02:00
$scope.close = function () {
2016-12-07 06:07:01 +01:00
if (from === 'current') {
$state.go('tabs.current', {
animation: 'out-slide-down'
});
}
2016-12-07 06:07:01 +01:00
else if (from === 'folder') {
$state.go('viewFolder', {
2016-12-08 06:56:38 +01:00
animation: 'out-slide-down'
2016-12-07 06:07:01 +01:00
});
}
else {
$state.go('tabs.vault', {
2016-12-08 06:56:38 +01:00
animation: 'out-slide-down'
});
}
};
2017-01-04 00:40:07 +01:00
$scope.launchWebsite = function (login) {
if (login.showLaunch) {
2016-09-28 05:19:33 +02:00
$analytics.eventTrack('Launched Website');
2017-01-04 00:40:07 +01:00
chrome.tabs.create({ url: login.uri });
}
};
$scope.clipboardError = function (e, password) {
2016-10-18 14:10:40 +02:00
toastr.info(i18n.browserNotSupportClipboard);
};
$scope.clipboardSuccess = function (e, type) {
e.clearSelection();
2016-11-19 07:36:09 +01:00
$analytics.eventTrack('Copied ' + (type === i18nService.username ? 'Username' : 'Password'));
toastr.info(type + i18nService.valueCopied);
};
$scope.showPassword = false;
$scope.togglePassword = function () {
2016-09-28 05:19:33 +02:00
$analytics.eventTrack('Toggled Password');
$scope.showPassword = !$scope.showPassword;
};
2016-09-06 05:43:56 +02:00
});