<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" session="true"%>
<%@page errorPage="Exception.jsp"%>
<%@page import="com.fujitsu.iflow.model.util.URLEncoder"%>
<%request.setCharacterEncoding("UTF-8");request.getParameterNames(); //Need dummy call for WL9.1%>
<%

    /********************************************
    * PLEASE READ BEFORE MODIFYING THIS FILE
    *
    * The Login page does not do Login itself.
    *
    * There should not even be a Login page.  Login is supposed to be implicit as part of accessing a
    * real page.  If you try to access the TaskList page, and it finds that you do not have a valid
    * session, then that page will redirect to the PasswordPrompt page to authenticate the user.
    * Therefor you should always link to the actual destination page, and never to a "Login" page.
    *
    * But old habits die hard, and there are many links existing, and more made all the time, to this page.
    *
    * The primary purpose of this page is to redirect the browser to a real page, and cause
    * user authentication to happen on the way there.  If the real page is not specified, then it
    * redirects by default to the task list page,
    *
    * There is also some legacy code where email messages would send a link to the Login page, with
    * some extra parameters like 'uid' 'aid' 'server' and 'proto'.  The old login page used to
    * authenticate the user, and then forward to the item page.  Instead, this Login page figures out
    * where the link should have been to, and redirects to there ... the user authentication will happen
    * only if needed.
    **********************************************/


    String goPage = "WorkList.jsp";

    /**********************************
    * Special behavior for "email" interface
    * uid = user id - not using this now, not sure if it is important
    * aid = activity id (workitem id)
    * server = server name, but not needed any more
    * proto = protocol, not needed because this is configured by the task manager
    **************************************/
    String wid = request.getParameter("wid");
    if (wid != null) {
        goPage = "WorkItem.jsp?taskId=" + wid;
    }
    else {
        // may be some email around with 'aid' in the URL
        String uid = request.getParameter("uid");
        String aid = request.getParameter("aid");
        if (aid!=null && uid!=null) {
            goPage = "WorkItem.jsp?aid=" + aid + "&uid=" + URLEncoder.encode(uid, "UTF8");
        }
    }

    response.sendRedirect(goPage);

%>
