two step login page

This commit is contained in:
Kyle Spearrin 2016-09-21 11:35:24 -04:00
parent 32d459159c
commit 8a3a981ac1
7 changed files with 64 additions and 30 deletions

View File

@ -22,16 +22,12 @@
$scope.loginPromise.then(function () {
userService.isTwoFactorAuthenticated(function (isTwoFactorAuthenticated) {
if (isTwoFactorAuthenticated) {
$state.go('login.twoFactor');
$state.go('twoFactor', { animation: 'in-slide-left' });
}
else {
$state.go('tabs.current', { animation: 'in-slide-left' });
$state.go('tabs.vault', { animation: 'in-slide-left' });
}
});
});
};
$scope.twoFactor = function (model) {
$state.go('tabs.current');
};
});

View File

@ -0,0 +1,15 @@
angular
.module('bit.accounts')
.controller('accountsLoginTwoFactorController', function ($scope, $state, loginService) {
popupUtils.initListSectionItemListeners();
$('#code').focus();
$scope.loginPromise = null;
$scope.login = function (model) {
$scope.loginPromise = loginService.logInTwoFactor(model.code);
$scope.loginPromise.then(function () {
$state.go('tabs.vault', { animation: 'in-slide-left' });
});
};
});

View File

@ -1,7 +1,28 @@
<ion-view view-title="bitwarden">
<ion-content class="padding">
<p>
Some content for your login.
</p>
</ion-content>
</ion-view>
<form name="theForm" ng-submit="theForm.$valid && login(model)" bit-form="loginPromise">
<div class="header">
<div class="left">
<a ui-sref="login({animation: 'out-slide-right'})"><i class="fa fa-chevron-left"></i> Log In</a>
</div>
<div class="right">
<button type="submit" class="btn btn-link" ng-show="!theForm.$loading">Continue</button>
<i class="fa fa-spinner fa-lg" ng-show="theForm.$loading" ng-class="{'fa-spin' : theForm.$loading}"></i>
</div>
<div class="title">Verification Code</div>
</div>
<div class="content">
<div class="list">
<div class="list-section">
<div class="list-section-items">
<div class="list-section-item list-section-item-icon-input">
<i class="fa fa-lock fa-lg fa-fw"></i>
<label for="code" class="sr-only">Verification Code</label>
<input id="code" type="number" name="Code" placeholder="Verification Code" ng-model="model.code">
</div>
</div>
<div class="list-section-footer">
Enter your two-step verification code.
</div>
</div>
</div>
</div>
</form>

View File

@ -64,7 +64,7 @@
})
.state('twoFactor', {
url: '/two-factor',
controller: 'accountsLoginController',
controller: 'accountsLoginTwoFactorController',
templateUrl: 'app/accounts/views/accountsLoginTwoFactor.html',
data: { authorize: false },
params: { animation: null }

View File

@ -21,9 +21,7 @@
if (response.profile) {
userService.setUserId(response.profile.id, function () {
userService.setEmail(response.profile.email, function () {
syncService.fullSync(function () {
$rootScope.$broadcast('syncCompleted');
});
syncService.fullSync(function () { });
deferred.resolve(response);
});
});
@ -44,7 +42,7 @@
var request = new TokenTwoFactorRequest(code);
var deferred = $q.defer();
apiService.auth.postTokenTwoFactor(request, function (response) {
apiService.postTokenTwoFactor(request, function (response) {
if (!response || !response.token) {
deferred.reject();
return;
@ -53,6 +51,7 @@
tokenService.setToken(response.token, function () {
userService.setUserId(response.profile.id, function () {
userService.setEmail(response.profile.email, function () {
syncService.fullSync(function () { });
deferred.resolve(response);
});
});

View File

@ -52,6 +52,7 @@
<script src="app/accounts/accountsModule.js"></script>
<script src="app/accounts/accountsLoginController.js"></script>
<script src="app/accounts/accountsLoginTwoFactorController.js"></script>
<script src="app/accounts/accountsHintController.js"></script>
<script src="app/accounts/accountsRegisterController.js"></script>

View File

@ -27,18 +27,20 @@ function initApiService() {
ApiService.prototype.postTokenTwoFactor = function (twoFactorTokenRequest, success, error) {
var self = this;
$.ajax({
type: 'POST',
url: self.baseUrl + '/auth/token/two-factor',
data: JSON.stringify(twoFactorTokenRequest),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (response) {
success(new TokenResponse(response))
},
error: function (jqXHR, textStatus, errorThrown) {
handleError(error, jqXHR, textStatus, errorThrown);
}
this.tokenService.getToken(function (token) {
$.ajax({
type: 'POST',
url: self.baseUrl + '/auth/token/two-factor?access_token=' + token,
data: JSON.stringify(twoFactorTokenRequest),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (response) {
success(new TokenResponse(response))
},
error: function (jqXHR, textStatus, errorThrown) {
handleError(error, jqXHR, textStatus, errorThrown);
}
});
});
};