Restricting use for 5 minutes - java

I am planning on creating a small website with JavaEE where a user can vote but only every 5 minutes. There are two buttons. One to vote yes and the other to vote no. I want the buttons to only be clickable every 5 minutes. Whats the best way to do this?
I thought of getting the users IP and entering it into my DB along with the timestamp. Everytime a user would vote I would get their IP from the DB and check if 5 mins have passed since their last vote. What do you think of this solution? Is this best practise?
I am trying to avoid a login or any other sort of authentication.
I plan on using JSF, Java, mySQL and AJAX.

One possible solution could be a cookie containing the last date of vote in client side plus saving the user IP and date of vote in a datatabse in server side.
If there is no cookie in client side and if there is zero entry in your database containing the user's IP address, or if the date stored in this enty is inferior to your vote recover time, then the user can vote.
Keep in mind that the more people will click your buttons, the more request your server will have to handle.
There is no risk zero, but you can get close to it.

Related

Is it possible with "org.eclipse.paho.client.mqttv3-1.2.0" Library in Java to get more than one MQTT message at a time?

I'm new here at Stackoverflow and have a question.
I want to create an IoT weather station with a ESP8266 that has two sensors (humidity, temperature) and send the data to a broker (Mosquitto) running on a Pi. Beside the easy way to fetch and visualize the data with nodered I want to program a desktop app in Java.
I use the "org.eclipse.paho.client.mqttv3-1.2.0" package to create a client and fetch the messages. With one topic (e.g. "/test/temperature") it's easily possible to receive the temperature values. But if I add a second client for humidity, it's not possible to receive the two at the same time. When two clients are implemented just the later called client gets its values.
I solved the problem by sending the values from the ESP8266 with a little time shift. But is there a way to fetch to messages at the same time? I thought about Threads but it's not working.
Has anyone had already the same problem or got an idea?
Thanks in advance and don't hesitate to ask further questions.
Cheers.
Robin
First off, you need to rethink your topic structure. Don't be so restrictive. Hand out topics like houses hand out candy on Halloween. :)
i.e.
robin/weather/ESP8266/temperature
robin/weather/ESP8266/humidity
A state machine can be almost anything. i.e. Hashtable, database, etc.. If you want to keep historical data then I would go with a database. i.e. SQLite, Derby, H2, etc. I use the “sqlite-jdbc” driver from Taro L. Saito. The JDBC driver works extremely well and he keeps the code in sync with the SQLite code base.
A basic database would have 2 tables: Temperature and Humidity. Have the client subscribe to both topics and when a message arrives, update the appropriate table with the incoming value and the current date and time.
If you want, you could create a 3rd table (i.e. 'Recent') and it would only ever have 2 rows (one for the current temperature and one for the current humidity) in the table that are constantly replaced.
No, messages are not fetched from a broker, they pushed by the broker. The broker will push messages as they arrive and they will always be one at once, this is just how MQTT works.
The way to do this is to maintain a state machine that holds the last value for each sensor and use these values to update the output when ever one value changes.

android, Everyone should evaluate each day only once

I'm going to build an app. Until now everything runs very well. Now I have a problem. The app gets its content from a mysql database.A column is called item.I have a ratingbar. The user can rate the item there.Every time the user evaluates an item the value is stored on the database in the respective item line.The values ​​are then added. In other words, when a user evaluates 20 times with 5 stars, the value adds up to 100 and so on.
I want to limit this. I will that the user can evaluate each day only once an item. I will it without a registration mask for the user. How can I solve this problem?
I know that i can identifier the WIFI MAC Adreess and other Unique Identifiers, but how can i solve this with them?
I can not use sqlite database, because the items should update with the time from the mysql database.
A registration mask should not be excluded. If this process is quite possible with them, then I supplement it with it.
I am looking forward to every comment
every computer has a machine ID, you will hash that and encrypt that to use as your identifier..most telecomms do not like using MAc addresses as IDs
One option would be to create UUID during every installation and sending this UUID to your server along with every request. In server, you can control very well if user can provide feedback once a day or others based on your requirement. Pls refer this link on how to create UUID.
https://developer.android.com/reference/java/util/UUID.html

Spring scheduling on a set of dates

I'm building an auction site in Spring and Postgres where the user can list his product and other user can bid and buy (like ebay).
What I want to do is when some auction ends the system send and email to the user saying to check the page and pay. These dates are stored in the auction table and can be any date (the end date is the starting date + 30 days).
Someone knows how can I send an email on this dates (the best way to do without overload the system!)?
thanks
You can execute some job on some interval, lets say every day. In this job you query the table from the database and chek if you have to send mails for some auction.
I don't know if is the most correct way, but I follow https://stackoverflow.com/a/18896316/3237975 and everything worked as I wanted.
I just change a little bit the class CustomTask to accept an input date and done!!
Thanks for the help
(if this approach is not the best performance wise, please advice other better)

What's the best way to secure userID when sending reset-password-link

I created a servlet that checks for userID in LDAP and if it is there, it sends email to that
user with link:
"Please follow this link to reset your password" ;
I was told that this is not a good practice and that I should create table in MySQl with userID, timeResetRequested, GUID fields.
And pass this GUID in email instead of userID.
And to delete that record after 2 hours.
Is there a better and cleaner way to accomplish this and still have it secure?
Yes, that is a much better way.
The question about whether to send a GUID or user id doesn't matter AS much as the reset time out however.
Imagine that you reset your password one day, and then 2 months later you sell your account. You could then recover your account by resetting your password on a 2 month old email. You would not need to know the new account password to reset it, but rather just simply log in to your email and hack back your account.
Now, despite saying that the reset timer is more important than the guid/user id, you must think, do you want your users knowing their user id? If you don't, a GUID is a nice way to mask it.

Expiry Notification at Intervals -- How do I avoid repeated notices for the same entry?

I am implementing a J2EE application that has an expiry-style license, and I would like to send e-mail notification to different customers as the customer's license approaches expiry. I'd like to be able to do something like notify at, for example, 90/60/30 days until expiry, but obviously I don't want to accidentally send repeated notices if the query for licenses nearing expiry results in the same set.
The only way I can think of is to have something stored alongside the license key to indicate the last notification date (or the next notification date).
i.e. Company A, license string, expiry: 2010-09-16, next notification: 2010-08-30
Is there a better way to do this that I'm not thinking of?
I'd like to come up with a more generic way of scheduling time-based events (30 days until X happens) for other elements as well, so if I can avoid adding a 'next notification time' to a couple tables in the database, I'd opt for that.
I can use Quartz, if that'd help. I've used it before, but only with the RamJobStore, so nothing was persisted between restarts.
If you are going to send notification exactly at 90/60/30 days until expiry date, how it is going to be repeated notices?
Are you doing notification within app like popup during app startup or as a separate remote process that sends like email notification? If it is within app, you can always simple checks during app startup

Categories

Resources