summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Habel <mail@exceptionfault.de>2009-10-20 22:23:43 +0200
committerAndreas Habel <mail@exceptionfault.de>2009-10-20 22:23:43 +0200
commit3b28b034f2a6f263c958b84adf87f096e8440155 (patch)
tree1ad9a28a4d65667ca7e04f3bc50220ac524d3c8d
parent6e1d4a6d8b9288356e64674f41209be4f4c2acfe (diff)
downloadwebsite-3b28b034f2a6f263c958b84adf87f096e8440155.tar.gz
website-3b28b034f2a6f263c958b84adf87f096e8440155.tar.bz2
website-3b28b034f2a6f263c958b84adf87f096e8440155.tar.xz
website-3b28b034f2a6f263c958b84adf87f096e8440155.zip
Added ruby script to create accounts and inform via email.
-rwxr-xr-xbin/createaccount.rb75
-rw-r--r--includes/models/account.php14
2 files changed, 88 insertions, 1 deletions
diff --git a/bin/createaccount.rb b/bin/createaccount.rb
new file mode 100755
index 0000000..45a8223
--- /dev/null
+++ b/bin/createaccount.rb
@@ -0,0 +1,75 @@
+#!/usr/bin/ruby
+
+require 'mysql'
+require 'net/smtp'
+
+$smtp_server = 'localhost'
+$mail_from = 'registration@themanaworld.org'
+$mail_from_name = 'The ManaWorld team'
+$mail_subject = 'The Mana World Account registration'
+$mail_body_success = "Your account was created successfully. Have fun playing themanaworld.\n"
+$mail_body_error = "The was something wrong with the creation of your account.\n" +
+ "Error message: "
+$create_script = "/path/to/script"
+
+##############################################################################
+
+returns = [
+ {'message' => "successfully created", 'status' => :SUCCESS, 'final_state' => 1 },
+ {'message' => "Same account already exists", 'status' => :FAILED, 'final_state' => 2 },
+ {'message' => "Email is too short", 'status' => :FAILED, 'final_state' => 2 },
+ {'message' => "Email is too long", 'status' => :FAILED, 'final_state' => 2 },
+ {'message' => "Invalid email", 'status' => :FAILED, 'final_state' => 2 },
+ {'message' => "Account name is too short", 'status' => :FAILED, 'final_state' => 2 },
+ {'message' => "Account name is too long", 'status' => :FAILED, 'final_state' => 2 },
+ {'message' => "Illegal character", 'status' => :FAILED, 'final_state' => 2 },
+ {'message' => "command not found", 'status' => :FAILED, 'final_state' => 2 },
+]
+
+##############################################################################
+
+def send_mail(email, username, status, errm)
+ message = "From: #{$mail_from_name} <#{$mail_from}>\n" +
+ "To: #{username} <#{email}>\n" +
+ "Subject: #{$mail_subject}\n\n"
+
+ if status == :SUCCESS then
+ message << $mail_body_success
+ elsif status == :FAILED then
+ message << $mail_body_error << errm
+ end
+
+ Net::SMTP.start($smtp_server) do |smtp|
+ smtp.send_message(message, $mail_from, email)
+ end
+end
+
+##############################################################################
+
+db = Mysql::new("localhost", "test", "test123", "test")
+db.query("SELECT id, username, password, email, gender
+ FROM tmw_accounts
+ WHERE state = 0").each do |id, username, password, email, g|
+ begin
+ gender = case g.to_i
+ when 1 then "M"
+ when 2 then "F"
+ end
+
+ # insert the right command here
+ retval = `#{$create_script} create #{username} #{gender} #{email} #{password}`
+ # parse the return value
+ returns.each do |retcode|
+ if retval.include? retcode['message'] then
+ send_mail( email, username, retcode['status'], retcode['message'] )
+ db.query("UPDATE tmw_accounts SET STATE = #{retcode['final_state']} WHERE id = #{id}")
+ end
+ end
+ rescue
+ puts "ERROR occured"
+ puts $!
+ db.query("UPDATE tmw_accounts SET STATE = 2 WHERE id = #{id}")
+ end
+end
+db.close
+
diff --git a/includes/models/account.php b/includes/models/account.php
index ea091f5..2d49ff2 100644
--- a/includes/models/account.php
+++ b/includes/models/account.php
@@ -49,9 +49,21 @@ class TMWAccount
if (strlen($this->username) < 4)
$errors[] = "Username is too short";
+ if (strlen($this->username) >= 24)
+ $errors[] = "Username is too long";
+
if (strlen($this->password) < 4)
$errors[] = "Password is too short";
+ if (strlen($this->password) >= 24)
+ $errors[] = "Password is too long";
+
+ if (strlen($this->email) < 4)
+ $errors[] = "EMail is too short";
+
+ if (strlen($this->email) >= 40)
+ $errors[] = "EMail is too long";
+
if (!check_chars($this->username))
$errors[] = 'Username contains invalid characters. ' . BAD_STRING_DESC;
@@ -99,4 +111,4 @@ class TMWAccount
}
}
-?> \ No newline at end of file
+?>