Skip to content

Commit

Permalink
Merge pull request #7 from xezpeleta/patch-redirect-index
Browse files Browse the repository at this point in the history
Fix redirection after login
  • Loading branch information
alleen authored Mar 4, 2018
2 parents 4e80215 + b9df869 commit c84b36b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pages/assets/js/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ $(document).ready(function() {
var frm = $('#login-form');
var redirectUri = $("meta[name='redirectUri']").attr('content');
var clientId = $("meta[name='clientId']").attr('content');
$('<a class="btn btn-primary btn-sm bigger-110" href="https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=' + redirectUri + '&client_id=' + clientId + '&scope=https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/userinfo.email&access_type=offline&approval_prompt=force&state=">Sign in with google</a>').appendTo(frm);
// (disabled) Send all the params
//var url = window.location.href
//var state = ( url.match(/\?(.+)$/) || [,''])[1];
// Send just the return param value
var urlParams = new URLSearchParams(window.location.search);
var state = urlParams.get('return') || '';
$('<a id="sign_with_google" class="btn btn-primary btn-sm bigger-110" href="https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=' + redirectUri + '&client_id=' + clientId + '&scope=https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/userinfo.email&access_type=offline&prompt=consent&state=' + state + '">Sign in with google</a>').appendTo(frm);

frm.children('#sign_with_google').on('click', function(){
return false;
Expand Down
10 changes: 9 additions & 1 deletion pages/redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,13 @@
auth_set_cookies( $user_id, false );
auth_set_tokens( $user_id );

print_header_redirect( '../../../my_view_page.php' );
// Obtain the redicrect url from state param
// Example: state=view.php?id=2222
if (isset($_GET['state'])) {
$return_path = $_GET['state'];
$redirect_url = '../../../' . $return_path;
} else {
$redirect_url = '../../../index.php';
}

print_header_redirect( $redirect_url );

0 comments on commit c84b36b

Please sign in to comment.