parent
9a662a111d
commit
df3893722c
|
@ -11,7 +11,24 @@
|
||||||
|
|
||||||
$urlRouterProvider.otherwise(function ($injector, $location) {
|
$urlRouterProvider.otherwise(function ($injector, $location) {
|
||||||
var $state = $injector.get('$state');
|
var $state = $injector.get('$state');
|
||||||
|
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');
|
$state.go('home');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$stateProvider
|
$stateProvider
|
||||||
|
@ -190,39 +207,22 @@
|
||||||
params: { animation: null }
|
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) {
|
$rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
|
||||||
if ($state.current.name.indexOf('tabs.') > -1 && toState.name.indexOf('tabs.') > -1) {
|
if ($state.current.name.indexOf('tabs.') > -1 && toState.name.indexOf('tabs.') > -1) {
|
||||||
stateService.purgeState();
|
stateService.purgeState();
|
||||||
}
|
}
|
||||||
|
|
||||||
cryptoService.getKey(false, function (key) {
|
|
||||||
userService.isAuthenticated(function (isAuthenticated) {
|
userService.isAuthenticated(function (isAuthenticated) {
|
||||||
if (isAuthenticated) {
|
if (isAuthenticated) {
|
||||||
var obj = {};
|
var obj = {};
|
||||||
obj[constantsService.lastActiveKey] = (new Date()).getTime();
|
obj[constantsService.lastActiveKey] = (new Date()).getTime();
|
||||||
chrome.storage.local.set(obj, function () { });
|
chrome.storage.local.set(obj, function () { });
|
||||||
}
|
}
|
||||||
|
else if (toState.data && toState.data.authorize) {
|
||||||
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();
|
event.preventDefault();
|
||||||
chrome.runtime.sendMessage({ command: 'logout' });
|
chrome.runtime.sendMessage({ command: 'logout' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
else {
|
else {
|
||||||
$scope.lockOption = '';
|
$scope.lockOption = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$scope.$apply();
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.changeLockOption = function () {
|
$scope.changeLockOption = function () {
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="list-section-item" ng-if="login.username">
|
<div class="list-section-item" ng-if="login.username">
|
||||||
<a class="btn-list" href="" title="{{i18n.copyUsername}}" ngclipboard ngclipboard-error="clipboardError(e)"
|
<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>
|
<i class="fa fa-lg fa-clipboard"></i>
|
||||||
</a>
|
</a>
|
||||||
<span class="item-label">{{i18n.username}}</span>
|
<span class="item-label">{{i18n.username}}</span>
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="list-section-item" ng-if="login.password">
|
<div class="list-section-item" ng-if="login.password">
|
||||||
<a class="btn-list" href="" title="{{i18n.copyPassword}}" ngclipboard ngclipboard-error="clipboardError(e)"
|
<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>
|
<i class="fa fa-lg fa-clipboard"></i>
|
||||||
</a>
|
</a>
|
||||||
<a class="btn-list" href="" title="{{i18n.togglePassword}}" ng-click="togglePassword()">
|
<a class="btn-list" href="" title="{{i18n.togglePassword}}" ng-click="togglePassword()">
|
||||||
|
|
|
@ -167,17 +167,6 @@ function initTokenService() {
|
||||||
return d;
|
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) {
|
TokenService.prototype.tokenSecondsRemaining = function (offsetSeconds) {
|
||||||
var d = this.getTokenExpirationDate();
|
var d = this.getTokenExpirationDate();
|
||||||
offsetSeconds = offsetSeconds || 0;
|
offsetSeconds = offsetSeconds || 0;
|
||||||
|
|
Loading…
Reference in New Issue