Achievement/Badge System - node.js

I'm currently working on a website and I have used PostgreSQL, Express and Node.js technologies to make it.
I want to make an achievement system that is event based. E.g. a user makes a new post and is awarded an achievement/badge for making the first post. I was wondering what the code logic behind this would be? How do I award the user when first post is made? And the next time when user makes a new post again (second post) check if the user already has the achievement/badge for making the first post and just continue without awarding the achievement/badge again?
My database tables
The badges table looks like this:
id name description icon created_at updated_at
user_badges table
user_id
badge_id
created_at
updated_at
users table
id name etc...
Any help would be much appreciated.

You shoould have one user table that will store user data and with that you should have an column like totalQaAsked or badgeGiven like this
user's table
username, userFullName, userLoggedIN, totalQaAsked, badgeGiven
At the first time totalQaAsked would be 0 so badgeGiven would be false when user ask his first question then you should have one table that will track question asked by the user and check weather this the first question asked by the user then it will update user's table with totalQaAsked+1 and badgeGiven=true. now you'll have user's data every time you proceed then you can check easily.
Question's table
username, question, some more columns
2nd Method
You can directly query from question with user's id and check how many question asked by the user then you can give badge according to it.

Related

How to protect hidden input to be changed by the user

I'm developing an online store website which has several products and user can submit comment for each single product.
So when the user opens a product webpage, they can submit their comments via comment form. In order to do that I've put a hidden input in the comment form which holds the id of the product however, it can be easily manipulated.
I've search a lot and I know that you can never trust data sent by the clients but I suppose there must be a way to make sure that the comment sent is exactly for the product the user is seeing right now. Because user can see a product on the website and change the product id in the hidden input of the comment form and submit it to the server.
Please help.
Thanks in advance.

How can we know ID of the document on client side

I have recently learned tutorial about restful APIs.In that, my instructor suggested me that if we want to delete any document we should pass id in the parameter of the request. But now I am confused How do we handle this implementation on the client side.I mean how can even the programmer on the front side could be aware of that particular document ID. Does he need to go to the database each time?
Common practice for accessing a record in db is to use its unique identifier, to get or update or delete the record.
On the client side (if you mean user interface) when user wants to delete a document, he/she must see the document somewhere in the interface. Suppose a page with a table containing a list of all (for instance) books in the db. On each row, you have book title and author's name and the id of the book document in the db.
So you can use that id to call the delete rest API.
In a nutshell, when you want to delete something you must have got it from db to simply see it, so the id is at your hand.
When you want to delete a some doc from the database you need to get all documents to the front end to see what do we need to do to this data right ?
Imagine any database GUI that u have worked with..
let's say phpmyadmin when using mysqli
in that case you have php mydamin's GUI so that u can clearly see what are the tables and how things persist in the database. you need to see that in order for you to make decision
. Like that you will need to bring at least a portion of that data to the front end for user to see it and choose what portion of data the user want's to make changes or delete.
so when we have a set of data in the front end like a list, if a user select one item from that list the id or the name of that item can be send to the server side and make the task if the user wishes to do
that's why you need an Id or a identification field of that particular data..

JSF - One vote/comment/rating per IP/User/day/session

I have a JSF application where every site visitor (whether it's a registered user or not) can leave multiple comments and rate existing comments (thumbs up/down). I want to limit the comment ratings to one rating per comment per visitor per day. Can you recommend me the best way to do this? Should I try to log the IP address, or the MAC address (if possible), or something else? Should I save the data in my DB or user the cookies (or something else)?
Relevant tables and fields:
article (id, title, body...)
comment (id, article_id, user_id, text...)
user (id, username...)
// This structure can be changed if needed
Thanks!

Issue while inserting the user in liferay

I have created a form which has basic user details and on clinking of the Save button I am inserting the user details in the "USER_" table by calling the UserLocalServiceUtil.addUser(....). Now the user is creating with out any issue. But I am not able to see some form field parameters in UserLocalServiceUtil.addUser(....) method like (Title, Gender and Date Of Birth). Now how can I save this values. Please give me some suggestions that how can I insert the following fields (Title, Gender and Date Of Birth) at the time of user creation.
Liferay uses com.liferay.portal.model.Contact entity to store the contact information.
Use com.liferay.portal.service.ContactLocalServiceUtil.addContact method to create the contact. Significant parametres:
userId - Id of the user that is creating the contact. You can use PortalUtil.getUser method to get the current user from a request.
className - "com.liferay.portal.model.User".
classPK - Id of the new user that the contact is created for.

Two forms on the same page drupal

I have a database of clients. Before entering a new client, I want to make sure that that client is not already in the database. So I want to put a search form at the top of my page to search by client number, and client name. Further down the page, I'll have another form to enter and submit the client's information. Would this be the best way to go about something like this? How would you approach this? i'm using drupal 6.
It is better that when the user is inserting a new customer name, an autocomplete shows the names matching the characters inserted by the user; if the user wrote "Mic", and in the database there is a customer with the name "Michael Greenpeace", the autocomplete will show "Michael Greenpeace", and the user will understand there is already a record for that customer.
Even without the autocomplete (which would help the user to understand if the data for the customer has been already inserted in the database, and continue with the next customer), a user that inserted the name of an existing customer should see the existing data; this would help the user to avoid rewriting data that are already updated (customer information need to be updated, sometimes, and not only inserted).

Resources