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

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

<oneit:dynIncluded>

<%
    ORMProcessState     process             =   (ORMProcessState)ProcessDecorator.getDefaultProcess(request);
    String              candidateID         =   (String) process.getAttribute("candidateID"); //request.getParameter("id");
    String              forgotpasswordCode  =   (String) process.getAttribute("forgotpasswordCode"); //request.getParameter("key");
    SecUser             user                =   (SecUser) process.getAttribute("SecUser");
    Article             home                =   WebUtils.getArticleByShortCut(process.getTransaction(), WebUtils.ADMIN_HOME);
    String              nextPage            = 	home.getLink(request);
    
    if(request.getParameter("id")!=null)
    {
        candidateID =   request.getParameter("id");
        process.setAttribute("candidateID", candidateID);
    }
    
    if(request.getParameter("key")!=null)
    {
        forgotpasswordCode  =   request.getParameter("key");
        process.setAttribute("forgotpasswordCode", forgotpasswordCode);
    }
    
    if(StringUtils.subBlanks(companyUserID) != null)
    {
        Canddate    candidate   =   CompanyUser.getCandidateForForgotPassword(process.getTransaction(), candidateID, forgotpasswordCode);

        if(candidate != null)
        {
            user    =  candidate.getUser();

//            if(StringUtils.subBlanks(forgotpasswordCode) != null)
//            {
//                RandomStringGen     random  =   new RandomStringGen();
//
//                user.setAttribute("md5:Password", random.generateAlphaNum(8));
//            }

            process.setAttribute("SecUser", user);
        }
    }
%>

<script type="text/javascript">
    $(document).ready(function() {
        validate();
        $('input').on('change keyup', function() { validate() });
    });

    function validate() {
        var empty = false;
        $('.password-field').each(function() {
            if ( $.trim($( this ).val()) == '') {
                empty = true;
            }
        });

        if (empty) {
            $('.reset-btn').attr('disabled', 'disabled');
        } else {
            $('.reset-btn').removeAttr('disabled');
        }
    }
</script>
<style>
    button[disabled] {
        opacity: 0.6;
        background-color: #0582ba;
    }
</style>

    <oneit:form name="resetPassword"    method="post">
    
            <oneit:dynInclude   page="/extensions/applicantportal/inc/multifieldtext.jsp"   data="<%= CollectionUtils.EMPTY_MAP%>"/>

        <%
            if(user!=null)
            {
                String  key =   Utils.getPwdKeyOfSecUser(request, user, true);
        %>
                <div class="main-box-layout login-box">
                    <div class="text-left">
                        <p >
                            Please enter a new password below.
                        </p>
                    </div>
                    <div>&nbsp;</div>
                    <div class="form-group text-left">
                        <label>Password *</label>
                        <oneit:input type="password" name="<%= key %>"      class="form-control password-field"/>
                    </div> <!-- form-group -->
                    <div class="form-group text-left">
                        <label>Confirm Password *</label>
                        <oneit:input type="password" name="<%= key + 2 %>"  class="form-control password-field"/>
                    </div> <!-- form-group -->
                    <div class="col-sm-12">
                        <oneit:button   value="Set New Password"    name="resetPassword"  cssClass="box-btn reset-btn"
                                        requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage).toMap() %>"/>
                    </div>
                </div>
        <%
            }
            else
            {
        %>
                <h3 class="text-danger">Invalid User or this link has been expired, generate new link to access this page.</h3>
        <%
            }
        %>
    </oneit:form>
</oneit:dynIncluded>