From 71b84afdb2024ce77ab2f3893f6e520110e04eb0 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 14 Feb 2017 11:29:08 +0100 Subject: [PATCH] Redirect to the pad when logging in or signing up from a pad --- www/common/toolbar.js | 2 ++ www/login/main.js | 12 +++++++++++- www/register/main.js | 12 +++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/www/common/toolbar.js b/www/common/toolbar.js index a9a2435ae..6784661d6 100644 --- a/www/common/toolbar.js +++ b/www/common/toolbar.js @@ -465,9 +465,11 @@ define([ window.location.href = '/'; }); $userAdmin.find('a.login').click(function (e) { + sessionStorage.redirectTo = window.location.href; window.location.href = '/login/'; }); $userAdmin.find('a.register').click(function (e) { + sessionStorage.redirectTo = window.location.href; window.location.href = '/register/'; }); diff --git a/www/login/main.js b/www/login/main.js index a6273b469..2a67748d6 100644 --- a/www/login/main.js +++ b/www/login/main.js @@ -78,7 +78,17 @@ define([ result.proxy.login_name = result.userName; } Cryptpad.login(result.userHash, result.userName, function () { - document.location.href = '/drive/'; + if (sessionStorage.redirectTo) { + var h = sessionStorage.redirectTo; + var parser = document.createElement('a'); + parser.href = h; + if (parser.origin === window.location.origin) { + delete sessionStorage.redirectTo; + window.location.href = h; + return; + } + } + window.location.href = '/drive/'; }); return; } diff --git a/www/register/main.js b/www/register/main.js index 901ced2ff..b6277d13f 100644 --- a/www/register/main.js +++ b/www/register/main.js @@ -120,7 +120,17 @@ define([ Cryptpad.whenRealtimeSyncs(result.realtime, function () { Cryptpad.login(result.userHash, result.userName, function () { - document.location.href = '/drive/'; + if (sessionStorage.redirectTo) { + var h = sessionStorage.redirectTo; + var parser = document.createElement('a'); + parser.href = h; + if (parser.origin === window.location.origin) { + delete sessionStorage.redirectTo; + window.location.href = h; + return; + } + } + window.location.href = '/drive/'; }); }); });