Skip to content

Commit

Permalink
After automatic redirect to login page, when user successfuly logs in…
Browse files Browse the repository at this point in the history
…, user is redirected to original page.
  • Loading branch information
pbuda committed Jan 30, 2013
1 parent d5af57f commit d9abf10
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions bootstrap-ui/src/main/webapp/app/application.js
@@ -1,6 +1,6 @@
"use strict";

angular.module('smlBootstrap', ['smlBootstrap.services', 'smlBootstrap.filters', 'smlBootstrap.controllers', 'smlBootstrap.directives', 'ngSanitize', 'ajaxthrobber'])
angular.module('smlBootstrap', ['smlBootstrap.services', 'smlBootstrap.filters', 'smlBootstrap.controllers', 'smlBootstrap.directives', 'ngSanitize', 'ajaxthrobber', 'ngCookies'])

.config(function ($routeProvider) {

Expand Down Expand Up @@ -70,7 +70,7 @@ angular.module('smlBootstrap', ['smlBootstrap.services', 'smlBootstrap.filters',
.run(function ($rootScope, UserSessionService, $location) {
$rootScope.$on("$routeChangeStart", function (event, next, current) {
if (!UserSessionService.isLogged() && (typeof next.templateUrl !== "undefined") && next.templateUrl.indexOf("/secured/") > -1) {
$location.path("/login");
$location.search("page", $location.url()).path("/login");

This comment has been minimized.

Copy link
@adamw

adamw Jan 30, 2013

Member

So "search" stores the url in a cookie or sth like that? Or in memory?

This comment has been minimized.

Copy link
@pbuda

pbuda Jan 30, 2013

Author Contributor

Yes, it appends query parameter to url. I.e. /login?page=/profile. Later in LoginController when user succesfuly logs in this parameter is used to redirect back to original page.

This comment has been minimized.

Copy link
@adamw

adamw Jan 30, 2013

Member

Ah, ok :)

} else if (UserSessionService.isLogged() && next.templateUrl === "partials/login.html") {
$location.path("/");
}
Expand Down
10 changes: 8 additions & 2 deletions bootstrap-ui/src/main/webapp/app/controllers.js
Expand Up @@ -181,7 +181,7 @@ controllers.controller('RegisterController', function RegisterController($scope,

});

controllers.controller('LoginController', function LoginController($scope, UserSessionService, $location) {
controllers.controller('LoginController', function LoginController($scope, UserSessionService, $location, $routeParams) {

var self = this;

Expand All @@ -202,7 +202,13 @@ controllers.controller('LoginController', function LoginController($scope, UserS


this.loginOk = function () {
$location.path("");
var optionalRedir = $routeParams.page;
if (typeof optionalRedir !== "undefined") {
$location.search("page", null);
$location.path(optionalRedir);
} else {
$location.path("");
}
};

this.loginFailed = function () {
Expand Down

0 comments on commit d9abf10

Please sign in to comment.