From 4f2219eb7a95d0397fbfde58063643e46ff86eb9 Mon Sep 17 00:00:00 2001 From: Quitta Date: Mon, 2 Sep 2013 04:15:18 +0200 Subject: [PATCH] started working on the module + small addition --HG-- branch : quitta-gsoc-2013 --- .hgignore | 7 +- .../{ => oldmodule}/ryzommanage.info | 0 .../{ => oldmodule}/ryzommanage.install | 0 .../{ => oldmodule}/ryzommanage.module | 0 .../drupal_module/ryzommanage/config.php | 90 ++ .../ryzommanage/ryzommanage.info | 10 + .../ryzommanage/ryzommanage.install | 31 + .../ryzommanage/ryzommanage.module | 949 ++++++++++++++++++ .../templates/ingame_register.phtml | 116 +++ code/ryzom/tools/server/ryzom_ams/howto.txt | 7 + .../tools/server/ryzom_ams/www/config.php | 2 +- .../ryzom_ams/www/html/inc/register.php | 7 + .../ryzom_ams/www/html/templates/register.tpl | 2 +- 13 files changed, 1216 insertions(+), 5 deletions(-) rename code/ryzom/tools/server/ryzom_ams/drupal_module/{ => oldmodule}/ryzommanage.info (100%) rename code/ryzom/tools/server/ryzom_ams/drupal_module/{ => oldmodule}/ryzommanage.install (100%) rename code/ryzom/tools/server/ryzom_ams/drupal_module/{ => oldmodule}/ryzommanage.module (100%) create mode 100644 code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/config.php create mode 100644 code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ryzommanage.info create mode 100644 code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ryzommanage.install create mode 100644 code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ryzommanage.module create mode 100644 code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/templates/ingame_register.phtml create mode 100644 code/ryzom/tools/server/ryzom_ams/howto.txt create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/inc/register.php diff --git a/.hgignore b/.hgignore index 9fb922bbb..5b6bebb35 100644 --- a/.hgignore +++ b/.hgignore @@ -199,7 +199,8 @@ code/nel/tools/pacs/build_rbank/build_rbank code/ryzom/common/data_leveldesign/leveldesign/game_element/xp_table/skills.skill_tree code/ryzom/common/data_leveldesign/leveldesign/game_element/xp_table/xptable.xp_table code/ryzom/tools/server/sql/ryzom_admin_default_data.sql - +code/ryzom/tools/server/ryzom_ams/drupal +code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ams_lib # Linux server compile code/ryzom/server/src/entities_game_service/entities_game_service code/ryzom/server/src/frontend_service/frontend_service @@ -210,6 +211,6 @@ code/ryzom/server/src/ryzom_admin_service/ryzom_admin_service code/ryzom/server/src/ryzom_naming_service/ryzom_naming_service code/ryzom/server/src/ryzom_welcome_service/ryzom_welcome_service code/ryzom/server/src/tick_service/tick_service -# WebTT temp dir +# WebTT temp dir code/ryzom/tools/server/www/webtt/app/tmp -code\ryzom\tools\server\ryzom_ams\old \ No newline at end of file +code\ryzom\tools\server\ryzom_ams\old diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage.info b/code/ryzom/tools/server/ryzom_ams/drupal_module/oldmodule/ryzommanage.info similarity index 100% rename from code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage.info rename to code/ryzom/tools/server/ryzom_ams/drupal_module/oldmodule/ryzommanage.info diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage.install b/code/ryzom/tools/server/ryzom_ams/drupal_module/oldmodule/ryzommanage.install similarity index 100% rename from code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage.install rename to code/ryzom/tools/server/ryzom_ams/drupal_module/oldmodule/ryzommanage.install diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage.module b/code/ryzom/tools/server/ryzom_ams/drupal_module/oldmodule/ryzommanage.module similarity index 100% rename from code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage.module rename to code/ryzom/tools/server/ryzom_ams/drupal_module/oldmodule/ryzommanage.module diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/config.php b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/config.php new file mode 100644 index 000000000..322d50357 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/config.php @@ -0,0 +1,90 @@ + 'Ryzom Manager', + 'machine_name' => 'ryzommanage', + 'description' => 'Ryzom Login Service integration - inserts and updates users and manages accounts.', + 'module' => 'ryzommanage', + ); + $vocab = (object) $vocab; + db_query("CREATE TABLE ryzommanage_querycache ( + `SID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , + `type` VARCHAR( 64 ) NOT NULL , + `query` VARCHAR( 512 ) NOT NULL + );"); + +} + +function ryzommanage_uninstall() { + db_query("DROP TABLE ryzommanage_querycache;"); +} + +function _ryzommanage_vocab_fields() { + +} \ No newline at end of file diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ryzommanage.module b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ryzommanage.module new file mode 100644 index 000000000..2acbdbe2b --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ryzommanage.module @@ -0,0 +1,949 @@ + ring users ---- nel user & nel permission ---- hook_user_cancel ---- remove character data on server +menu items that do stuff + +*/ +error_reporting(E_ALL); +ini_set('display_errors', 'on'); + +$path = drupal_get_path('module', 'ryzommanage'); +require_once ($path . '/config.php'); +require_once( $path . '/ams_lib/libinclude.php' ); + + +/* +Drupal 7 ryzom core module +Copyright (C) 2013 Matthew Lagoe (Botanic) & Paige Offerdahl (Tobi) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +//output template +function loadTemplate($template,$vars) +{ + extract($vars); + include($template); +} +/** + * + * Function ryzommanage_admin + * + * @takes Nothing + * @return array $form + * + * Info: Creates the box's etc that go in the ryzom admin menu + * + */ +function ryzommanage_admin() +{ + $form = array(); + //admin menu items + + + $path = drupal_get_path('module', 'ryzommanage'); + require($path . '/config.php'); + $form['ryzommanage_serverurl'] = array( + '#type' => 'textfield', + '#title' => t('Server url'), + '#default_value' => $cfg['db']['lib']['name'],//variable_get('ryzommanage_serverurl', 'localhost'), + '#description' => t("The url of the ryzom server to integrate with."), + '#required' => TRUE + ); + $form['ryzommanage_mysqlport'] = array( + '#type' => 'textfield', + '#title' => t('Port for MySQL'), + '#size' => 5, + '#maxlength' => 5, + '#default_value' => variable_get('ryzommanage_mysqlport', '3306'), + '#description' => t("The MySQL port of the ryzom server to integrate with."), + '#required' => TRUE, + '#element_validate' => array( + '_check_port_value' + ) + ); + $form['ryzommanage_dbname'] = array( + '#type' => 'textfield', + '#title' => t('Database Name'), + '#default_value' => variable_get('ryzommanage_dbname', 'nel'), + '#description' => t("The MySQL database name to connect to."), + '#required' => TRUE + ); + $form['ryzommanage_username'] = array( + '#type' => 'textfield', + '#title' => t('MySQL Username'), + '#default_value' => variable_get('ryzommanage_username', 'root'), + '#description' => t("The MySQL username to connect with."), + '#required' => TRUE + ); + $form['ryzommanage_password'] = array( + '#type' => 'password_confirm', + '#title' => t('MySQL Password'), + '#description' => t("Confirm the MySQL password.") + ); + return system_settings_form($form); +} +//validate registration webpage +function ryzommanage_form_alter(&$form, &$form_state, $form_id) +{ + if($form_id == "user_register_form") + { + $form['#validate'][] = '_webpage_registration'; + } elseif($form_id == "user_profile_form") { + $form['#validate'][] = '_webpage_profile'; + } +} + +function _webpage_registration(&$form_state) +{ + + $user = checkUser($form_state['account']['name']['#value']); + $email = validEmail($form_state['account']['mail']['#value']); + + if ($user != "success") { + form_set_error('name', t($user)); + } + if ($email != "success") { + form_set_error('mail', t('Not a valid email address, please check it and try again.')); + } + +} + +function _webpage_profile(&$form_state) +{ + $email = validEmail($form_state['account']['mail']['#value']); + + if ($email != "success") { + form_set_error('mail', t('Not a valid email address, please check it and try again.')); + } + if ((checkPassword($form_state['account']['pass']['#value']['pass1']) == "success" ) and ( $form_state['account']['pass']['#value']['pass1'] == + $form_state['account']['pass']['#value']['pass2'] )) { + } +} + +/** + * + * Function ryzommanage_menu + * + * @takes Nothing + * @return array $items + * + * Info: Creates the menu item in the admin interface + * + */ +function ryzommanage_menu() +{ + $items = array(); + //page for client registration + $items['register'] = array( + 'title' => 'register', + 'page callback' => '_collect_register', + 'page arguments' => array(1, 2), + 'access callback' => 'user_access', + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); + //main menu item + $items['admin/config/ryzommanage'] = array( + 'title' => 'Ryzom Server Integration', + 'description' => 'Ryzom integration information.', + 'page callback' => 'system_admin_menu_block_page', + 'access arguments' => array( + 'administer site configuration' + ), + 'file' => 'system.admin.inc', + 'file path' => drupal_get_path('module', 'system') + ); + // First submenu item + $items['admin/config/ryzommanage/serversettings'] = array( + 'title' => 'Ryzom Server Settings', + 'description' => 'This is the first child item in the section', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'ryzommanage_admin' + ), + 'access arguments' => array( + 'administer site configuration' + ) + ); + // Second submenu item + $items['admin/config/ryzommanage/nameregister'] = array( + 'title' => 'Name Registration Settings', + 'description' => 'Configure default behavior of name registration module.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'name_registration_admin_settings' + ), + 'access arguments' => array( + 'administer site configuration' + ) + ); + return $items; +} +function name_registration_admin_settings() { + $form = array(); + $form['ryzommanage_game-name'] = array( + '#type' => 'textfield', + '#title' => t('Game Name'), + '#default_value' => variable_get('ryzommanage_game-name', ''), + '#description' => t("Name of game used on registration pages."), + '#required' => TRUE + ); + //this is not the TOS url used in the create account page, you change that in the config of the client with the ConditionsTermsURL value + $form['ryzommanage_TOS'] = array( + '#type' => 'textfield', + '#title' => t('Terms of Service URL'), + '#default_value' => variable_get('ryzommanage_TOS', ''), + '#description' => t("The url of the TOS for your server."), + '#required' => TRUE + ); + $form['ryzommanage_register-welcome'] = array( + '#type' => 'textarea', + '#title' => t('Registration Welcome Message'), + '#default_value' => variable_get('ryzommanage_register-welcome', ''), + '#description' => t("Registration welcome message on first page of create account."), + '#required' => TRUE + ); + + return system_settings_form($form); +} +/** + * + * Function ryzommanage_menu + * + * @takes Int $element, &$form_state + * @return Nothing + * + * Info: Used by ryzommanage_mysqlport to validate ryzommanage_admin will run form_error if port is not between 1 and 65535. + * + */ +function _check_port_value($element, &$form_state) +{ + if ((!is_numeric(parse_size($element['#value']))) or ((parse_size($element['#value']) > 65535) or (parse_size($element['#value']) < 1))) { + form_error($element, t($element['#value'] . ' is not a valid value for the MySQL port, it must be a valid value. You must choose a number between 1 and 65535.')); + } +} +/** + * + * Function ryzommanage_block_info + * + * @takes Nothing + * @return array $blocks + * + * Info: Info for block that shows the user menu + * + */ +function ryzommanage_block_info() +{ + $blocks['ryzommanage_usersblock'] = array( + // info: The name of the block. + 'info' => t('Ryzom Manage User Block'), + 'status' => TRUE, + 'region' => '-1', // Not usually provided. + 'visibility' => BLOCK_VISIBILITY_LISTED // Not usually provided. + ); + return $blocks; +} +/** + * + * Function ryzommanage_block_view + * + * @takes Nothing + * @return array $block + * + * Info: View for block + * + */ +function ryzommanage_block_view($delta = '') +{ + $block = array(); + //The $delta parameter tells us which block is being requested. + switch ($delta) { + case 'ryzommanage_usersblock': + $block['subject'] = t("uppercase this please"); + $block['content'] = top_bar(); + break; + } + return $block; +} +/** + * + * Function _collect_register + * + * @takes + * @return Nothing + * + * Info: Determins what to send back to client, if the client is ryzom core then send the http data if its a browser send to / + * + */ +function _collect_register($nids, $collection) +{ + syncdata(); + //if not using ryzom core client show registration page + if (check_if_game_client()) { + return_client_httpdata(); + } else { + //redirect to registration page + header("Location: /user/register"); + } +} +/** + * + * Function check_if_game_client + * + * @takes Nothing + * @return Boolean + * + * Info: Returns True if connecting client is ryzom core + * + */ +function check_if_game_client() +{ + //if HTTP_USER_AGENT is not set then its ryzom core + if (!isset($_SERVER['HTTP_USER_AGENT'])) { + return true; + } else { + return false; + } +} +/** + * + * Function return_client_httpdata + * + * @takes + * @return + * + * Info: Returns ryzom core formatted html for use in registration via client + * + */ +function return_client_httpdata() +{ + //check if values exist + if (isset($_POST["Username"]) and isset($_POST["Password"]) and isset($_POST["Email"]) ) + { + //check values + $user = checkUser($_POST["Username"]); + $pass = checkPassword($_POST["Password"]); + $cpass = confirmPassword(); + $email = checkEmail($_POST["Email"]); + } else { + $user = ""; + $pass = ""; + $cpass = ""; + $email = ""; + } + //if all are good then create user + if (($user == "success") and ($pass == "success") and ($cpass == "success") and ($email == "success") and (isset($_POST["TaC"]))) { + $edit = array( + 'name' => $_POST["Username"], + 'pass' => $_POST["Password"], + 'mail' => $_POST["Email"], + 'init' => $_POST["Email"], + 'unhashpass' => $_POST["Password"], + 'status' => 1, + 'access' => REQUEST_TIME + ); + user_save(NULL, $edit); + header('Location: email_sent.php'); + exit; + } else { + $pageElements = array( + 'GAME_NAME' => variable_get('ryzommanage_game-name', ''), + 'WELCOME_MESSAGE' => variable_get('ryzommanage_register-welcome', ''), + 'USERNAME' => $user, + 'PASSWORD' => $pass, + 'CPASSWORD' => $cpass, + 'EMAIL' => $email + ); + if ($user != "success") { + $pageElements['USERNAME_ERROR'] = 'TRUE'; + } else { + $pageElements['USERNAME_ERROR'] = 'FALSE'; + } + + if ($pass != "success") { + $pageElements['PASSWORD_ERROR'] = 'TRUE'; + } else { + $pageElements['PASSWORD_ERROR'] = 'FALSE'; + } + if ($cpass != "success") { + $pageElements['CPASSWORD_ERROR'] = 'TRUE'; + } else { + $pageElements['CPASSWORD_ERROR'] = 'FALSE'; + } + if ($email != "success") { + $pageElements['EMAIL_ERROR'] = 'TRUE'; + } else { + $pageElements['EMAIL_ERROR'] = 'FALSE'; + } + if (isset($_POST["TaC"])) { + $pageElements['TAC_ERROR'] = 'FALSE'; + } else { + $pageElements['TAC_ERROR'] = 'TRUE'; + } + loadTemplate('templates/ingame_register.phtml',$pageElements); + } +} +/** + * + * Function checkUser + * + * @takes $username + * @return string + * + * Info: Returns a string based on if the username is valid, if valid then "success" is returned + * + */ +function checkUser($username) +{ + if (isset($username)) { + if (strlen($username) > 12) { + return "Username must be no more than 12 characters."; + } elseif (strlen($username) < 5) { + return "Username must be 5 or more characters."; + } elseif (!preg_match('/^[a-z0-9\.]*$/', $username)) { + return "Username can only contain numbers and letters."; + } elseif (db_query("SELECT COUNT(*) FROM {users} WHERE name = :name", array( + ':name' => $username + ))->fetchField()) { + return "Username " . $username . " is in use."; + } else { + return "success"; + } + } else { + return "success"; + } + return "fail"; +} +/** + * + * Function checkPassword + * + * @takes $pass + * @return string + * + * Info: Returns a string based on if the password is valid, if valid then "success" is returned + * + */ +function checkPassword($pass) +{ + if (isset($pass)) { + if (strlen($pass) > 20) { + return "Password must be no more than 20 characters."; + } elseif (strlen($pass) < 5) { + return "Password must be more than 5 characters."; + } else { + return "success"; + } + } + return "fail"; +} +/** + * + * Function confirmPassword + * + * @takes $pass + * @return string + * + * Info: Verify's $_POST["Password"] is the same as $_POST["ConfirmPass"] + * + */ +function confirmPassword() +{ + if (($_POST["Password"]) != ($_POST["ConfirmPass"])) { + return "Passwords do not match."; + } else { + return "success"; + } + return "fail"; +} +/** + * + * Function checkEmail + * + * @takes $email + * @return + * + * + * + */ +function checkEmail($email) +{ + if (isset($email)) { + if (!validEmail($email)) { + return "Email address is not valid."; + } elseif (db_query("SELECT COUNT(*) FROM {users} WHERE mail = :mail", array( + ':mail' => $email + ))->fetchField()) { + return "Email is in use."; + } else { + return "success"; + } + } else { + return "success"; + } + return "fail"; +} +function validEmail($email) +{ + $isValid = true; + $atIndex = strrpos($email, "@"); + if (is_bool($atIndex) && !$atIndex) { + $isValid = false; + } else { + $domain = substr($email, $atIndex + 1); + $local = substr($email, 0, $atIndex); + $localLen = strlen($local); + $domainLen = strlen($domain); + if ($localLen < 1 || $localLen > 64) { + // local part length exceeded + $isValid = false; + } else if ($domainLen < 1 || $domainLen > 255) { + // domain part length exceeded + $isValid = false; + } else if ($local[0] == '.' || $local[$localLen - 1] == '.') { + // local part starts or ends with '.' + $isValid = false; + } else if (preg_match('/\\.\\./', $local)) { + // local part has two consecutive dots + $isValid = false; + } else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { + // character not valid in domain part + $isValid = false; + } else if (preg_match('/\\.\\./', $domain)) { + // domain part has two consecutive dots + $isValid = false; + } else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\", "", $local))) { + // character not valid in local part unless + // local part is quoted + if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\", "", $local))) { + $isValid = false; + } + } + if ($isValid && !(checkdnsrr($domain, "MX") || checkdnsrr($domain, "A"))) { + // domain not found in DNS + $isValid = false; + } + } + return $isValid; +} +function generateSALT($length = 2) +{ + // start with a blank salt + $salt = ""; + // define possible characters - any character in this string can be + // picked for use in the salt, so if you want to put vowels back in + // or add special characters such as exclamation marks, this is where + // you should do it + $possible = "2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ"; + // we refer to the length of $possible a few times, so let's grab it now + $maxlength = strlen($possible); + // check for length overflow and truncate if necessary + if ($length > $maxlength) { + $length = $maxlength; + } + // set up a counter for how many characters are in the salt so far + $i = 0; + // add random characters to $salt until $length is reached + while ($i < $length) { + // pick a random character from the possible ones + $char = substr($possible, mt_rand(0, $maxlength - 1), 1); + // have we already used this character in $salt? + if (!strstr($salt, $char)) { + // no, so it's OK to add it onto the end of whatever we've already got... + $salt .= $char; + // ... and increase the counter by one + $i++; + } + } + // done! + return $salt; +} +function createUser($values) +{ + + $login = $values[0]; + $pass = $values[1]; + $email = $values[2]; + + $salt = generateSALT(); + $hashpass = crypt($pass, $salt); + + $params = array( + $login, + $hashpass, + $email + ); + + try { + $hostname = variable_get('ryzommanage_serverurl', 'localhost'); + $port = variable_get('ryzommanage_mysqlport', '3306'); + $dbname = variable_get('ryzommanage_dbname', 'nel'); + $username = variable_get('ryzommanage_username', 'root'); + $password = variable_get('ryzommanage_password', ''); + $dbh = new PDO("mysql:host=$hostname;port=$port;dbname=$dbname", $username, $password); + $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + catch (PDOException $e) { + watchdog('ryzommanage', $e->getMessage(), NULL, WATCHDOG_ERROR); + $nid = db_insert('ryzommanage_querycache')->fields(array( + "SID" => NULL, + "type" => "createUser", + "query" => json_encode(array( + $login, + $pass, + $email + )) + ))->execute(); + return true; + } + + try { + $statement = $dbh->prepare("INSERT INTO user (Login, Password, Email) VALUES (?, ?, ?)"); + } + catch (PDOException $e) { + watchdog('ryzommanage', $e->getMessage(), NULL, WATCHDOG_ERROR); + $nid = db_insert('ryzommanage_querycache')->fields(array( + "SID" => NULL, + "type" => "createUser", + "query" => json_encode(array( + $login, + $pass, + $email + )) + ))->execute(); + return true; + } + + try { + $statement->execute($params); + } + catch (PDOException $e) { + watchdog('ryzommanage', $e->getMessage(), NULL, WATCHDOG_ERROR); + $nid = db_insert('ryzommanage_querycache')->fields(array( + "SID" => NULL, + "type" => "createUser", + "query" => json_encode(array( + $login, + $pass, + $email + )) + ))->execute(); + return true; + } + + createPermissions(array($login)); +} + +function createPermissions($values) { + + try { + $hostname = variable_get('ryzommanage_serverurl', 'localhost'); + $port = variable_get('ryzommanage_mysqlport', '3306'); + $dbname = variable_get('ryzommanage_dbname', 'nel'); + $username = variable_get('ryzommanage_username', 'root'); + $password = variable_get('ryzommanage_password', ''); + $dbh = new PDO("mysql:host=$hostname;port=$port;dbname=$dbname", $username, $password); + $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + catch (PDOException $e) { + watchdog('ryzommanage', $e->getMessage(), NULL, WATCHDOG_ERROR); + $nid = db_insert('ryzommanage_querycache')->fields(array( + "SID" => NULL, + "type" => "createPermissions", + "query" => json_encode(array( + $values[0] + )) + ))->execute(); + return true; + } + + try { + $sth = $dbh->prepare("SELECT UId FROM user WHERE Login='" . $values[0] . "';"); + $sth->execute(); + $result = $sth->fetchAll(); + foreach ($result as $UId) { + $statement = $dbh->prepare("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES ('" . $UId['UId'] . "', 'r2', 'OPEN');"); + $statement->execute($values); + $statement = $dbh->prepare("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES ('" . $UId['UId'] . "', 'ryzom_open', 'OPEN');"); + $statement->execute($values); + } + } + catch (PDOException $e) { + watchdog('ryzommanage', $e->getMessage(), NULL, WATCHDOG_ERROR); + $nid = db_insert('ryzommanage_querycache')->fields(array( + "SID" => NULL, + "type" => "createPermissions", + "query" => json_encode(array( + $values[0] + )) + ))->execute(); + return true; + } + + return true; +} + +function login_form($login_form) +{ + $login_form['#action'] = url(current_path(), array( + 'query' => drupal_get_destination(), + 'external' => FALSE + )); + $login_form['#id'] = 'user-login-form'; + $login_form['#validate'] = user_login_default_validators(); + $login_form['#submit'][] = 'user_login_submit'; + $login_form['name'] = array( + '#type' => 'textfield', + '#title' => t('Username'), + '#maxlength' => 12, + '#size' => 15, + '#required' => TRUE + ); + $login_form['pass'] = array( + '#type' => 'password', + '#title' => t('Password'), + '#maxlength' => 20, + '#size' => 15, + '#required' => TRUE + ); + $items = array(); + if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) { + $items[] = l(t('Create new account'), 'user/register', array( + 'attributes' => array( + 'title' => t('Create a new user account.') + ) + )); + } + $items[] = l(t('Request new password'), 'user/password', array( + 'attributes' => array( + 'title' => t('Request new password via e-mail.') + ) + )); + $login_form['links'] = array( + '#markup' => theme('item_list', array( + 'items' => $items + )) + ); + $login_form['remember_me'] = array( + '#type' => 'checkbox', + '#title' => t('Remember Me'), + '#default_value' => 0 + ); + $login_form['actions'] = array( + '#type' => 'actions' + ); + $login_form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => t('Log in') + ); + return $login_form; +} + +function top_bar() +{ + global $user; + $userId = $user->uid; + if (user_is_logged_in()) { + // Logged in user + return "
Notepad | Mail | Wiki | Profile | Craft Recipe-Book | Occupations | News/Events | Account | Logout
"; + } else { + return drupal_get_form('login_form'); + // Not logged in + } +} + +function ryzommanage_user_presave(&$edit, $account, $category) +{ + if (isset($edit['unhashpass'])) { + $pass = $edit['unhashpass']; + } elseif (isset($_POST['pass']['pass1'])) { + $pass = $_POST['pass']['pass1']; + } + + if (!isset($edit['name'])) { + $name = $user->name; + } else { + $name = $edit['name']; + } + + if ($account->is_new == 1 ) { + createUser(array($edit['name'], $pass, $edit['mail'])); + } else { + user_edit( array($edit['name'], $pass)); + } +} + +function ryzommanage_form_user_register_form_alter(&$form, &$form_state, $form_id) { + // Modification for the form with the given form ID goes here. For example, if + // FORM_ID is "user_register_form" this code would run only on the user + // registration form. + + // Change the data for the username and email fields + $form['account']['name']['#maxlength'] = '12'; + $form['account']['name']['#description'] = '5-12 lower-case characters and numbers. The login (username) you create here will be your login name.
The name of your game characters will be chosen later on.
'; + $form['account']['mail']['#description'] = 'Please verify that the e-mail address you enter here is valid and will remain valid in the future.
It will be used to manage your Tempest in the Aether account.
'; + // Add a checkbox to registration form about agreeing to terms of use. + $form['terms_of_use'] = array( + '#type' => 'checkbox', + '#title' => t("I agree with the terms and conditions."), + '#required' => TRUE, + ); +} + +function ryzommanage_form_user_profile_form_alter(&$form, &$form_state, $form_id) { + // Modification for the form with the given form ID goes here. For example, if + // FORM_ID is "user_register_form" this code would run only on the user + // registration form. + + // Change the data for the password field + $form['account']['pass']['#description'] = 'Password must be 5-20 characters.
'; +} + +function user_edit($values) { + + $username = $values[0]; + $newpassword = $values[1]; + + $salt = generateSALT(); + $pass = crypt($newpassword, $salt); + + try { + $hostname = variable_get('ryzommanage_serverurl', 'localhost'); + $port = variable_get('ryzommanage_mysqlport', '3306'); + $dbname = variable_get('ryzommanage_dbname', 'nel'); + $ryusername = variable_get('ryzommanage_username', 'root'); + $password = variable_get('ryzommanage_password', ''); + $dbh = new PDO("mysql:host=$hostname;port=$port;dbname=$dbname", $ryusername, $password); + $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + catch (PDOException $e) { + watchdog('ryzommanage', $e->getMessage(), NULL, WATCHDOG_ERROR); + $nid = db_insert('ryzommanage_querycache')->fields(array( + "SID" => NULL, + "type" => "user_edit", + "query" => json_encode(array( + $username, + $newpassword + )) + ))->execute(); + return true; + } + + $sql = "UPDATE `nel`.`user` SET `Password` = ? WHERE `user`.`Login` = ?"; + + try { + $q = $dbh->prepare($sql); + } + catch (PDOException $e) { + watchdog('ryzommanage', $e->getMessage(), NULL, WATCHDOG_ERROR); + $nid = db_insert('ryzommanage_querycache')->fields(array( + "SID" => NULL, + "type" => "user_edit", + "query" => json_encode(array( + $username, + $newpassword + )) + ))->execute(); + return true; + } + + try { + $q->execute(array( $pass, $username)); + } + catch (PDOException $e) { + watchdog('ryzommanage', $e->getMessage(), NULL, WATCHDOG_ERROR); + $nid = db_insert('ryzommanage_querycache')->fields(array( + "SID" => NULL, + "type" => "user_edit", + "query" => json_encode(array( + $username, + $newpassword + )) + ))->execute(); + return true; + } + + return true; +} + +/** + * + * Function syncdata + * + * @takes Nothing + * @return array $values + * + * Info: Runs functions to finish syncing data when shard is offline + * + */ +function syncdata () { + + try { + $hostname = variable_get('ryzommanage_serverurl', 'localhost'); + $port = variable_get('ryzommanage_mysqlport', '3306'); + $dbname = variable_get('ryzommanage_dbname', 'nel'); + $ryusername = variable_get('ryzommanage_username', 'root'); + $password = variable_get('ryzommanage_password', ''); + $dbh = new PDO("mysql:host=$hostname;port=$port;dbname=$dbname", $ryusername, $password); + $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + catch (PDOException $e) { + watchdog('ryzommanage', $e->getMessage(), NULL, WATCHDOG_ERROR); + return true; + } + + $query = db_select('ryzommanage_querycache', 'q') + ->fields('q', array('SID', 'type', 'query')); + + $result = $query->execute(); + + foreach ($result as $record) { + watchdog('ryzommanage_usersync', $record->query, NULL, WATCHDOG_ERROR); + + switch($record->type) { + case 'createPermissions': + case 'user_edit': + case 'createUser': + watchdog('ryzommanage_usersync', $record->type, NULL, WATCHDOG_INFO); + $SID = $record->SID; + $num_deleted = db_delete('ryzommanage_querycache') + ->condition('SID', $SID) + ->execute(); + $func = $record->type; + $func(json_decode($record->query)); + } + + } + +} +/** + * + * Function ryzommanage_cron + * + * @takes + * @return + * + * Info: Runs the syncdata function with the drupal cron + * + */ +function ryzommanage_cron() { + + syncdata(); + +} diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/templates/ingame_register.phtml b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/templates/ingame_register.phtml new file mode 100644 index 000000000..1f0fc0859 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/templates/ingame_register.phtml @@ -0,0 +1,116 @@ +
+ RYZOM CORE INGAME REGISTRATION +
+ +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + You must accept the Terms of Service';} + else { + echo ' +
id="caption-Username">Desired Username: + + width="42%">
id="caption-Password">Desired Password: + + width="42%">
id="caption-ConfirmPass">Confirm Password: + width="42%">
id="caption-Email">Email Address (to which a confirmation email will be sent): + account.', this);" /> + width="42%">
+ colspan="2">YES, I agree to the terms of + service';}; ?> +
+ +
+ +
+
+ +
+ +
+ 5-12 lower-case characters and numbers. The login (username) you create here will be + your login name. The name of your game characters will be chosen later on. +
+ +
+ 5-20 characters. +
+ +
+ Retype your Password +
+ +
+ Please verify that the e-mail address you enter here is valid and will remain valid + in the future. It will be used to manage your account. +
+ +
\ No newline at end of file diff --git a/code/ryzom/tools/server/ryzom_ams/howto.txt b/code/ryzom/tools/server/ryzom_ams/howto.txt new file mode 100644 index 000000000..f930ce26f --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/howto.txt @@ -0,0 +1,7 @@ +-Edit config .php file +-Atm also edit the autoload function's paths +-call the install.php function in your terminal located in the sql folder + +for mailing: +-set imap settings in config file (also make sure the folder exists that you will use for mail logging and storing emails) +-make sure imap is enabled. \ No newline at end of file diff --git a/code/ryzom/tools/server/ryzom_ams/www/config.php b/code/ryzom/tools/server/ryzom_ams/www/config.php index 6e2769079..25679ac64 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/config.php +++ b/code/ryzom/tools/server/ryzom_ams/www/config.php @@ -54,7 +54,7 @@ $TICKET_MAILING_SUPPORT = true; //You have to create this dir at first! $MAIL_DIR = "/tmp/mail"; - +$TOS_URL ="http://createyourtos.com"; $MAIL_LOG_PATH = "/tmp/mail/cron_mail.log"; $cfg['crypt']['key'] = 'Sup3rS3cr3tStuff'; diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/register.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/register.php new file mode 100644 index 000000000..966f75c08 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/register.php @@ -0,0 +1,7 @@ +
- {$tac_tag1}{$tac_tag2} + {$tac_tag1}{$tac_tag2}