News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Registration. Member name regex and creaton of a new database?

Started by Osvaldon, September 03, 2016, 03:40:42 PM

Previous topic - Next topic

Osvaldon

SMF 2.0.11

Registration
1) I want names to match a name format. Where should I place a regex check (which line or lines?) and how do I give users a warning if their name doesn't match the format?
2) Data of members is saved on smf_members table of the database. How do I make the website save parts of the same data on another table or database? I want to use that data elsewhere, but I only need the name, password hash, email etc., I don't need that other information that is forum related.

Osvaldon

I just can't find anything on the php files, there are too many. Someone just please direct me to the right files and perhaps lines if possible.

vbgamer45

Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Kindred

In answer to number 2...   Check the hooks for registration
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

margarett

In any case I would start by hacking Sources/Register.php, then proceed to using hooks when you're feeling comfortable.
1)
Find
foreach ($_POST as $key => $value)
{
if (!is_array($_POST[$key]))
$_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key]));
}

Add after
// Do your regex magic here with $_POST['real_name']
if (regex result is not in the pattern you want) // PSEUDO CODE OK????
$reg_errors[] = 'The username doesn\'t match the required pattern';

That will automatically do the rest for you. For proper coding, the error string should come from $txt and from a language file, but it will do the trick for a first approach.

2)
Find
// Do our spam protection now.
spamProtection('register');

If the code execution gets here, then the member is registered. You either edit Subs-Members.php where all the data is actually written, or you just do it here, all data is available anyway.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Osvaldon

Quote from: margarett on September 06, 2016, 05:48:00 AM

if (preg_match('~^[A-Z][a-z]*_[A-Z][a-z]*$~', $_POST['real_name']) === 0)
{
$test = ' Test String ';
$reg_errors[] = $_POST['real_name'] . $test . 'The username doesn\'t match the required pattern of Name_Surname. Your name and surname should begin with a capital letter and have _ between them.';
}


I've tried this, but $_POST['real_name'] is an empty string for some reason.

And I get the impression that there's no need to specify a table name. Does the program look through each table on the entire database until it finds the correct column and row?

Kindred

Quote from: Osvaldon on September 06, 2016, 12:07:06 PM
And I get the impression that there's no need to specify a table name. Does the program look through each table on the entire database until it finds the correct column and row?

oh, no... you absolutely must specify the table and the column(s) in order to retrieve/insert the correct row
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Osvaldon

Quote from: Kindred on September 06, 2016, 02:17:50 PM
oh, no... you absolutely must specify the table and the column(s) in order to retrieve/insert the correct row

My bad, I was looking for table names with the prefix, when in the code it was {db_prefix}tableName, now it's starting to make more sense to me :D

FROM {db_prefix}members

Osvaldon

Quote from: Osvaldon on September 06, 2016, 12:07:06 PM
if (preg_match('~^[A-Z][a-z]+*_[A-Z][a-z]+$~', $_POST['real_name']) === 0)
{
$test = ' Test String ';
$reg_errors[] = $_POST['real_name'] . $test . 'The username doesn\'t match the required pattern of Name_Surname. Your name and surname should begin with a capital letter and have _ between them.';
}


I get the error message, but a missing string is causing my check to always fail. Can anyone explain me, why $_POST['real_name'] is an empty string? I've filled the username field. If I change 'real_name' to 'email', I get the email string that I've entered into the email field, but I want to use the username field for the check.

Osvaldon

foreach ($_POST as $key => $value)
{
$reg_errors[] = $_POST[$key] . $key;
if (!is_array($_POST[$key]))
$_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key]));
}


$reg_errors[] = $_POST[$key] . $key;
Ok, I put that line there and what I actually needed was 'user', not 'real_name'. So I guess it's solved now.

Advertisement: