Uutiset:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu
Advertisement:

Post registration hook

Aloittaja huns, elokuu 04, 2013, 07:10:33 AP

« edellinen - seuraava »

huns

I want to check if an email exists, before even letting him register.
Where am I supposed to do this ? (I'm not familiar with the code of SMF, but I can code PHP.)

(I'll put this into a mod, but don't worry about that for now.)

So. When he presses the Registration button, there is a function/php file I want to run.
Where do I insert this in the code? (So he shouldn't even proceed, unless the code returns OK.)


ps.: How the heck do you solve the CAPTCHA here? I had to request at least 30 images before I found one readable. lol

Chalky

That's what the "email activation" is for on registration.  New registrants only show as members "awaiting activation" rather than appearing on the memberlist and cannot log in until they have received the automatically generated email to the address they gave and clicked on the activation link that appears in the email.  Why would you need to insert your own script to do that?

CAPTCHA is horrible but it's the only defence we can use here with all the different languages we support.  It goes away after 10 posts  :)

huns

#2
I'm aware of that function, but that makes the SMTP server send out thousands of mails to unknown emails.
I want to implement this:
http://code.google.com/p/php-smtp-email-validation/

The code itself is ridiculously simple, but I don't know where could I insert it into SMF's registration code.

ps.:
   So the workflow looks like this
   1) Insert new code using the linked library (php) into register.php
   2) Run the validation on user's mail
       (maybe we could store this down, or call the function with the $row[''] code)
       sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);)
   3) Wait until SMTP response and die if it's non-existent.

Btw this could be a core function.

emanuele

You can do it somewhere in Register2 (Register.php).
Then depending on the effect you want to obtain you can either use a fatal_lang_error or add something to the $reg_errors array.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

huns

I'm a bit busy with my work at the moment, but I'll start working on the project soon. (In a few days at most.)
I'll report back here if I managed to get the work done. (And of course, publish the extension / make a topic to ask for opinions about it.)

huns

If I call the fatal_lang_error function:
- It will display an error message, I suppose.
- Will it also "die"? As in... stop the user from registering?

Yeah, I know. I'm not familiar with these parts of SMF.

Arantor

Yes... if you call fatal_lang_error it will end execution having displayed the error indicated.

Specifically, fatal_lang_error('something'); will try and use $txt['something'] (global variable) as the error message when it closes down execution.
Holder of controversial views, all of which my own.


huns

Yeah I managed to look up the strings in the Language file.

One other thing: What do you suggest?
- Should I include the script itself into Register.php (not that long),
- Or should I add it as a new file and call it from there?

(I'll need to include a new language file anyway. If I'm doing this, I want to make it into a proper mod that I will upload to the mod db as I mentioned first.)

Arantor

If it's not a lot of code, you could just include it into Register.php.
Holder of controversial views, all of which my own.


huns

The code is inserted, and the package installs, but I get the following error:

Parse error: syntax error, unexpected '$bIsEmailValid' (T_VARIABLE), expecting '(' in \Sources\Register.php on line 455

The source is here:
$bIsEmailValid = jValidateEmailUsingSMTP($_POST['email'], "server.hosting.com", "[email protected]");
if $bIsEmailValid {
echo '';
} else {
fatal_lang_error('checkmail_notexists', false);
}


How do I make this into 'expected'?
Ps.: I used a tenary operator first but I didn't want any trouble during I debug this problem. (I'm not a PHP expert as you may have already noticed that.) I tried shuffling around the function and variable too, but it didn't help.


Addendum:
The code could be a one liner (either with the tenary) or using "!". Doing 'echo '' basically is nothing.
It is not final. I still have to integrate the language and the other variables.

Arantor

Well... using proper PHP syntax would help... and not creating an extra branch would be better too.

$bIsEmailValid = jValidateEmailUsingSMTP($_POST['email'], "server.hosting.com", "[email protected]");
if (!$bIsEmailValid)
fatal_lang_error('checkmail_notexists', false);


You could technically make a ternary out of it, because of the way PHP handles things but it's best practice not to make unnecessary branches.

Since you're doing nothing if something is true and something if something is false, just test for the something is false.
Holder of controversial views, all of which my own.


huns

Thanks Arantor. There was a silly error in the code as I tried to make it more simple (doh!).
Now it works properly.... (read on)

Well guys, end of story.
The e-mail check code is not reliable for use in live environment, so I strongly discourage from anyone using it.

However,
I'll modify the plugin per se, to make it a reliable extra line of defense.
There are some neat tricks which can help checking the mail, and I'll implement those in the plugin.

Finally, thanks for the replies! I have been able to create a proper, fully functioning plugin, with your help. I will post the code on a Bitbucket/Github repo, so you can all have a look at it before I make it into a pack/submit it.

And heck, even if the plugin will do no wonders, now I can make wonders.
Besides, knowing the forum you run is never a disadvantage.


ps.: grrr, this verification drives me mad. :)

Advertisement: