Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
vlavrynovych committed Aug 16, 2017
2 parents 68a6e68 + cdabb6f commit 3841426
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 55 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"authors": [
"Volodymyr Lavrynovych <volodyalavrynovych@gmail.com>"
],
"version": "0.7.1",
"version": "1.0.0",
"description": "Provides ability to easily handle most of the logic related to the authentication process and page load for the AngularJS SPA",
"main": "dist/angular-spa-auth.min.js",
"keywords": [
Expand Down
15 changes: 12 additions & 3 deletions dist/angular-spa-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
return $rootScope.currentUser !== undefined;
}
}])
.service('AuthService', ['$rootScope', '$q', '$http', '$location', function ($rootScope, $q, $http, $location) {
.service('AuthService', ['$rootScope', '$q', '$http', '$location', '$route', function ($rootScope, $q, $http, $location, $route) {

// ------------------------------------------------------------------------/// Config
var config = {
Expand Down Expand Up @@ -137,7 +137,7 @@

// ------------------------------------------------------------------------/// Private
function info(message) {
_log(console.info, message)
_log(console.info, 'AuthService: ' + message)
}

function error(err) {
Expand All @@ -151,8 +151,15 @@
}

function goTo(route) {
info(($location.path() || 'unknown') + ' -----> ' + route);
if(route == config.uiRoutes.login && service.isAuthenticated()) {
$location.path(getHome());
info('User is already authenticated and cannot open login page: ' + route);
route = getHome();
$location.path(route);
info('Redirected to the ' + route);
} else if(route == $location.path()) {
info('Reload: ' + route);
$route.reload()
} else {
$location.path(route);
info('Redirected to the ' + route);
Expand All @@ -173,6 +180,7 @@
}

function init() {
info('init');
isAuthenticated()
.then(service.refreshCurrentUser)
.then(function (user) {
Expand Down Expand Up @@ -235,6 +243,7 @@
*/
openTarget: function () {
var target = config.uiRoutes.target || getHome();
info('Open target: ' + target);
goTo(target);
service.clearTarget()
},
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-spa-auth.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/angular-spa-auth.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-spa-auth",
"title": "Angular SPA Auth",
"version": "0.7.1",
"version": "1.0.0",
"author": "Volodymyr Lavrynovych <volodyalavrynovych@gmail.com>",
"contributors": [
"Volodymyr Lavrynovych <volodyalavrynovych@gmail.com>"
Expand Down
15 changes: 12 additions & 3 deletions src/angular-spa-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
return $rootScope.currentUser !== undefined;
}
}])
.service('AuthService', ['$rootScope', '$q', '$http', '$location', function ($rootScope, $q, $http, $location) {
.service('AuthService', ['$rootScope', '$q', '$http', '$location', '$route', function ($rootScope, $q, $http, $location, $route) {

// ------------------------------------------------------------------------/// Config
var config = {
Expand Down Expand Up @@ -137,7 +137,7 @@

// ------------------------------------------------------------------------/// Private
function info(message) {
_log(console.info, message)
_log(console.info, 'AuthService: ' + message)
}

function error(err) {
Expand All @@ -151,8 +151,15 @@
}

function goTo(route) {
info(($location.path() || 'unknown') + ' -----> ' + route);
if(route == config.uiRoutes.login && service.isAuthenticated()) {
$location.path(getHome());
info('User is already authenticated and cannot open login page: ' + route);
route = getHome();
$location.path(route);
info('Redirected to the ' + route);
} else if(route == $location.path()) {
info('Reload: ' + route);
$route.reload()
} else {
$location.path(route);
info('Redirected to the ' + route);
Expand All @@ -173,6 +180,7 @@
}

function init() {
info('init');
isAuthenticated()
.then(service.refreshCurrentUser)
.then(function (user) {
Expand Down Expand Up @@ -235,6 +243,7 @@
*/
openTarget: function () {
var target = config.uiRoutes.target || getHome();
info('Open target: ' + target);
goTo(target);
service.clearTarget()
},
Expand Down
Loading

0 comments on commit 3841426

Please sign in to comment.