return Controller.redirect((String) o);
} else if (o instanceof Result) {
return (Result) o;
} else if (o instanceof AuthUser) {
final AuthUser newUser = (AuthUser) o;
final Session session = context.session();
// We might want to do merging here:
// Adapted from:
// http://stackoverflow.com/questions/6666267/architecture-for-merging-multiple-user-accounts-together
// 1. The account is linked to a local account and no session
// cookie is present --> Login
// 2. The account is linked to a local account and a session
// cookie is present --> Merge
// 3. The account is not linked to a local account and no
// session cookie is present --> Signup
// 4. The account is not linked to a local account and a session
// cookie is present --> Linking Additional account
// get the user with which we are logged in - is null if we
// are
// not logged in (does NOT check expiration)
AuthUser oldUser = getUser(session);
// checks if the user is logged in (also checks the expiration!)
boolean isLoggedIn = isLoggedIn(session);
Object oldIdentity = null;
// check if local user still exists - it might have been
// deactivated/deleted,
// so this is a signup, not a link
if (isLoggedIn) {
oldIdentity = getUserService().getLocalIdentity(oldUser);
isLoggedIn = oldIdentity != null;
if (!isLoggedIn) {
// if isLoggedIn is false here, then the local user has
// been deleted/deactivated
// so kill the session
logout(session);
oldUser = null;
}
}
final Object loginIdentity = getUserService().getLocalIdentity(
newUser);
final boolean isLinked = loginIdentity != null;
final AuthUser loginUser;
if (isLinked && !isLoggedIn) {
// 1. -> Login
loginUser = newUser;
} else if (isLinked) {