email 2fa login

This commit is contained in:
Kyle Spearrin 2017-06-24 09:19:04 -04:00
parent b8e9567501
commit 181ee74ba3
3 changed files with 34 additions and 5 deletions

View File

@ -2,7 +2,7 @@ angular
.module('bit.accounts')
.controller('accountsLoginController', function ($scope, $rootScope, $cookies, apiService, cryptoService, authService,
$state, constants, $analytics, $uibModal, $timeout, $window, $filter) {
$state, constants, $analytics, $uibModal, $timeout, $window, $filter, toastr) {
$scope.state = $state;
$scope.twoFactorProviderConstants = constants.twoFactorProvider;
$scope.rememberTwoFactor = { checked: false };
@ -33,9 +33,7 @@ angular
$scope.twoFactorProvider = null;
$scope.login = function (model) {
$scope.loginPromise = authService.logIn(model.email, model.masterPassword);
$scope.loginPromise.then(function (twoFactorProviders) {
$scope.loginPromise = authService.logIn(model.email, model.masterPassword).then(function (twoFactorProviders) {
if (model.rememberEmail) {
var cookieExpiration = new Date();
cookieExpiration.setFullYear(cookieExpiration.getFullYear() + 10);
@ -114,6 +112,25 @@ angular
});
};
$scope.sendEmail = function (doToast) {
if ($scope.twoFactorProvider !== constants.twoFactorProvider.email) {
return;
}
var key = cryptoService.makeKey(_masterPassword, _email);
var hash = cryptoService.hashPassword(_masterPassword, key);
apiService.twoFactor.sendEmailLogin({
email: _email,
masterPasswordHash: hash
}, function () {
if (doToast) {
toastr.success('Verification email sent.');
}
}, function () {
toastr.error('Could not send verification email.');
});
};
function loggedInGo() {
if (returnState) {
$state.go(returnState.name, returnState.params);
@ -142,6 +159,11 @@ angular
initU2f(challenges);
}
else if ($scope.twoFactorProvider === constants.twoFactorProvider.email) {
if (Object.keys($scope.twoFactorProviders).length > 1) {
$scope.sendEmail(false);
}
}
}
function initU2f(challenges) {

View File

@ -4,7 +4,7 @@
Enter the 6 digit verification code from your authenticator app.
</p>
<p class="login-box-msg" ng-if="twoFactorProvider === twoFactorProviderConstants.email">
Enter the 6 digit verification code that was emailed to you.
Enter the 6 digit verification code that was just now emailed to you.
</p>
<form name="twoFactorForm" ng-submit="twoFactorForm.$valid && twoFactor(token)" api-form="twoFactorPromise">
<div class="callout callout-danger validation-errors" ng-show="twoFactorForm.$errors">
@ -19,6 +19,12 @@
ng-model="token" required api-field />
<span class="fa fa-lock form-control-feedback"></span>
</div>
<p>
Didn't get the email?
<a href="#" stop-click ng-click="sendEmail(true)" ng-if="twoFactorProvider === twoFactorProviderConstants.email">
Send it again
</a>
</p>
<div class="row">
<div class="col-xs-7">
<div class="checkbox">

View File

@ -119,6 +119,7 @@
getAuthenticator: { url: _apiUri + '/two-factor/get-authenticator', method: 'POST', params: {} },
getYubi: { url: _apiUri + '/two-factor/get-yubikey', method: 'POST', params: {} },
sendEmail: { url: _apiUri + '/two-factor/send-email', method: 'POST', params: {} },
sendEmailLogin: { url: _apiUri + '/two-factor/send-email-login', method: 'POST', params: {} },
putEmail: { url: _apiUri + '/two-factor/email', method: 'POST', params: {} },
putU2f: { url: _apiUri + '/two-factor/u2f', method: 'POST', params: {} },
putAuthenticator: { url: _apiUri + '/two-factor/authenticator', method: 'POST', params: {} },