Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to prevent registration spam #250

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
'RequireEmailConfirm' => false, // Require e-mail confirmation during registration.
'RequireChangeConfirm' => false, // Require confirmation when changing e-mail addresses.
'EmailConfirmExpire' => 48, // E-mail confirmations expire hours. Unconfirmed accounts will expire after this period of time.
'PendingRegistration' => false, // Requires 'RequireEmailConfirm' to be true. Prevents new registration if ip address has a pending registration on selected mail.
'PincodeEnabled' => true, // Whether or not the pincode system is enabled in your server. (Check your char_athena.conf file. Enabled by default.)
'MailerFromAddress' => 'noreply@localhost', // The e-mail address displayed in the From field.
'MailerFromName' => 'MailerName', // The name displayed with the From e-mail address.
Expand Down
1 change: 1 addition & 0 deletions lang/en_us.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
'InvalidSecurityCode' => 'Please enter the security code correctly.',
'InvalidPassword' => 'Your password contains invalid characters.',
'InvalidBirthdate' => 'Invalid birthdate input.',
'PendingRegistration' => 'You already have a pending registration. Please check your mails and follow the confirmation process.',
'CriticalRegisterError' => 'Something bad happened. Report to an administrator ASAP.',
// - account/edit
'AccountEditTitle' => 'Modify Account',
Expand Down
15 changes: 13 additions & 2 deletions lib/Flux/LoginServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,25 @@ public function register($username, $password, $confirmPassword, $email,$email2,
throw new Flux_RegisterError('E-mail address is already in use', Flux_RegisterError::EMAIL_ADDRESS_IN_USE);
}
}

if (Flux::config('RequireEmailConfirm') && Flux::config('PendingRegistration')) {
$sql = "SELECT state FROM {$this->loginDatabase}.login WHERE last_ip = ? And state = 5 LIMIT 1";
$sth = $this->connection->getStatement($sql);
$sth->execute(array($_SERVER['REMOTE_ADDR']));

$res = $sth->fetch();
if ($res) {
throw new Flux_RegisterError('Detected pending registration. A new registration has been prevented.', Flux_RegisterError::PENDING_REGISTRATION);
}
}

if ($this->config->getUseMD5()) {
$password = Flux::hashPassword($password);
}

$sql = "INSERT INTO {$this->loginDatabase}.login (userid, user_pass, email, sex, group_id, birthdate) VALUES (?, ?, ?, ?, ?, ?)";
$sql = "INSERT INTO {$this->loginDatabase}.login (userid, user_pass, email, sex, group_id, birthdate, last_ip) VALUES (?, ?, ?, ?, ?, ?, ?)";
$sth = $this->connection->getStatement($sql);
$res = $sth->execute(array($username, $password, $email, $gender, (int)$this->config->getGroupID(), date('Y-m-d', $birthdatestamp)));
$res = $sth->execute(array($username, $password, $email, $gender, (int)$this->config->getGroupID(), date('Y-m-d', $birthdatestamp), $_SERVER['REMOTE_ADDR']));

if ($res) {
$idsth = $this->connection->getStatement("SELECT LAST_INSERT_ID() AS account_id");
Expand Down
1 change: 1 addition & 0 deletions lib/Flux/RegisterError.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ class Flux_RegisterError extends Flux_Error {
const INVALID_PASSWORD = 18;
const INVALID_BIRTHDATE = 19;
const INVALID_EMAIL_CONF = 20;
const PENDING_REGISTRATION = 21;
}
?>
3 changes: 3 additions & 0 deletions modules/account/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@
case Flux_RegisterError::INVALID_BIRTHDATE:
$errorMessage = Flux::message('InvalidBirthdate');
break;
case Flux_RegisterError::PENDING_REGISTRATION:
$errorMessage = Flux::message('PendingRegistration');
break;
default:
$errorMessage = Flux::message('CriticalRegisterError');
break;
Expand Down
Loading