function tryToInstall() { global $ydb; global $yourls_user_passwords; $tableuser = YOURLS_DB_TABLE_USERS; $results = $ydb->get_results("show tables like '{$tableuser}'; "); if (empty($results)) { $ydb->query("CREATE TABLE `{$tableuser}` (\n\t\t `user_id` int(11) NOT NULL auto_increment,\n\t\t `user_email` varchar(200) NOT NULL,\n\t\t `user_password` varchar(32) NOT NULL,\n\t\t `user_token` varchar(50) NOT NULL,\n\t\t PRIMARY KEY (`user_id`),\n\t\t UNIQUE KEY `user_email_UNIQUE` (`user_email`),\n\t\t UNIQUE KEY `user_hash_UNIQUE` (`user_token`)\n\t\t );"); $create_success = $ydb->query("SHOW TABLES LIKE '{$tableuser}'"); if (!$create_success) { // Problems on creation. } else { foreach ($yourls_user_passwords as $username => $pass) { $token = createRandonToken(); $password = md5($pass); $ydb->query("insert into `{$tableuser}` (user_email, user_password, user_token) values ('{$username}', '{$password}', '{$token}')"); } } } $table = YOURLS_DB_TABLE_URL_TO_USER; $results = $ydb->get_results("show tables like '{$table}'; "); if (empty($results)) { $ydb->query("CREATE TABLE `{$table}` (\n\t\t\t`url_keyword` varchar(200) character set latin1 collate latin1_bin NOT NULL,\n\t\t\t`users_user_id` int(11) NOT NULL,\n\t\t\tPRIMARY KEY (`url_keyword`,`users_user_id`)\n\t\t\t);"); $create_success = $ydb->query("SHOW TABLES LIKE '{$table}'"); if (!$create_success) { // Problems on creation. } } }
function createRandonToken() { global $ydb; $ui = uniqid(uniqid("a", true), true); $table = YOURLS_DB_TABLE_USERS; $results = $ydb->get_results("select user_email from `{$table}` where `user_token` = '{$ui}'"); if (!empty($results)) { return createRandonToken(); } else { return str_replace(".", "", $ui); } }
require_once 'formjoin.php'; break; } } if (!empty($username) && !empty($password)) { if (validEmail($username) === false) { $error_msg = "E-mail not recognized!"; require_once 'formjoin.php'; } else { $table = YOURLS_DB_TABLE_USERS; $results = $ydb->get_results("select user_email from `{$table}` where `user_email` = '{$username}'"); if ($results) { $error_msg = "Please choose other username."; require_once 'formjoin.php'; } else { $token = createRandonToken(); $password = md5($password); $ydb->query("insert into `{$table}` (user_email, user_password, user_token) values ('{$username}', '{$password}', '{$token}')"); $results = $ydb->get_results("select user_token from `{$table}` where `user_email` = '{$username}'"); if (!empty($results)) { $token = $results[0]->user_token; $error_msg = "User {$username} added with token {$token}."; require_once 'form.php'; } else { require_once 'formjoin.php'; } } } } else { $error_msg = "Please fill all fields."; require_once 'formjoin.php';