Quiz with countdown enabled upon opening - mysql

How can I implement an online application which sends emails to selected users. The email contains a link which is available for 3 days after the email was sent. If the user clicks the link before it expires, then they will open a new browser window/tab with the user specific questions and a countdown timer that begins on window load. Starting from that moment, with no pause permitted, they have exactly 1 hour to answer the questions.
The quiz will be submitted by user or automatically with all the answers after the timer reaches 60 minutes.
The user can see the time remaining (updating real time somewhere in the UI).
If possible I would like to implement it in a way that if user accidentally closes the tab, he can open it again with all the answers saved.
We are currently working with Java/Spring Boot(REST API - backend), ReactJS(frontend) + MySQL database.
We do not know exactly how we should search the keywords needed for that email-link-expiration logic. The login method, creation of the quiz and the sending of it to a user along with the database structure is clear for us.
We appreciate any help or implementation ideas (or even technologies)

The ideea was to generate each quizz with a specific random token, like this:
04e69b43-f6e2-4a6b-835b-dd58c95e41810
Then, send the email to the specific person myapp.com/quizz?token=token.
A CRON job in backend will check the creation date of the quizz and check if 3 days have passed without being assessed for the first time and mark the quizz as expired if so(of course, when the link will be assessed and the quizz is expired, an error message will be displayed).
If the quizz is not expired and user clicks, automatically start the quiz and save in the database firstClickTime and expirationTime = firstClick + 1h.The frontend will send each minute a JSON with everything he has written so far to prevent any lost answers if he closes the tab.
Of course there are also some other small details, but this is the whole idea.

Related

Firebase event is not showing in Event tab

I have created a event on my Firebase dashboard
and can see it in Debug View
But I cannot see it in Events Tab, it's not there and I cannot mark it as a conversation event, as I need to set it.
Creating one from conversations tab does not specify app platform, which I need it to be for my iOS app.
How do I fix this issue?
There's an intended delay before the data shows up in the Events page. The initial data logged usually takes up to 24 hours to display and 3-4 hours delay for the succeeding data. DebugView on the other hand, shows you data (from events, event parameters, and user properties) as Analytics collects the data. This is used to help you set up data collection, troubleshoot issues as issues arise, and understand a user's behavior as the user explores your website or app. For additional information about the delay in Analytics reporting, you can refer to this blog post.

How to reload gmail add-on through background process using app-script

May i get some help on the below points where i am using app-script to develop a gmail add-on:
How can we refresh gmail add-on with back ground process?
=> Here is my case, I need to display card with multiple sections which is the process of hitting multiple apis to fetch data and to display the card. For this initially we will show a card with minimal information to the user once i get information from api, i need to update the basic cards with complete information.
How can we trigger a function on every mail thread open?
=> Currently it works once for a mail, here as explained above point need to refresh a card once we fetch the data. If not, user will be seeing same basic information card every time he opens the mail.
From above mentioned issues for point one we are trying to get solution where we can hit service for certain interval of time to check data availability and if data exists then fetch data and update cards, i mean to say need a setTimeout function kind of thing, unfortunately we did'nt found this in app script and We found sleep/waitLock functions in app-script, but my services may take little time to fetch data as it connects though multiple services so we cant make the user to wait until the whole process is to be completed. So that we will show a card with basic information required then after need to auto refresh the cards once we fetch the data. we tried of keeping refresh button for the user to click and fetch the updated data but here we are losing user experience, trying for auto refresh with out user interference to get updated information.
Need a process / solution where we can auto refresh the card with out user interference after the data available at our end instead of making user to wait until the process to be completed.
Earliest reply will be more helpful for us.
Thanks.
If a data status on a third-party backend changes as the result of a user interaction with your add-on UI, it is recommended that the add-on set a 'state changed' bit to true so that any existing client side cache is cleared. See the ActionResponseBuilder.setStateChanged() method description for additional details.
The card-based interface in Gmail Addons is an Apps Script Service.
You can interlink it with other Apps Script services as well as implement API calls - everything within the same Apps Script file.
Gmail Addons contents automatically update every time the user opens a different e-mail or refreshes his browser.
Within your Apps Script code you can install time-driven triggers to run the data availability check with a customized frequency.
Consider to install for your users an Auto Refresh extension if you do not want them to refresh the card themselves.

How to set my url only available for a period of time? React

I am working on my react project and I need one page of my website only available for like 5 minutes.
For an instance, I will send user an email which contain an url, user can visited the webpage by clicking url. However, after a certain period of time (like 5 minute), user cannot access the webpage by clicking url anymore (which means the url is useless.)
How should I create such webpage with url in my React project?
You're going to want to do this on your server. Say you have a route that looks like this, /verification/:id and you send an email to the user with a link routing them to https://my-site/verification/cd5d00c4-ff6c-11e8-8eb2-f2801f1b9fd1. When the email is sent you can store that string, cd5d00c4-ff6c-11e8-8eb2-f2801f1b9fd1 in your database and set a timer to remove it from the database after a specified amount of time if it's still there. When someone navigates to /verification/:id you take the id and see if it exists in your database. If it does, let them verify and then remove it from the database.

How does Facebook detect when a user receives a new message & make changes to the html?

I'm new to AJAX and PHP but I know that PHP is a server-side scripting language and so there will not be any changes to the html unless the user refreshes the page or the user submits a form. Therefore I suppose the change of the number in <span id="mercurymessagesCountValue"> when a facebook user receives a message
is AJAX-related.
And this is my guess:
The change of the number is triggered when it is detected that another user [the sender] has inserted a new row into a particular table and each column contains different data: the time, the message, the sender id and the receiver id.
So here's my question... In this case, how is the changes in the database detected and how does it trigger a javscript [or something else] to make changes to the html? Or if I'm wrong... can I know how Facebook does that? Thanks very much!!
If I got the question right, you should check out about pull and push models. Facebook works under the push model: facebook server knows when new message is received and it pushes the notification to the client (website open in the browser).
Let me clear a few things up for you here,
AJAX is simply a type of request being sent by the browser to go grab data from another page dynamically. In facebook's case, they actually have a special type of connection to the client computer to keep the page 'alive'. This way, they can push dynamic updates to the client without the need to constantly poll/refresh a single page on the server (would make large amounts of load).
So, let's just pretend, they are constantly refreshing the page on the server to determine how many notifications are unread -
Client -> Ajax Call -> Server PHP Page -> Ajax Return -> Client
So, in order, the client sends a request for the page to be generated by the server.
The server's php page will then count the number of 'unread' notification rows in the database for that particular user. It will then output the number of unread rows in plain html.
The client then recieves this plain HTML from the Ajax call, and simply updates the DOM with the new number of unread notifications
PLEASE NOTE: This is not how facebook works, but it's a good example of how to set up your own basic notification system if you are new to dynamic coding.
My guess is that requests are sent frequently from the client via Javascript, to the host, asking "has anything new happend since last time i asked?". The answer is responded by the server, with PHP, if it is yes, the new data is delivered in the respond and JavaScript updates the DOM (HTML) with the new data, like showing the red flag or something.
javascript:location.load(t);
(t=time interval)
i guess ,, refreshing a page in every several seconds will pop up the notifications recieved..!!

Facebook connect database transaction help

I am trying to implement a simple login system with facebook, but I need users to pick a username. What I was thinking was to get all the information I need from facebook, request permissions, then add the information to the database, redirect to a form asking for a username and then add that to the database, to the same entry.
I think a transaction is needed so I don't end up with any half completed database entries. But I've only ever used them on the same page, so I'm wondering if this is safe? If it fails then there is no point where I would be telling the database to roll back the changes and it would be with a transaction open.
Is this right or will it be ok?
I think you made it more complicated than it should be :)
No need to enter facebook id into database before username as you can always grab it later.
Forward user to login screen (or better just open login popup using javascript FB API)
Once user is logged in forward them to username picking page (or better do javascript popup without page redirect)
When user is entered username request the current user id from facebook on server side (by either using graph api or fql) and then if everything is ok enter this record to database.