package com.github.mfursov.w7.page;

import com.github.mfursov.w7.UserSession;
import com.github.mfursov.w7.page.signin.LoginPage;
import com.github.mfursov.w7.util.HttpUtils;
import org.apache.wicket.RestartResponseException;

import javax.servlet.http.HttpServletRequest;

public abstract class BaseUserPage extends BasePage {

    public BaseUserPage() {
        this(false);
    }

    public BaseUserPage(boolean skipRedirect) {
        if (!UserSession.get().isSignedIn() && !skipRedirect) {
            HttpUtils.saveLastViewedPage((HttpServletRequest) getRequest().getContainerRequest());
            throw new RestartResponseException(LoginPage.class);
        }
    }

}
