Browse Source

fix(login): fixed so that you get redirect back to the page or dashboard you where on when you clicked on sign in link, fixes #3312

Torkel Ödegaard 9 years ago
parent
commit
d74eb8c188

+ 1 - 1
public/app/core/components/sidemenu/sidemenu.html

@@ -45,7 +45,7 @@
 	</li>
 
 	<li ng-show="::!ctrl.isSignedIn">
-		<a href="login" class="sidemenu-item" target="_self">
+    <a href="{{ctrl.loginUrl}}" class="sidemenu-item">
 			<span class="icon-circle sidemenu-icon"><i class="fa fa-fw fa-sign-in"></i></span>
 			<span class="sidemenu-item-text">Sign in</span>
 		</a>

+ 3 - 1
public/app/core/components/sidemenu/sidemenu.ts

@@ -12,6 +12,7 @@ export class SideMenuCtrl {
   mainLinks: any;
   orgMenu: any;
   appSubUrl: string;
+  loginUrl: string;
 
   /** @ngInject */
   constructor(private $scope, private $location, private contextSrv, private backendSrv, private $element) {
@@ -22,13 +23,14 @@ export class SideMenuCtrl {
 
     this.mainLinks = config.bootData.mainNavLinks;
     this.openUserDropdown();
+    this.loginUrl = '/login?redirect=' + encodeURIComponent(this.$location.path());
 
     this.$scope.$on('$routeChangeSuccess', () => {
       if (!this.contextSrv.pinned) {
         this.contextSrv.sidemenu = false;
       }
+      this.loginUrl = '/login?redirect=' + encodeURIComponent(this.$location.path());
     });
-
   }
 
  getUrl(url) {

+ 6 - 1
public/app/core/controllers/login_ctrl.js

@@ -69,7 +69,12 @@ function (angular, coreModule, config) {
       }
 
       backendSrv.post('/login', $scope.formModel).then(function(result) {
-        if (result.redirectUrl) {
+        var params = $location.search();
+
+        if (params.redirect && params.redirect[0] === '/') {
+          window.location.href = config.appSubUrl + params.redirect;
+        }
+        else if (result.redirectUrl) {
           window.location.href = result.redirectUrl;
         } else {
           window.location.href = config.appSubUrl + '/';