vincent15000's avatar

What's the best way to send a unique usage code ?

Hello,

The context is the following : a group owner invites another user to join the group and sends this user a code. So when the user connects, he has just to enter the code to join the group.

I need to generate a unique code associated to a unique user and a unique group and this code can be used only once. The question is : where do I store this code ?

I thought about creating another table (group_id, user_id, code) specifically to manage this code and the line will be removed from the database when the user has used the code.

Another way could be to generate a temporary link so that the user can click on this link directly from the email, but would this say that the user is automatically connected by clicking on the link ? For this type of application, I prefer not, I really want that each user manually log in.

Is there a better way to do what I need ?

Thanks for your help.

V

0 likes
5 replies
Sinnbeck's avatar

I would personally create a table for this. I would perhaps also add expires_at, and deleted_at columns, to track when it expires (if that is a thing of course) and when it was used/deleted.

1 like
vincent15000's avatar

@Sinnbeck Thank you ... yes I thought about the expiration date and other useful fields like this one. I have to define precisely what I need more.

click's avatar
click
Best Answer
Level 35

You are actually describing an invitation system. A unique link would be OK and to prevent people are automatically joining the team you can create a landing page for the link that describes the invitation:

You are invited to join Team X by John Doe. 

[ Join Team ] 

The moment they click the button they are added to the team.

You can create (and expire) the link with Laravel's signed urls: https://laravel.com/docs/9.x/urls#signed-urls or you can keep track of it with a special database table.

1 like
vincent15000's avatar

@click Ok thank you ... yes it's an invitation system. Is it possible to have both the signed URL and keep track of the invitation in a database table ?

Please or to participate in this conversation.