Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
[Web Portal] redirect back to original page after login (#3092)
Browse files Browse the repository at this point in the history
* redirect back to original page after login

* fix

* fix2

* fix variable name conflicts
  • Loading branch information
sunqinzheng authored Jul 26, 2019
1 parent 0222b5a commit 27c44a6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
11 changes: 9 additions & 2 deletions src/webportal/src/app/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import 'whatwg-fetch';

import {FontClassNames} from '@uifabric/styling';
import c from 'classnames';
import {isEmpty} from 'lodash';
import {initializeIcons} from 'office-ui-fabric-react';
import querystring from 'querystring';
import React, {useState, useCallback} from 'react';
import ReactDOM from 'react-dom';
import url from 'url';

import Bottom from './index/bottom';
import {login} from './index/conn';
Expand All @@ -33,9 +35,14 @@ import LoginModal from './index/login-modal';
import {checkToken} from '../user/user-auth/user-auth.component';
import config from '../config/webportal.config';
import t from 'tachyons-sass/tachyons.scss';
import url from 'url';

const loginTarget = '/home.html';
let loginTarget = '/home.html';

const currentUrl = new URL(window.location.href);
const from = currentUrl.searchParams.get('from');
if (!isEmpty(from)) {
loginTarget = from;
}

if (config.authnMethod === 'OIDC') {
const query = url.parse(window.location.href, true).query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ $(document).ready(() => {
alert(userData.message);
} else {
alert('Change password successfully, please login again.');
userLogout();
userLogout('/home.html');
}
},
error: (xhr, textStatus, error) => {
Expand Down
3 changes: 2 additions & 1 deletion src/webportal/src/app/user/user-auth/user-auth.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

const {userLogout} = require('../user-logout/user-logout.component.js');

const checkToken = (callback, redirectToLogin=true) => {
if (typeof callback === 'boolean') {
Expand All @@ -23,7 +24,7 @@ const checkToken = (callback, redirectToLogin=true) => {
}
const authToken = cookies.get('token');
if (!authToken && redirectToLogin) {
window.location.replace('/index.html');
userLogout();
} else if (callback) {
callback(authToken);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<% if (window.ENV.authnMethod !== 'OIDC') { %>
<li><a href="#" onclick="window.location.replace('/change-password.html')">Change password</a></li>
<% } %>
<li><a href="#" onclick="userLogout()">Logout</a></li>
<li><a href="#" onclick="userLogout('/home.html')">Logout</a></li>
</ul>
</li>
<% } else { %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

const querystring = require('querystring');
const webportalConfig = require('../../config/webportal.config.js');

const userLogout = () => {
const userLogout = (origin = window.location.href) => {
cookies.remove('user');
cookies.remove('token');
cookies.remove('admin');
cookies.remove('my-jobs');
if (webportalConfig.authnMethod === 'basic') {
window.location.replace('/index.html');
if (!origin) {
window.location.replace('/index.html');
} else {
window.location.replace(`/index.html?${querystring.stringify({from: origin})}`);
}
} else {
location.href = webportalConfig.restServerUri+'/api/v1/authn/oidc/logout';
}
Expand Down

0 comments on commit 27c44a6

Please sign in to comment.