various bug fixes #92 #84

This commit is contained in:
Kyle Spearrin 2017-02-23 19:31:29 -05:00
parent 9a662a111d
commit df3893722c
4 changed files with 33 additions and 42 deletions

View File

@ -11,7 +11,24 @@
$urlRouterProvider.otherwise(function ($injector, $location) {
var $state = $injector.get('$state');
$state.go('home');
var userService = $injector.get('userService');
var cryptoService = $injector.get('cryptoService');
cryptoService.getKey(false, function (key) {
userService.isAuthenticated(function (isAuthenticated) {
if (isAuthenticated) {
if (!key) {
$state.go('lock');
}
else {
$state.go('tabs.current');
}
}
else {
$state.go('home');
}
});
});
});
$stateProvider
@ -190,39 +207,22 @@
params: { animation: null }
});
})
.run(function ($rootScope, userService, cryptoService, tokenService, $state, constantsService, stateService) {
.run(function ($rootScope, userService, $state, constantsService, stateService) {
$rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
if ($state.current.name.indexOf('tabs.') > -1 && toState.name.indexOf('tabs.') > -1) {
stateService.purgeState();
}
cryptoService.getKey(false, function (key) {
userService.isAuthenticated(function (isAuthenticated) {
if (isAuthenticated) {
var obj = {};
obj[constantsService.lastActiveKey] = (new Date()).getTime();
chrome.storage.local.set(obj, function () { });
}
if (!toState.data || !toState.data.authorize) {
if (isAuthenticated && !tokenService.isTokenExpired()) {
event.preventDefault();
if (!key) {
$state.go('lock');
}
else {
$state.go('tabs.current');
}
}
return;
}
if (!isAuthenticated || tokenService.isTokenExpired()) {
event.preventDefault();
chrome.runtime.sendMessage({ command: 'logout' });
}
});
userService.isAuthenticated(function (isAuthenticated) {
if (isAuthenticated) {
var obj = {};
obj[constantsService.lastActiveKey] = (new Date()).getTime();
chrome.storage.local.set(obj, function () { });
}
else if (toState.data && toState.data.authorize) {
event.preventDefault();
chrome.runtime.sendMessage({ command: 'logout' });
}
});
});
});

View File

@ -14,6 +14,8 @@
else {
$scope.lockOption = '';
}
$scope.$apply();
});
$scope.changeLockOption = function () {

View File

@ -28,7 +28,7 @@
</div>
<div class="list-section-item" ng-if="login.username">
<a class="btn-list" href="" title="{{i18n.copyUsername}}" ngclipboard ngclipboard-error="clipboardError(e)"
ngclipboard-success="clipboardSuccess(e, i18n.username)" data-clipboard-target="#username">
ngclipboard-success="clipboardSuccess(e, i18n.username)" data-clipboard-text="{{login.username}}">
<i class="fa fa-lg fa-clipboard"></i>
</a>
<span class="item-label">{{i18n.username}}</span>
@ -36,7 +36,7 @@
</div>
<div class="list-section-item" ng-if="login.password">
<a class="btn-list" href="" title="{{i18n.copyPassword}}" ngclipboard ngclipboard-error="clipboardError(e)"
ngclipboard-success="clipboardSuccess(e, i18n.password)" data-clipboard-target="#password">
ngclipboard-success="clipboardSuccess(e, i18n.password)" data-clipboard-text="{{login.password}}">
<i class="fa fa-lg fa-clipboard"></i>
</a>
<a class="btn-list" href="" title="{{i18n.togglePassword}}" ng-click="togglePassword()">

View File

@ -167,17 +167,6 @@ function initTokenService() {
return d;
};
TokenService.prototype.isTokenExpired = function (offsetSeconds) {
var d = this.getTokenExpirationDate();
offsetSeconds = offsetSeconds || 0;
if (d === null) {
return false;
}
// Token expired?
return !(d.valueOf() > (new Date().valueOf() + (offsetSeconds * 1000)));
};
TokenService.prototype.tokenSecondsRemaining = function (offsetSeconds) {
var d = this.getTokenExpirationDate();
offsetSeconds = offsetSeconds || 0;