Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Pop up functionality upon login

Community Beginner ,
Dec 09, 2011 Dec 09, 2011

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.

2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Dec 12, 2011 Dec 12, 2011

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 reques

...
Translate
Guide ,
Dec 09, 2011 Dec 09, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 09, 2011 Dec 09, 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 ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 12, 2011 Dec 12, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 12, 2011 Dec 12, 2011

Thanks parkest for the tutorial and your answer.

Well if a person disable his cookies or each time he close his browser and clear its cookies, the pop up will appear again next time he logins.

Actually, a pop up will appear on his first login after 2 weeks. If he logins again in this 2 weeks, he should be able to have the pop up only once. So, I think cookies is not appropriate to be used here.

I am thinking of using a UUID and put conditions on it. The problem is that I don't know whether the UUID change each time a user login or not. Can anybody help me and advise me whether or not this is a good solution to my problem ?

Thanks in advance.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 12, 2011 Dec 12, 2011

If you're having the user authenticate before you are displaying the popup then there is a real nobrainer here, deposit the last popup date on the user table as a column then at login, check if that last popup date is x weeks old and display the popup if needed.

Do you need some assistance with the code on that too?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 12, 2011 Dec 12, 2011

Ok.

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

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 12, 2011 Dec 12, 2011

what sort of authentication are you using? cflogin or are you writing your own?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 12, 2011 Dec 12, 2011

No cflogin. Authentication was developed by my colleague and it's one of his own.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 12, 2011 Dec 12, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 12, 2011 Dec 12, 2011

Ok thanks.

I'll try it and let u know if it's good or not.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 14, 2011 Dec 14, 2011
LATEST

It's good thank u....

Actually I had not taken all ur sample code but only part of it and apply some logic, then it works.

Thank you very much for ur help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources