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

Commit

Permalink
Create shouldRedirectToDashboard to merge redirect pages conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Sep 9, 2013
1 parent 5cafe65 commit ccc5cb9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 11 additions & 5 deletions zanata-war/src/main/java/org/zanata/security/UserRedirectBean.java
Expand Up @@ -185,18 +185,24 @@ public boolean isRedirectToRegister()
return isRedirectTo(REGISTER_URL);
}

private boolean isRedirectTo(String URL)
// provided user is logged in, they should be redirect to dashboard
public boolean shouldRedirectToDashboard()
{
return isRedirectToHome() || isRedirectToRegister();
}

private boolean isRedirectTo(String url)
{
if (isRedirect())
{
String redirectUrl = getUrl();
int qsIndex = url.indexOf('?');
String redirectingUrl = getUrl();
int qsIndex = redirectingUrl.indexOf('?');
if (qsIndex > 0)
{
url = url.substring(0, qsIndex);
redirectingUrl = redirectingUrl.substring(0, qsIndex);
}

if (url.endsWith(URL))
if (redirectingUrl.endsWith(url))
{
return true;
}
Expand Down
10 changes: 2 additions & 8 deletions zanata-war/src/main/webapp/WEB-INF/pages.xml
Expand Up @@ -53,12 +53,9 @@
<rule if="#{!identity.loggedIn}">
<redirect view-id="/account/login_input.xhtml" />
</rule>
<rule if="#{authenticationManager.authenticated and !authenticationManager.newUser and userRedirect.redirectToHome}">
<rule if="#{authenticationManager.authenticated and !authenticationManager.newUser and userRedirect.userRedirect.shouldRedirectToDashboard()}}">
<redirect view-id="/dashboard/home.xhtml" />
</rule>
<rule if="#{authenticationManager.authenticated and !authenticationManager.newUser and userRedirect.redirectToRegister}">
<redirect view-id="/dashboard/home.xhtml" />
</rule>
<rule if="#{authenticationManager.authenticated and !authenticationManager.newUser and userRedirect.redirect}">
<redirect url="#{userRedirect.url}" />
</rule>
Expand Down Expand Up @@ -108,10 +105,7 @@
<begin-conversation/>
<redirect view-id="/account/inactive_account.xhtml"/>
</rule>
<rule if="#{authenticationManager.authenticated and !authenticationManager.newUser and userRedirect.redirectToHome}">
<redirect view-id="/dashboard/home.xhtml" />
</rule>
<rule if="#{authenticationManager.authenticated and !authenticationManager.newUser and userRedirect.redirectToRegister}">
<rule if="#{authenticationManager.authenticated and !authenticationManager.newUser and userRedirect.shouldRedirectToDashboard()}">
<redirect view-id="/dashboard/home.xhtml" />
</rule>
<rule if="#{authenticationManager.authenticated and !authenticationManager.newUser and userRedirect.redirect}">
Expand Down

0 comments on commit ccc5cb9

Please sign in to comment.