2017-11-09 23:16:28 +01:00
|
|
|
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,
|
2018-01-11 21:21:43 +01:00
|
|
|
popupUtilsService, $analytics, i18nService, $timeout) {
|
2017-11-09 23:16:28 +01:00
|
|
|
$timeout(function () {
|
2018-01-11 21:21:43 +01:00
|
|
|
popupUtilsService.initListSectionItemListeners(document, angular);
|
2017-11-09 23:16:28 +01:00
|
|
|
if ($stateParams.email) {
|
|
|
|
document.getElementById('master-password').focus();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById('email').focus();
|
|
|
|
}
|
|
|
|
}, 500);
|
2016-09-21 01:57:24 +02:00
|
|
|
|
2017-11-09 23:16:28 +01:00
|
|
|
$scope.i18n = i18nService;
|
2016-09-21 01:57:24 +02:00
|
|
|
$scope.model = {
|
|
|
|
email: $stateParams.email
|
|
|
|
};
|
2016-09-20 22:17:31 +02:00
|
|
|
|
|
|
|
$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
|
|
|
|
2017-06-26 15:55:07 +02:00
|
|
|
$scope.loginPromise.then(function (response) {
|
|
|
|
if (response.twoFactor) {
|
2017-01-19 04:14:51 +01:00
|
|
|
$analytics.eventTrack('Logged In To Two-step');
|
|
|
|
$state.go('twoFactor', {
|
|
|
|
animation: 'in-slide-left',
|
|
|
|
email: model.email,
|
2017-06-26 21:37:15 +02:00
|
|
|
masterPassword: model.masterPassword,
|
2017-06-26 22:36:56 +02:00
|
|
|
providers: response.twoFactorProviders,
|
|
|
|
provider: null
|
2017-01-19 04:14:51 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$analytics.eventTrack('Logged In');
|
|
|
|
$state.go('tabs.vault', {
|
|
|
|
animation: 'in-slide-left',
|
|
|
|
syncOnLoad: true
|
|
|
|
});
|
|
|
|
}
|
2016-09-03 06:03:13 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
});
|