<%@ page extends="oneit.servlets.jsp.FormJSP" %>

<%@ include file="/setuprequest.jsp" %>
<%@ include file="/inc/stdimports50.jsp" %><%-- This is in cougar --%>
<%@ include file="/extensions/performa/inc/stdimports.jsp" %>

<%! protected String getName (ServletConfig config) { return "email_verified_jsp"; } %>

<%@ include file="inc/htmlheader_nopriv.jsp" %>

<%
    ORMProcessState     process     =   (ORMProcessState) ProcessDecorator.getDefaultProcess(request);
    ObjectTransaction   objTran     =   process.getTransaction ();
    String              nextPage    =   WebUtils.getArticleByShortCut(process.getTransaction(), WebUtils.ADMIN_HOME).getLink(request);

    //to process company user verification
    String              id          =   request.getParameter("id");
    String              key         =   request.getParameter("key");
    Boolean             invalid     =   Boolean.TRUE;   
            
    if(id!=null && key!=null)
    {
        CompanyUser companyUser =   CompanyUser.searchIdPin(objTran, Long.parseLong(id), key);

        if(companyUser!=null && companyUser.getIsEmailChanged()==Boolean.TRUE)
        {
            try
            {
                companyUser.setIsEmailChanged(Boolean.FALSE);
                companyUser.setIsAccountVerified(Boolean.TRUE);
                
                objTran.commit();
                objTran.commitResources();
            }
            finally
            {
                objTran.releaseResources();
            }
            
            invalid =   Boolean.FALSE;
//            response.sendRedirect(nextPage);
        }
    }
    
    if(invalid)
    {
%>
        <h3>Verification Error</h3>
        <p><span>Access expired.</span></p>
<%
    }
    else
    {
%>
        <p>Your e-mail address is successfully verified! Please login to access your account!</p>
        <a class="btn btn-primary" href="<%= nextPage %>">Go to login</a>
<%
    }
%>

<%@ include file="inc/htmlfooter_nopriv.jsp" %>