bitwarden-estensione-browser/src/popup-old/app/accounts/accountsLoginController.js

59 lines
2.1 KiB
JavaScript
Raw Normal View History

angular
2016-09-03 06:03:13 +02:00
.module('bit.accounts')
2017-01-04 00:40:07 +01:00
.controller('accountsLoginController', function ($scope, $state, $stateParams, authService, userService, toastr,
popupUtilsService, $analytics, i18nService, $timeout) {
$timeout(function () {
popupUtilsService.initListSectionItemListeners(document, angular);
if ($stateParams.email) {
document.getElementById('master-password').focus();
}
else {
document.getElementById('email').focus();
}
}, 500);
2016-09-21 01:57:24 +02:00
$scope.i18n = i18nService;
2016-09-21 01:57:24 +02:00
$scope.model = {
email: $stateParams.email
};
$scope.loginPromise = null;
2016-09-20 23:47:21 +02:00
$scope.login = function (model) {
2016-09-22 18:50:27 +02:00
if (!model.email) {
2016-11-19 07:36:09 +01:00
toastr.error(i18nService.emailRequired, i18nService.errorsOccurred);
2016-09-22 19:03:28 +02:00
return;
}
if (model.email.indexOf('@') === -1) {
2016-11-19 07:36:09 +01:00
toastr.error(i18nService.invalidEmail, i18nService.errorsOccurred);
2016-09-22 18:50:27 +02:00
return;
}
if (!model.masterPassword) {
2016-11-19 07:36:09 +01:00
toastr.error(i18nService.masterPassRequired, i18nService.errorsOccurred);
2016-09-22 18:50:27 +02:00
return;
}
2018-02-02 04:53:36 +01:00
$scope.loginPromise = authService.logIn(model.email, model.masterPassword);
2016-09-03 06:03:13 +02:00
$scope.loginPromise.then(function (response) {
if (response.twoFactor) {
$analytics.eventTrack('Logged In To Two-step');
$state.go('twoFactor', {
animation: 'in-slide-left',
email: model.email,
masterPassword: model.masterPassword,
2017-06-26 22:36:56 +02:00
providers: response.twoFactorProviders,
provider: null
});
}
else {
$analytics.eventTrack('Logged In');
$state.go('tabs.vault', {
animation: 'in-slide-left',
syncOnLoad: true
});
}
2016-09-03 06:03:13 +02:00
});
};
});