Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
fix(login redirect): preserves hash location after login (#1228)
Browse files Browse the repository at this point in the history
fix(profile): redirect to login is user not logged in

https://zanata.atlassian.net/browse/ZNTA-1051
  • Loading branch information
Alex Eng committed Jul 4, 2016
1 parent 62d52d8 commit 19f9659
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
11 changes: 9 additions & 2 deletions frontend/src/main/web/src/actions/profile.js
Expand Up @@ -91,8 +91,15 @@ const getUserInfo = (dispatch, username, dateRangeOption) => {

export const profileInitialLoad = (username) => {
return (dispatch, getState) => {
dispatch(getUserInfo(dispatch, username || window.config.user.username,
getState().profile.dateRangeOption))
const config = window.config
if (isEmpty(username) && !config.permission.isLoggedIn) {
// redirect to login screen if no username is found url
// and user is not logged in
window.location = config.baseUrl + config.links.loginUrl + '#profile'
} else {
dispatch(getUserInfo(dispatch, username,
getState().profile.dateRangeOption))
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion frontend/src/main/web/src/containers/UserProfile/index.jsx
Expand Up @@ -50,7 +50,10 @@ const classes = {
class UserProfile extends Component {

componentDidMount () {
this.props.handleInitLoad(this.props.params.username)
const paramUsername = this.props.params.username
const username = (!paramUsername || paramUsername === 'undefined')
? undefined : paramUsername
this.props.handleInitLoad(username)
}

render () {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/main/web/webpack.config.js
Expand Up @@ -40,5 +40,9 @@ module.exports = {
},
node: {
__dirname: true
},
eslint: {
failOnWarning: false,
failOnError: true
}
}
11 changes: 10 additions & 1 deletion zanata-war/src/main/webapp/account/login.xhtml
Expand Up @@ -20,6 +20,15 @@
var usernameFieldId = "[id='#{rich:clientId('username')}']";
jQuery(usernameFieldId).focus()
})

/**
* enforce hash location by appending the hash lication to the current
* action so that it persists to the redirected URL.
*/
function onLogin(form) {
form.action = form.action + window.location.hash;
return true;
}
</script>

<div class="header__logo-only">
Expand Down Expand Up @@ -62,7 +71,7 @@
</ui:fragment>

<h:form id="loginForm"
styleClass="l--push-top-half l--pad-all-1 bg--pop-higher">
styleClass="l--push-top-half l--pad-all-1 bg--pop-higher" onsubmit="return onLogin(this)">
<div class="l--clearfix">
<h:outputLabel for="username"
styleClass="l--float-left">#{msgs['jsf.Username']}</h:outputLabel>
Expand Down

0 comments on commit 19f9659

Please sign in to comment.