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

Commit

Permalink
Merge pull request #168 from zanata/rhbz981071
Browse files Browse the repository at this point in the history
Fix redirect to register page after login: https://bugzilla.redhat.com/show_bug.cgi?id=981071
  • Loading branch information
carlosmunoz committed Sep 9, 2013
2 parents d9d3854 + ccc5cb9 commit 627dd85
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Expand Up @@ -249,7 +249,7 @@ else if (identity.isLoggedIn())
{
if (userRedirect != null)
{
if(userRedirect.isRedirect() && !userRedirect.isRedirectToHome())
if(userRedirect.isRedirect() && !userRedirect.isRedirectToHome() && !userRedirect.isRedirectToRegister())
{
return "redirect";
}
Expand Down
27 changes: 21 additions & 6 deletions zanata-war/src/main/java/org/zanata/security/UserRedirectBean.java
Expand Up @@ -29,8 +29,6 @@
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.faces.Redirect;
import org.jboss.seam.security.Identity;
import org.jboss.seam.web.ServletContexts;

/**
Expand All @@ -51,6 +49,7 @@
public class UserRedirectBean implements Serializable
{
private static final String HOME_URL = "/";
private static final String REGISTER_URL = "/register";
private static final String ERROR_URL = "/error";

/**
Expand Down Expand Up @@ -177,17 +176,33 @@ public boolean isRedirect()
}

public boolean isRedirectToHome()
{
return isRedirectTo(HOME_URL);
}

public boolean isRedirectToRegister()
{
return isRedirectTo(REGISTER_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 url = 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(HOME_URL))
if (redirectingUrl.endsWith(url))
{
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions zanata-war/src/main/webapp/WEB-INF/pages.xml
Expand Up @@ -53,7 +53,7 @@
<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.redirect}">
Expand Down Expand Up @@ -105,7 +105,7 @@
<begin-conversation/>
<redirect view-id="/account/inactive_account.xhtml"/>
</rule>
<rule if="#{authenticationManager.authenticated and !authenticationManager.newUser and userRedirect.redirectToHome}">
<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 627dd85

Please sign in to comment.