From 181ee74ba3ddea9f8672549e01f2b05558e7f181 Mon Sep 17 00:00:00 2001
From: Kyle Spearrin
Date: Sat, 24 Jun 2017 09:19:04 -0400
Subject: [PATCH] email 2fa login
---
src/app/accounts/accountsLoginController.js | 30 ++++++++++++++++---
.../views/accountsLoginTwoFactor.html | 8 ++++-
src/app/services/apiService.js | 1 +
3 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/src/app/accounts/accountsLoginController.js b/src/app/accounts/accountsLoginController.js
index d99c2ee6ff..7402be22c3 100644
--- a/src/app/accounts/accountsLoginController.js
+++ b/src/app/accounts/accountsLoginController.js
@@ -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) {
diff --git a/src/app/accounts/views/accountsLoginTwoFactor.html b/src/app/accounts/views/accountsLoginTwoFactor.html
index 8d46526ac8..eceac49f23 100644
--- a/src/app/accounts/views/accountsLoginTwoFactor.html
+++ b/src/app/accounts/views/accountsLoginTwoFactor.html
@@ -4,7 +4,7 @@
Enter the 6 digit verification code from your authenticator app.
- Enter the 6 digit verification code that was emailed to you.
+ Enter the 6 digit verification code that was just now emailed to you.