SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 12/06/2018, 01:01 PM   #1
bruxo00
High-roller
 
bruxo00's Avatar
 
Join Date: Oct 2012
Location: Portugal
Posts: 1,088
Reputation: 138
Default How to create a email confirmation system

INTRODUCTION

In this tutorial I will teach you how to create a simple email confirmation system. It will send an email to the player with a code, and he needs to enter that code in the sever in order to play. It is really simple.

You will need first to download SAMPMailJS include HERE.

After you setup the include correctly, let's jump to the tutorial. Note that there are several ways of doing this. The way I'm doing this for the tutorial will be:

- Player registers and enters a valid email
- The server will send an email to the player with a code
- The player can play the first time without confirming the email (you can create a command to do this aswell)
- The second time the player joins the server, it will ask for the code
- If he enters the code correctly, it will confirm the email and let him play, otherwise it will kick him, or anything you want. You can choose not to kick him, but instead block some of the server functionalities for unconfirmed players. It's up to you really.

TUTORIAL

Create 3 new variables on your player enum (normally): (in this case the code will be an integer, you can use a string if you want)

Code:
Email[32],
ConfCode,
Confirmed
At the registration time, you will generate a new confirmation code, like this:

Code:
stock RandomEx(min, max) // Y_Less | returns a int between min and max
{
    new rand = random(max - min) + min;
    return rand;
}


// Put this in your registration system, when the player enters his email

Player[playerid][ConfCode] = RandomEx(1000, 9999); // code will be between 1000 and 9999
Player[playerid][Confirmed] = 0; // player is not confirmed
This code will generate a confirmation code between 1000 and 9999. You can choose to be a bigger or smaller number, it is up to you.

Now let's create the script that will send the email. I will assume you already have SAMPMailJS set up with the last version. That already comes with a confirmation code email template, that we will use here. You can create your own or edit the existing one.

Create a function that sends the email, and call it after you generate the confirmation code:

Code:
forward SendConfirmationEmail(playerid);
public SendConfirmationEmail(playerid)
{
	new text[64], pName[MAX_PLAYER_NAME];

	GetPlayerName(playerid, pName, sizeof pName);

	format(text, sizeof text, "PNAME:%s#CONFCODE:%d", pName, Player[playerid][ConfCode]); // formats the string with the code standard that SAMPMailJS accepts. tag1:value1#tag2:value2

	SendEmail("My Server Name", Player[playerid][Email], "[SERVER NAME] Confirm your email", text, true, "confcode.html");

	return 1;
}
Now the code to show the dialog to enter the confirmation code. It will appear when the player logins to the server, or if you want create a command to show it:

Code:
#define		DIALOG_CONFIRM		500 // define a dialog ID

// After the player logins

	if(Player[playerid][Confirmed] == 0) {
		return ShowPlayerDialog(playerid, DIALOG_CONFIRM, DIALOG_STYLE_INPUT, "CONFIRM YOUR EMAIL", "Email not confirmed. Enter the confirmation code sent to your email.", "Confirm", "Cancel");
	}
	
	
	
// OnDialogResponse(...)

        case DIALOG_CONFIRM: {
            if(!response) return Kick(playerid);

            if(Player[playerid][ConfCode] == strval(inputtext)) { // if the code and the inputtext are the same
                SendClientMessage(playerid, -1, "You confirmed your email!");
				Player[playerid][Confirmed] = 1; // player confirmed
            }
            else { // otherwise
                Kick(playerid); // kicks the player
            }
        }
And it's done. It is that simple.

Email recieved:



I didn't compiled the code, it may have some syntax errors. If it does, tell me and I will fix it.
bruxo00 is offline   Reply With Quote
Old 13/06/2018, 01:15 AM   #2
BrGabrielBr
Huge Clucker
 
BrGabrielBr's Avatar
 
Join Date: Jul 2016
Location: Rio De Janeiro
Posts: 467
Reputation: 5
Default Re: How to create a email confirmation system

Fico dahora mano!
__________________
BrGabrielBr is offline   Reply With Quote
Old 13/06/2018, 09:29 AM   #3
Ahmadd
Big Clucker
 
Join Date: May 2018
Posts: 48
Reputation: 0
Default Re: How to create a email confirmation system

Thanks ^^
Ahmadd is offline   Reply With Quote
Old 13/06/2018, 12:45 PM   #4
DarkMythHunter
Big Clucker
 
Join Date: May 2017
Location: Philippines
Posts: 84
Reputation: 24
Default Re: How to create a email confirmation system

Ah finally.
DarkMythHunter is offline   Reply With Quote
Old 17/06/2018, 01:46 PM   #5
MustafaKemalAtaturk
Little Clucker
 
MustafaKemalAtaturk's Avatar
 
Join Date: Mar 2015
Location: Turkey
Posts: 14
Reputation: 0
Default Re: How to create a email confirmation system

Is NodeJS so necessary? Idk is it installed on my server and i dont have perm for that
MustafaKemalAtaturk is offline   Reply With Quote
Old 17/06/2018, 02:12 PM   #6
bruxo00
High-roller
 
bruxo00's Avatar
 
Join Date: Oct 2012
Location: Portugal
Posts: 1,088
Reputation: 138
Default Re: How to create a email confirmation system

Quote:
Originally Posted by MustafaKemalAtaturk View Post
Is NodeJS so necessary? Idk is it installed on my server and i dont have perm for that
You don't necessarily need to use the include that I use in the tutorial, you can use any other email include, but you will need to adapt your code to that new include.
bruxo00 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Confirmation email. ZeQualX Scripting Help 1 07/02/2014 05:14 AM
[Tutorial] How to create a better looking email for your server Frede Tutorials 1 09/04/2013 10:24 PM
[Suggestion] Server Advertisements confirmation system Biesmen General 18 06/12/2011 01:09 AM
email system jasonnw666 Help Archive 5 04/01/2010 06:50 PM
how do i create my own Email address provider? Mowgli Everything and Nothing 12 21/10/2009 05:52 PM


All times are GMT. The time now is 05:31 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.