1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-02 08:30:14 +01:00

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 () { $scope.loginPromise.then(function () {
userService.isTwoFactorAuthenticated(function (isTwoFactorAuthenticated) { userService.isTwoFactorAuthenticated(function (isTwoFactorAuthenticated) {
if (isTwoFactorAuthenticated) { if (isTwoFactorAuthenticated) {
$state.go('login.twoFactor'); $state.go('twoFactor', { animation: 'in-slide-left' });
} }
else { 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"> <form name="theForm" ng-submit="theForm.$valid && login(model)" bit-form="loginPromise">
<ion-content class="padding"> <div class="header">
<p> <div class="left">
Some content for your login. <a ui-sref="login({animation: 'out-slide-right'})"><i class="fa fa-chevron-left"></i> Log In</a>
</p> </div>
</ion-content> <div class="right">
</ion-view> <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', { .state('twoFactor', {
url: '/two-factor', url: '/two-factor',
controller: 'accountsLoginController', controller: 'accountsLoginTwoFactorController',
templateUrl: 'app/accounts/views/accountsLoginTwoFactor.html', templateUrl: 'app/accounts/views/accountsLoginTwoFactor.html',
data: { authorize: false }, data: { authorize: false },
params: { animation: null } params: { animation: null }

View File

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

View File

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

View File

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