-------------------------------------visualforce page----------------------------------------- <apex:page controller="LeadlistDisplayCntrl" extensions="DealerPortalLoginControllerCRA" showHeader="false" sidebar="false" standardStylesheets="true" applyHTmlTag="false" lightningStylesheets="true" action="{!checkSessionValidity}"> <!-- * @description It is Lead list view through Dealer portal * * * @author Janardhan Muddana --> <style> .top-right { position: absolute; top: 22px; right: 16px;color: #FFFFFF; } </style> <script> window.onload = backButtonOverride; function backButtonOverride() { setTimeout("backButtonOverrideBody()", 1); } function backButtonOverrideBody() { try { history.forward(); } catch (e) { } setTimeout("backButtonOverrideBody()", 500); } function checksessionOnApply() { var check1= '{!SessionTimeoutonApply}'; if(check1){ checkSession(); } } </script> <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" lang="en"> <head> <meta charset="utf-8" /> <meta http-equiv="x-ua-compatible" content="ie=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <apex:slds /> <div> <apex:image id="theImage" value="https://c.eu5.content.force.com/servlet/servlet.ImageServer?id=01524000001XG0s&oid=00D24000000e4Gc&lastMod=1474615125000" width="100%"/> <div class="top-right" style="right: 55px;top: 28px;font-family: Arial, Helvetica, sans-serif;"><b>{!conName}</b></div> <apex:image value="https://c.cs88.content.force.com/servlet/servlet.ImageServer?id=0159E000000IDtY&oid=00D9E000000D1fA&lastMod=1520397060000" styleClass="top-right"/> </div> </head> <body class="slds-scope"> <apex:form > <apex:actionFunction name="checkSession" action="{!checkSessionValidity}" /> <apex:pageBlock > <div class="slds-clearfix"> <div style="margin-bottom:9px;" class="slds-float_right"> <!-- As per business request, this button is disabled - Janardhan <apex:commandbutton action="{!CreateLead}" value="Create New Lead" styleClass="slds-button slds-button_success "/> --> <apex:commandbutton action="{!backtoHomePage}" value="Home" styleClass="slds-button slds-button_brand"/> <apex:commandbutton action="{!logout}" value="Logout" styleClass="slds-button slds-button_destructive "/> </div> </div> <div align = "Center"> <apex:pageBlockSection title="Filter" collapsible="false" > </apex:pageBlockSection> <table class="slds-table slds-align_absolute-center"> <tr> <td data-label="Lead status"> <div class="slds-truncate" title="LeadStatus">Lead Status:</div> </td> <td> <apex:selectList value="{!leadStatusVal}" multiselect="false" size="1"> <apex:selectOption itemValue="" itemLabel="--------All--------"/> <apex:selectOption itemValue="Open" itemLabel="Open"/> <apex:selectOption itemValue="Qualified" itemLabel="Qualified"/> <apex:selectOption itemValue="Disqualified" itemLabel="Disqualified"/> <apex:selectOption itemValue="Converted" itemLabel="Converted"/> </apex:selectList> </td> </tr> <tr> <td data-label="Lead Number" > <div class="slds-truncate" title="Lead Number">Lead Number:</div> </td> <td > <apex:inputtext id="leadNumber" value="{!leadNumber}" /> </td> </tr> <tr> <td > <div class="slds-truncate" title="Last Name">Last Name:</div> </td> <td > <apex:inputtext id="LastName" value="{!strLastName}" /> </td> </tr> <tr> <td> <div class="slds-truncate" title="First Name">First Name:</div> </td> <td > <apex:inputtext id="firstName" value="{!strFirstName}" /> </td> </tr> </table> <table class="slds-table slds-align_absolute-center"><tr><td> <apex:commandbutton action="{!setApply}" status="fetchStatusonApply" rerender="results" value="Apply" styleClass="slds-button slds-button_brand"/> <!-- oncomplete="checksessionOnApply();" --> </td></tr></table> </div> </apex:pageBlock> </apex:form> <apex:form > <apex:pageBlock id="results"> <apex:pageBlockSection title="Result" collapsible="false" id="result" columns="1"> <apex:outputPanel id="LeadList" layout="block"> <apex:actionStatus id="fetchStatusonApply" startText="Loading.." stopText=""> <apex:facet name="start"> <div class="slds-spinner_container"> <div role="status" class="slds-spinner slds-spinner_medium slds-spinner_brand"> <span class="slds-assistive-text">Loading</span> <div class="slds-spinner__dot-a"></div> <div class="slds-spinner__dot-b"></div> </div> </div> </apex:facet> </apex:actionStatus> <!-- list of Lead records --> <center> <apex:pageBlockTable id="center" value="{!lstLead}" var="lead" style="width:100%"> <apex:column headerValue="LEAD NUMBER" style="width:100px;"> <apex:outputLink value="{!URLFOR($Page.LeadDetailFromLeadList,'',[Id=lead.id, token= strToken,dName=strDName ])}"> <apex:outputText value="{!lead.Lead_ID__c}" /> </apex:outputLink> </apex:column> <apex:column value="{!lead.name}" headerValue="NAME" style="width:150px;"/> <apex:column value="{!lead.status}" headerValue="STATUS" style="width:200px;"/> <apex:column value="{!lead.CreatedDate}" headerValue="CREATED DATE" style="width:150px;"/> </apex:pageBlockTable> </center> </apex:outputPanel> </apex:pageBlockSection> <!-- pagination Logic ---> <div class="slds-button-group slds-align_absolute-center" role="group"> <apex:commandButton id="frst" status="fetchStatus" reRender="results" value="|<" action="{!first}" disabled="{!!hasPrevious}" title="First Page" styleClass="slds-button slds-button_brand" style="border-radius:9px;"/> <apex:commandButton id="prev" status="fetchStatus" reRender="results" value="<" action="{!previous}" disabled="{!!hasPrevious}" title="Previous Page" styleClass="slds-button slds-button_brand" style="border-radius: 9px;margin-left: 2px;"/> <apex:commandButton id="nxt" status="fetchStatus" reRender="results" value=">" action="{!next}" disabled="{!!hasNext}" title="Next Page" styleClass="slds-button slds-button_brand" style="border-radius: 9px;margin-left: 2px;"/> <apex:commandButton id="lst" status="fetchStatus" reRender="results" value=">|" action="{!last}" disabled="{!!hasNext}" title="Last Page" styleClass="slds-button slds-button_brand" style="border-radius: 9px;margin-left: 2px;"/> <apex:outputText id="pagenum">{!(pageNumber*size)+1-size}-{!IF((pageNumber * size)>noOfRecords, noOfRecords,(pageNumber * size))} of {!noOfRecords}</apex:outputText> </div> <apex:outputPanel > <apex:actionStatus id="fetchStatus" startText="Loading.." stopText=""> <apex:facet name="start"> <div class="slds-spinner_container"> <div role="status" class="slds-spinner slds-spinner_medium slds-spinner_brand"> <span class="slds-assistive-text">Loading</span> <div class="slds-spinner__dot-a"></div> <div class="slds-spinner__dot-b"></div> </div> </div> </apex:facet> </apex:actionStatus> </apex:outputPanel> </apex:pageBlock> </apex:form> </body> </html> </apex:page> --------------------------------------------controller Class---------------------------------------------- global class LeadlistDisplayCntrl { global String leadStatusVal {get;set;} global String leadNumber {get;set;} global String strLastName {get;set;} global String strFirstName {get;set;} global string conName {get;set;} global String soql {get;set;} global String leadListSoql; global String strToken {get;set;} global Integer size {get;set;} global Integer noOfRecords {get;set;} global List < Dealer_Login_History__c > lstDealerHist {get;set;} global String soqlLoginHist {get;set;} global String soqlDealerCon {get;set;} global List <contact> lstDealerCon {get;set;} global Set < Id > setLeadId = new Set < Id > (); global PageReference reRend; global string strDName {get;set;} global ApexPages.StandardSetController con { get{ if (con == null) { strToken = System.currentPageReference().getParameters().get('token'); strDName = System.currentPageReference().getParameters().get('dName'); system.debug('ttttt'+strToken); size = 10; //Integer.valueOf(System.Label.PaginationLimit); soqlLoginHist = 'select Dealer__c from Dealer_Login_History__c where token__c = \'' + String.escapeSingleQuotes(System.currentPageReference().getParameters().get('token')) + '\''; lstDealerHist = Database.query(soqlLoginHist); soqlDealerCon = 'select AccountId,name from contact where id = \'' + String.escapeSingleQuotes(lstDealerHist[0].Dealer__c) + '\''; lstDealerCon = Database.query(soqlDealerCon); conName = lstDealerCon[0].name; leadListSoql='select id,name,Lead_ID__c,CreatedDate,Status from Lead '; leadListSoql+= 'where recordtype.name = \'TD - SA\' and Preferred_Dealer_Account__c = \'' + String.escapeSingleQuotes(lstDealerCon[0].AccountId) + '\' '; leadListSoql+='order by CreatedDate desc LIMIT 10000'; con = new ApexPages.StandardSetController(Database.getQueryLocator(leadListSoql)); con.setPageSize(size); noOfRecords = con.getResultSize(); } return con; } set; } global void runQuery(String query) { try{ leadListSoql = 'select id,name,Lead_ID__c,CreatedDate,Status from Lead where Preferred_Dealer_Account__c =\'' + String.escapeSingleQuotes(lstDealerCon[0].AccountId) + '\''; leadListSoql+=query; leadListSoql+= 'order by CreatedDate desc LIMIT 10000'; list<lead> lstFilterLeads = Database.query(leadListSoql); con = new ApexPages.StandardSetController(Database.getQueryLocator(leadListSoql)); con.setPageSize(size); noOfRecords = con.getResultSize(); } catch (Exception e) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Exception on run query' + e.getMessage())); } } /* global void setSoqlforLeadList(String soql) { soql = leadListSoql; } global String getSoqlforLeadList() { return leadListSoql; } global Set < Id > getLeadSet() { return setLeadId; } */ global List <lead> getApply() { return null; } public PageReference setApply() { soql=''; if (String.isnotEmpty(leadNumber)) soql += ' and Lead_ID__c LIKE \'%' + String.escapeSingleQuotes(leadNumber) + '%\''; if (String.isnotEmpty(leadStatusVal)) soql += ' and Status = \'' + String.escapeSingleQuotes(leadStatusVal) + '\''; if (String.isnotEmpty(strLastName)) soql += ' and LastName LIKE \'%' + String.escapeSingleQuotes(strLastName) + '%\''; if (String.isnotEmpty(strFirstName)) soql += ' and firstNameLIKE \'%' + String.escapeSingleQuotes(strFirstName) + '%\''; runQuery(soql); return null; } global List <lead> getlstLead() { List <lead> leadList = new List <lead> (); for (lead objLead: (List <lead> ) con.getRecords()) leadList.add(objLead); return leadList; } global Boolean hasNext { get { return con.getHasNext(); } set; } global Boolean hasPrevious { get { return con.getHasPrevious(); } set; } global Integer pageNumber { get { return con.getPageNumber(); } set; } global void first() { con.first(); } global void last() { con.last(); } global void previous() { con.previous(); } global void next() { con.next(); } public PageReference CreateLead() { reRend = new PageReference('/apex/NSALeadCapturePage'); reRend.getParameters().put('token', strToken); reRend.setRedirect(true); return reRend; } ------------------------------Extension class----------------------------- /* * [#Dealer Lead Login Portal - CR] * @description Dealer able to login and see Lead details * @author Janardhan Muddana */ global with sharing class DealerPortalLoginControllerCRA { public DealerPortalLoginControllerCRA(CaseListOnDealerPortalController controller) { } public DealerPortalLoginControllerCRA(ButtonsRedirectCtrl controller) { } public DealerPortalLoginControllerCRA(CRARemovalListCtrl controller) { } public DealerPortalLoginControllerCRA(LeadlistDisplayCntrl controller) { strToken = System.currentPageReference().getParameters().get('token'); } global String ContactName {get;set;} global boolean isError {get;set;} global String filename {get;set;} global string conDealerName {get;set;} global Transient Blob filebody {get;set;} global String Did {get;set;} global String updatedComment; global string strToken {get;set;} global String randomtoken {get;set;} global boolean SessionTimeoutonApply {get;set;} global String textUsername; global String textPassword; global String caseId; global String contactId; global List < Contact > lstContact; global PageReference reRend; global string leadId {get;set;} global String gettextUsername() { return textUsername; } global String gettextPassword() { return textPassword; } global String getRandomToken() { return randomtoken; } global void settextUsername(String newuser) { textUsername = newuser; } global void settextPassword(String newpwd) { textPassword = newpwd; } global void setRandomToken() { randomtoken = System.currentPageReference().getParameters().get('token'); } public DealerPortalLoginControllerCRA(pdfViewController controller) { } global DealerPortalLoginControllerCRA() { strToken = System.currentPageReference().getParameters().get('token'); leadId = System.currentPageReference().getParameters().get('id'); } global DealerPortalLoginControllerCRA(ApexPages.StandardController controller) { strToken = System.currentPageReference().getParameters().get('token'); SessionTimeoutonApply = false; } global PageReference CRAlogin() { //scriptvar='<script> func(); </script>'; isError = false; //check if user logs in through email URL or direct portal //caseId = System.currentPageReference().getParameters().get('id'); if (String.isnotblank(textUsername) && String.isnotblank(textPassword)) { String soql = 'select id, name, National_Id_Number__c, Dealer_Portal_Password__c, Dealer_Portal_Access_Allowed__c from Contact'; soql += ' where National_Id_Number__c = \'' + String.escapeSingleQuotes(textUsername) + '\''; soql += ' LIMIT 1'; lstContact = Database.query(soql); if (lstContact.size() > 0){ conDealerName = lstContact[0].name; } if (lstContact.size() <= 0) { ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, System.Label.ErrorInvalidUsername)); rerend = null; } if (lstContact.size() > 0) { //Validate login if (textUsername.EqualsIgnoreCase(lstContact[0].National_Id_Number__c) && textPassword.Equals(lstContact[0].Dealer_Portal_Password__c)) { // Allow login if Dealer has access to portal if (!(lstContact[0].Dealer_Portal_Access_Allowed__c)) { ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, System.Label.ErrorLoginDisabled)); rerend = null; } else { //Check if there is already a session existing /* List < Dealer_Login_History__c > lstDealerHist = [select id from Dealer_Login_History__c where Dealer__r.National_Id_Number__c = : textUsername and ValidTo__c > : System.Now() and Status__c != 'LOGOUT']; if (lstDealerHist.size() > 0) { reRend = new PageReference('/apex/DealerExistingSessionError'); } else { */ //Create new session randomtoken = getToken(lstContact[0].id); Did = lstContact[0].id; createLoginHistory(randomtoken, lstContact[0].id); if(String.isnotblank(leadId) && leadId.startsWith('00Q')){ reRend = new PageReference('/apex/LeadDetailFromLeadList'); reRend.getParameters().put('id', leadId ); }else if(String.isnotblank(leadId) && leadId.startsWith('500')){ reRend = new PageReference('/apex/CaseDetailforDealerfromList'); reRend.getParameters().put('id', leadId ); }else { reRend = new PageReference('/apex/ButtonsRedirectPage'); } reRend.getParameters().put('token', randomtoken); reRend.getParameters().put('Did', Did); reRend.getParameters().put('dName', conDealerName); } } else { ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, System.Label.ErrorIncorrectusernameorpassword)); } return rerend; } } else { //Credential cannot be blank ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, System.Label.ErrorUserCredentialCannotbeBlank)); } return reRend; } global PageReference Leadlogin() { reRend = new PageReference('/apex/LeadListOnLeadPortal'); reRend.getParameters().put('token', strToken); reRend.getParameters().put('dName', conDealerName); /* isError = false; //check if user logs in through email URL or direct portal if (String.isnotblank(textUsername) && String.isnotblank(textPassword)) { String soql = 'select id, name, National_Id_Number__c, Dealer_Portal_Password__c, Dealer_Portal_Access_Allowed__c from Contact'; soql += ' where National_Id_Number__c = \'' + String.escapeSingleQuotes(textUsername) + '\''; soql += ' LIMIT 1'; lstContact = Database.query(soql); if (lstContact.size() > 0){ conDealerName = lstContact[0].name; } if (lstContact.size() <= 0) { ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, System.Label.ErrorInvalidUsername)); rerend = null; } if (lstContact.size() > 0) { //Validate login if (textUsername.EqualsIgnoreCase(lstContact[0].National_Id_Number__c) && textPassword.Equals(lstContact[0].Dealer_Portal_Password__c)) { // Allow login if Dealer has access to portal if (!(lstContact[0].Dealer_Portal_Access_Allowed__c)) { ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, System.Label.ErrorLoginDisabled)); rerend = null; } else { //Check if there is already a session existing List < Dealer_Login_History__c > lstDealerHist = [select id from Dealer_Login_History__c where Dealer__r.National_Id_Number__c = : textUsername and ValidTo__c > : System.Now() and Status__c != 'LOGOUT']; if (lstDealerHist.size() > 0) { reRend = new PageReference('/apex/DealerExistingSessionError'); } else { //Create new session randomtoken = getToken(lstContact[0].id); createLoginHistory(randomtoken, lstContact[0].id); //Redirect user to Case List if (String.isnotblank(leadId)){ reRend = new PageReference('/apex/LeadDetailFromLeadList'); reRend.getParameters().put('id', leadId ); }else { reRend = new PageReference('/apex/LeadListOnLeadPortal'); } reRend.getParameters().put('token', randomtoken); reRend.getParameters().put('dName', conDealerName); } } } else { ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, System.Label.ErrorIncorrectusernameorpassword)); } return rerend; } } else { //Credential cannot be blank ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, System.Label.ErrorUserCredentialCannotbeBlank)); } */ return reRend; } global void createLoginHistory(String token, Id contactId) { //set session cookies Cookie counter = new Cookie('counter', String.valueOf(System.now()), null, -1, false); ApexPages.currentPage().setCookies(new Cookie[] { counter }); //create a new entry in Login history Dealer_Login_History__c dealerLogin = new Dealer_Login_History__c(); dealerLogin.Token__c = token; dealerLogin.Dealer__c = contactId; dealerLogin.Status__c = 'LOGIN'; dealerLogin.Active__c = true; dealerLogin.LoggedIn__c = System.now(); dealerLogin.ValidTo__c = System.now().addMinutes(20); dealerLogin.SessionCookie__c = String.valueOf(counter); insert dealerLogin; } global ApexPages.PageReference checkSessionValidity() { string strToken; strToken = System.currentPageReference().getParameters().get('token'); if (String.isnotblank(strToken)) { Cookie counter = ApexPages.currentPage().getCookies().get('counter'); String sessionD = getSessionCookie(strtoken); if (counter == null || sessionD == null) { reRend = new PageReference('/apex/DealerLoginCRA'); reRend.getParameters().put('error', System.Label.SessionNotFound); } else { if (String.valueof(counter).Equals(sessionD)) { List < Dealer_Login_History__c > lstdealerLoginHistory = [select token__c, ValidTo__c, Status__c from Dealer_Login_History__c where token__c = : strToken LIMIT 1]; if (lstdealerLoginHistory.size() > 0) { //Existing session String tokenfromDealerHistory = lstdealerLoginHistory[0].token__c; Datetime sessiontimeout = lstdealerLoginHistory[0].ValidTo__c; if (lstdealerLoginHistory[0].ValidTo__c > System.now() && lstdealerLoginHistory[0].Status__c != 'LOGOUT') { //This is an active session reRend = null; } else { //return to InactiveSession/login page reRend = new PageReference('/apex/DealerLoginCRA'); reRend.getParameters().put('error', System.Label.SessionTimeOut); } } else { //No session found with this token //return to InactiveSession/login page reRend = new PageReference('/apex/DealerLoginCRA'); reRend.getParameters().put('error', System.Label.InvalidToken); } } else { reRend = new PageReference('/apex/DealerLoginCRA'); reRend.getParameters().put('error', System.Label.SessionNotFound); } } } else { //No token found //return to InactiveSession/login page reRend = new PageReference('/apex/DealerLoginCRA'); reRend.getParameters().put('error', System.Label.ErrorNoTokenFound); } return reRend; } global Boolean checkSessionTimeOutApply() { String strToken = System.currentPageReference().getParameters().get('token'); if (String.isnotblank(strToken)) { Cookie counter = ApexPages.currentPage().getCookies().get('counter'); String sessionD = getSessionCookie(strtoken); if (String.valueof(counter).Equals(sessionD)) { SessionTimeoutonApply = true; } } return SessionTimeoutonApply; } global String getToken(id cid) { String token = String.valueOf(cid) + String.valueOf(math.random()) + String.valueOf(System.Now()); return token; } global String getContactNamefromLoginHist(String token) { String strContactname = null; if (token != null) { List < Contact > lstCont = [select name from Contact where id in (select Dealer__c from Dealer_Login_History__c where token__c = : token)]; if (lstCont.size() > 0) { strContactname = lstCont[0].name; } } return strContactname; } global String getSessionCookie(String token) { String strCookie = null; if (token != null) { List < Dealer_Login_History__c > lstdealerhist = [select SessionCookie__c from Dealer_Login_History__c where token__c = : token]; if (lstdealerhist.size() > 0) { strCookie = lstdealerhist[0].SessionCookie__c; } } return strCookie; } global ApexPages.PageReference logout() { string strToken; string leadId; strToken = System.currentPageReference().getParameters().get('token'); leadId = System.currentPageReference().getParameters().get('id'); String dealerLoginsoql = 'select id, status__c, token__c from Dealer_Login_History__c where token__c = \'' + String.escapeSingleQuotes(strToken) + '\''; dealerLoginsoql += ' and Active__c = '; dealerLoginsoql += 'true'; try { List < Dealer_Login_History__c > lstLogin = Database.query(dealerLoginsoql); lstLogin[0].Status__c = 'LOGOUT'; lstLogin[0].LoggedOut__c = System.now(); update lstLogin; } catch (Exception e) {} reRend = new PageReference('/apex/DealerLoginCRA'); reRend.setRedirect(true); // reRend.getParameters().put('id', leadId); return reRend; } global ApexPages.PageReference backToLeadList() { reRend = new PageReference('/apex/LeadListOnLeadPortal'); reRend.getParameters().put('token', strToken); reRend.setRedirect(true); return reRend; } global ApexPages.PageReference backtoHomePage() { String strToken= System.currentPageReference().getParameters().get('token'); String Did= System.currentPageReference().getParameters().get('Did'); String dName= System.currentPageReference().getParameters().get('dName'); reRend = new PageReference('/apex/ButtonsRedirectPage'); reRend.getParameters().put('token', strToken); reRend.getParameters().put('Did',Did); reRend.getParameters().put('dName',dName); reRend.setRedirect(true); return reRend; } }

Comments
Post a Comment