Skip to main content
adamaas
Known Participant
December 9, 2011
Answered

Pop up functionality upon login

  • December 9, 2011
  • 1 reply
  • 2267 views

I have a problem to code a functionality in coldfusion.

When I have to log in, there is a pop up that will appear from the first connection. After I login another day or time, the pop up should not appear.

In the database, I store no data about session and log.

My question is what and how do I do to make the pop up appears on the first connection?

Thanks in advance for your answer.

    This topic has been closed for replies.
    Correct answer parkerst

    Ok.

    Well i have understood what u say but i would like to have some assistance of how to code it?

    Thanks


    This code should get you going. It's not tested, i wrote i off the top of my head, so let me know if you have any issues which you are unable to resolve.

    I would suggest, in order to maintain clean code, move a lot of this into some sort of user management cfc then just invoke User.popupStatus()..etc..

    all a matter of taste really.

    -------- Set the following application Variables in your application.cfc ------

    <cfscript>

         //This will save you setting these variables over and over on every request (so long as your application.cfc is written correctly and this is inside onApplicationStart()

         application.loginPopup = structNew();

         //this means weeks, check here for more info on unit info: http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_c-d_28.html

         application.loginPopup.repeatUnit = "ww";

         application.loginPopup.repeatFrequency = 2; //2 of Unit

    </cfscript>

    -------- Insert this where ever you want the popup in your post-login page -----

    <!--- Replace with what ever your login detection code is etc --->

    <cfif IsLoggedIn()>

         <!--- Consider moving this to User.cfc (or DAO of sorts) -> getLastPopupDate( Number userId ); --->

         <cfquery name="userCheck" datasource="dsn">

              SELECT lastPopupDate

              FROM tblUser

              WHERE userid = <cfqueryparam cfsqltype="cf_sql_integer" value="#session.userId#" />

         </cfquery>

         <!--- DateDiff documentation here http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_c-d_28.html --->

         <cfif DateDiff( application.loginPopup.repeatUnit, checkUser.lastPopupDate, Now() ) GTE application.loginPopup.repeatFrequency>

              <script type="text/javascript">

                   //Your popup code here

              </script>

              <!--- Change getdate to what ever native date function your DBMS uses, or use a coldfusion param, doesn't really matter --->

              <!--- Consider moving this to User.cfc (or DAO of sorts) -> setLastPopupDate( Number userId, DateTime lastDisplayed = Now() ); --->

              <cfquery datasource="dsn">

                   UPDATE tblUser

                   SET lastPopupDate = getDate()

                   WHERE userid = <cfqueryparam cfsqltype="cf_sql_integer" value="#session.userId#" />

              </cfquery>

         </cfif>

    </cfif>

    Message was edited by: parkerst Adjusted for lack of CfLogin

    1 reply

    Owainnorth
    Inspiring
    December 9, 2011

    Have the site create a cookie on first visit, then wrap the popup JS in a cfif which tests for the cookie.

    adamaas
    adamaasAuthor
    Known Participant
    December 9, 2011

    Thanks for your quick reply.

    Am newbie in coldfusion, could you give me an example how to do it ? I mean in terms of code.

    What iff a person disable cookies on his browser ?

    Is there any other solutions apart from using cookies ?

    Inspiring
    December 13, 2011

    Firstly, setting the cookie.

    <cfcookie name="beenBefore" expires="never" value="true" />

    http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_c_12.html

    This documentation will help you configure your cookie to your liking.

    getting the cookie

    <cfif NOT isDefined('BeenBefore') OR NOT isBoolean(cookie.beenBefore) OR NOT cookie.beenBefore>

         <script> /* Put your popup code here */ </script>

    </cfif>

    Now as for other options, the only one I can think of off the top of my head is to log the IP address of all visitors into your database and show a popup if the IP is new.