diff --git a/admin.php b/admin.php index 598d552..5aaa0bc 100644 --- a/admin.php +++ b/admin.php @@ -157,6 +157,18 @@ $loginDisabledAllowed = $userCount == 1 && $settings['registrations_open'] == 0;

+

+
+ +
+
+ +
+
+ + +
false, + "message" => translate('session_expired', $i18n) + ])); +} + +// Check that user is an admin +if ($userId !== 1) { + die(json_encode([ + "success" => false, + "message" => translate('error', $i18n) + ])); +} + +$currencies = [ + ['id' => 1, 'name' => 'Euro', 'symbol' => '€', 'code' => 'EUR'], + ['id' => 2, 'name' => 'US Dollar', 'symbol' => '$', 'code' => 'USD'], + ['id' => 3, 'name' => 'Japanese Yen', 'symbol' => '¥', 'code' => 'JPY'], + ['id' => 4, 'name' => 'Bulgarian Lev', 'symbol' => 'лв', 'code' => 'BGN'], + ['id' => 5, 'name' => 'Czech Republic Koruna', 'symbol' => 'Kč', 'code' => 'CZK'], + ['id' => 6, 'name' => 'Danish Krone', 'symbol' => 'kr', 'code' => 'DKK'], + ['id' => 7, 'name' => 'British Pound Sterling', 'symbol' => '£', 'code' => 'GBP'], + ['id' => 8, 'name' => 'Hungarian Forint', 'symbol' => 'Ft', 'code' => 'HUF'], + ['id' => 9, 'name' => 'Polish Zloty', 'symbol' => 'zł', 'code' => 'PLN'], + ['id' => 10, 'name' => 'Romanian Leu', 'symbol' => 'lei', 'code' => 'RON'], + ['id' => 11, 'name' => 'Swedish Krona', 'symbol' => 'kr', 'code' => 'SEK'], + ['id' => 12, 'name' => 'Swiss Franc', 'symbol' => 'Fr', 'code' => 'CHF'], + ['id' => 13, 'name' => 'Icelandic Króna', 'symbol' => 'kr', 'code' => 'ISK'], + ['id' => 14, 'name' => 'Norwegian Krone', 'symbol' => 'kr', 'code' => 'NOK'], + ['id' => 15, 'name' => 'Russian Ruble', 'symbol' => '₽', 'code' => 'RUB'], + ['id' => 16, 'name' => 'Turkish Lira', 'symbol' => '₺', 'code' => 'TRY'], + ['id' => 17, 'name' => 'Australian Dollar', 'symbol' => '$', 'code' => 'AUD'], + ['id' => 18, 'name' => 'Brazilian Real', 'symbol' => 'R$', 'code' => 'BRL'], + ['id' => 19, 'name' => 'Canadian Dollar', 'symbol' => '$', 'code' => 'CAD'], + ['id' => 20, 'name' => 'Chinese Yuan', 'symbol' => '¥', 'code' => 'CNY'], + ['id' => 21, 'name' => 'Hong Kong Dollar', 'symbol' => 'HK$', 'code' => 'HKD'], + ['id' => 22, 'name' => 'Indonesian Rupiah', 'symbol' => 'Rp', 'code' => 'IDR'], + ['id' => 23, 'name' => 'Israeli New Sheqel', 'symbol' => '₪', 'code' => 'ILS'], + ['id' => 24, 'name' => 'Indian Rupee', 'symbol' => '₹', 'code' => 'INR'], + ['id' => 25, 'name' => 'South Korean Won', 'symbol' => '₩', 'code' => 'KRW'], + ['id' => 26, 'name' => 'Mexican Peso', 'symbol' => 'Mex$', 'code' => 'MXN'], + ['id' => 27, 'name' => 'Malaysian Ringgit', 'symbol' => 'RM', 'code' => 'MYR'], + ['id' => 28, 'name' => 'New Zealand Dollar', 'symbol' => 'NZ$', 'code' => 'NZD'], + ['id' => 29, 'name' => 'Philippine Peso', 'symbol' => '₱', 'code' => 'PHP'], + ['id' => 30, 'name' => 'Singapore Dollar', 'symbol' => 'S$', 'code' => 'SGD'], + ['id' => 31, 'name' => 'Thai Baht', 'symbol' => '฿', 'code' => 'THB'], + ['id' => 32, 'name' => 'South African Rand', 'symbol' => 'R', 'code' => 'ZAR'], +]; + +$categories = [ + ['id' => 1, 'name' => 'No category'], + ['id' => 2, 'name' => 'Entertainment'], + ['id' => 3, 'name' => 'Music'], + ['id' => 4, 'name' => 'Utilities'], + ['id' => 5, 'name' => 'Food & Beverages'], + ['id' => 6, 'name' => 'Health & Wellbeing'], + ['id' => 7, 'name' => 'Productivity'], + ['id' => 8, 'name' => 'Banking'], + ['id' => 9, 'name' => 'Transport'], + ['id' => 10, 'name' => 'Education'], + ['id' => 11, 'name' => 'Insurance'], + ['id' => 12, 'name' => 'Gaming'], + ['id' => 13, 'name' => 'News & Magazines'], + ['id' => 14, 'name' => 'Software'], + ['id' => 15, 'name' => 'Technology'], + ['id' => 16, 'name' => 'Cloud Services'], + ['id' => 17, 'name' => 'Charity & Donations'], +]; + +$payment_methods = [ + ['id' => 1, 'name' => 'PayPal', 'icon' => 'images/uploads/icons/paypal.png'], + ['id' => 2, 'name' => 'Credit Card', 'icon' => 'images/uploads/icons/creditcard.png'], + ['id' => 3, 'name' => 'Bank Transfer', 'icon' => 'images/uploads/icons/banktransfer.png'], + ['id' => 4, 'name' => 'Direct Debit', 'icon' => 'images/uploads/icons/directdebit.png'], + ['id' => 5, 'name' => 'Money', 'icon' => 'images/uploads/icons/money.png'], + ['id' => 6, 'name' => 'Google Pay', 'icon' => 'images/uploads/icons/googlepay.png'], + ['id' => 7, 'name' => 'Samsung Pay', 'icon' => 'images/uploads/icons/samsungpay.png'], + ['id' => 8, 'name' => 'Apple Pay', 'icon' => 'images/uploads/icons/applepay.png'], + ['id' => 9, 'name' => 'Crypto', 'icon' => 'images/uploads/icons/crypto.png'], + ['id' => 10, 'name' => 'Klarna', 'icon' => 'images/uploads/icons/klarna.png'], + ['id' => 11, 'name' => 'Amazon Pay', 'icon' => 'images/uploads/icons/amazonpay.png'], + ['id' => 12, 'name' => 'SEPA', 'icon' => 'images/uploads/icons/sepa.png'], + ['id' => 13, 'name' => 'Skrill', 'icon' => 'images/uploads/icons/skrill.png'], + ['id' => 14, 'name' => 'Sofort', 'icon' => 'images/uploads/icons/sofort.png'], + ['id' => 15, 'name' => 'Stripe', 'icon' => 'images/uploads/icons/stripe.png'], + ['id' => 16, 'name' => 'Affirm', 'icon' => 'images/uploads/icons/affirm.png'], + ['id' => 17, 'name' => 'AliPay', 'icon' => 'images/uploads/icons/alipay.png'], + ['id' => 18, 'name' => 'Elo', 'icon' => 'images/uploads/icons/elo.png'], + ['id' => 19, 'name' => 'Facebook Pay', 'icon' => 'images/uploads/icons/facebookpay.png'], + ['id' => 20, 'name' => 'GiroPay', 'icon' => 'images/uploads/icons/giropay.png'], + ['id' => 21, 'name' => 'iDeal', 'icon' => 'images/uploads/icons/ideal.png'], + ['id' => 22, 'name' => 'Union Pay', 'icon' => 'images/uploads/icons/unionpay.png'], + ['id' => 23, 'name' => 'Interac', 'icon' => 'images/uploads/icons/interac.png'], + ['id' => 24, 'name' => 'WeChat', 'icon' => 'images/uploads/icons/wechat.png'], + ['id' => 25, 'name' => 'Paysafe', 'icon' => 'images/uploads/icons/paysafe.png'], + ['id' => 26, 'name' => 'Poli', 'icon' => 'images/uploads/icons/poli.png'], + ['id' => 27, 'name' => 'Qiwi', 'icon' => 'images/uploads/icons/qiwi.png'], + ['id' => 28, 'name' => 'ShopPay', 'icon' => 'images/uploads/icons/shoppay.png'], + ['id' => 29, 'name' => 'Venmo', 'icon' => 'images/uploads/icons/venmo.png'], + ['id' => 30, 'name' => 'VeriFone', 'icon' => 'images/uploads/icons/verifone.png'], + ['id' => 31, 'name' => 'WebMoney', 'icon' => 'images/uploads/icons/webmoney.png'], +]; + +function validate($value) +{ + $value = trim($value); + $value = stripslashes($value); + $value = htmlspecialchars($value); + $value = htmlentities($value); + return $value; +} + +if ($_SERVER["REQUEST_METHOD"] === "POST") { + + $postData = file_get_contents("php://input"); + $data = json_decode($postData, true); + + $loggedInUserId = $userId; + + $email = validate($data['email']); + $username = validate(strtolower($data['username'])); + $password = $data['password']; + + if (empty($username) || empty($password) || empty($email)) { + die(json_encode([ + "success" => false, + "message" => translate('error', $i18n) + ])); + } + + $stmt = $db->prepare('SELECT COUNT(*) FROM user WHERE username = :username OR email = :email'); + $stmt->bindValue(':username', $username, SQLITE3_INTEGER); + $stmt->bindValue(':email', $email, SQLITE3_TEXT); + $result = $stmt->execute(); + $row = $result->fetchArray(); + // Error if user exist + if ($row[0] > 0) { + die(json_encode([ + "success" => false, + "message" => translate('error', $i18n) + ])); + } + + // Get main currency and language from admin user + $stmt = $db->prepare('SELECT main_currency, language FROM user WHERE id = :id'); + $stmt->bindValue(':id', $loggedInUserId, SQLITE3_TEXT); + $result = $stmt->execute(); + $row = $result->fetchArray(); + $currency = $row['main_currency'] ?? 1; + $language = $row['language'] ?? 'en'; + $avatar = "images/avatars/0.svg"; + + // Get code for main currency + $stmt = $db->prepare('SELECT code FROM currencies WHERE id = :id'); + $stmt->bindValue(':id', $currency, SQLITE3_TEXT); + $row = $stmt->execute(); + $main_currency = $row->fetchArray()['code']; + + $query = "INSERT INTO user (username, email, password, main_currency, avatar, language, budget) VALUES (:username, :email, :password, :main_currency, :avatar, :language, :budget)"; + $stmt = $db->prepare($query); + $hashedPassword = password_hash($password, PASSWORD_DEFAULT); + $stmt->bindValue(':username', $username, SQLITE3_TEXT); + $stmt->bindValue(':email', $email, SQLITE3_TEXT); + $stmt->bindValue(':password', $hashedPassword, SQLITE3_TEXT); + $stmt->bindValue(':main_currency', 1, SQLITE3_TEXT); + $stmt->bindValue(':avatar', $avatar, SQLITE3_TEXT); + $stmt->bindValue(':language', $language, SQLITE3_TEXT); + $stmt->bindValue(':budget', 0, SQLITE3_INTEGER); + $result = $stmt->execute(); + + if ($result) { + + // Get id of the newly created user + $newUserId = $db->lastInsertRowID(); + + // Add username as household member for that user + $query = "INSERT INTO household (name, user_id) VALUES (:name, :user_id)"; + $stmt = $db->prepare($query); + $stmt->bindValue(':name', $username, SQLITE3_TEXT); + $stmt->bindValue(':user_id', $newUserId, SQLITE3_INTEGER); + $stmt->execute(); + + if ($newUserId > 1) { + + // Add categories for that user + $query = 'INSERT INTO categories (name, "order", user_id) VALUES (:name, :order, :user_id)'; + $stmt = $db->prepare($query); + foreach ($categories as $index => $category) { + $stmt->bindValue(':name', $category['name'], SQLITE3_TEXT); + $stmt->bindValue(':order', $index + 1, SQLITE3_INTEGER); + $stmt->bindValue(':user_id', $newUserId, SQLITE3_INTEGER); + $stmt->execute(); + } + + // Add payment methods for that user + $query = 'INSERT INTO payment_methods (name, icon, "order", user_id) VALUES (:name, :icon, :order, :user_id)'; + $stmt = $db->prepare($query); + foreach ($payment_methods as $index => $payment_method) { + $stmt->bindValue(':name', $payment_method['name'], SQLITE3_TEXT); + $stmt->bindValue(':icon', $payment_method['icon'], SQLITE3_TEXT); + $stmt->bindValue(':order', $index + 1, SQLITE3_INTEGER); + $stmt->bindValue(':user_id', $newUserId, SQLITE3_INTEGER); + $stmt->execute(); + } + + // Add currencies for that user + $query = "INSERT INTO currencies (name, symbol, code, rate, user_id) VALUES (:name, :symbol, :code, :rate, :user_id)"; + $stmt = $db->prepare($query); + foreach ($currencies as $currency) { + $stmt->bindValue(':name', $currency['name'], SQLITE3_TEXT); + $stmt->bindValue(':symbol', $currency['symbol'], SQLITE3_TEXT); + $stmt->bindValue(':code', $currency['code'], SQLITE3_TEXT); + $stmt->bindValue(':rate', 1, SQLITE3_FLOAT); + $stmt->bindValue(':user_id', $newUserId, SQLITE3_INTEGER); + $stmt->execute(); + } + + // Retrieve main currency id + $query = "SELECT id FROM currencies WHERE code = :code AND user_id = :user_id"; + $stmt = $db->prepare($query); + $stmt->bindValue(':code', $main_currency, SQLITE3_TEXT); + $stmt->bindValue(':user_id', $newUserId, SQLITE3_INTEGER); + $result = $stmt->execute(); + $currency = $result->fetchArray(SQLITE3_ASSOC); + + // Update user main currency + $query = "UPDATE user SET main_currency = :main_currency WHERE id = :user_id"; + $stmt = $db->prepare($query); + $stmt->bindValue(':main_currency', $currency['id'], SQLITE3_INTEGER); + $stmt->bindValue(':user_id', $newUserId, SQLITE3_INTEGER); + $stmt->execute(); + + // Add settings for that user + $query = "INSERT INTO settings (dark_theme, monthly_price, convert_currency, remove_background, color_theme, hide_disabled, user_id) + VALUES (2, 0, 0, 0, 'blue', 0, :user_id)"; + $stmt = $db->prepare($query); + $stmt->bindValue(':user_id', $newUserId, SQLITE3_INTEGER); + $stmt->execute(); + + // If email verification is required add the user to the email_verification table + $query = "SELECT * FROM admin"; + $stmt = $db->prepare($query); + $result = $stmt->execute(); + $settings = $result->fetchArray(SQLITE3_ASSOC); + } + + $db->close(); + + die(json_encode([ + "success" => true, + "message" => translate('success', $i18n) + ])); + } + + + +} else { + die(json_encode([ + "success" => false, + "message" => translate('error', $i18n) + ])); +} + +?> \ No newline at end of file diff --git a/includes/i18n/de.php b/includes/i18n/de.php index 74ae898..34fd475 100644 --- a/includes/i18n/de.php +++ b/includes/i18n/de.php @@ -281,6 +281,7 @@ $i18n = [ "user_management" => "Benutzerverwaltung", "delete_user" => "Benutzer löschen", "delete_user_info" => "Durch das Löschen eines Benutzers werden auch alle seine Abonnements und Einstellungen gelöscht.", + "create_user" => "Benutzer erstellen", "smtp_settings" => "SMTP Einstellungen", "smtp_usage_info" => "Wird für die Passwortwiederherstellung und andere System-E-Mails verwendet", // Email Verification diff --git a/includes/i18n/el.php b/includes/i18n/el.php index d668c99..8b1dd2c 100644 --- a/includes/i18n/el.php +++ b/includes/i18n/el.php @@ -281,6 +281,7 @@ $i18n = [ "user_management" => "Διαχείριση χρηστών", "delete_user" => "Διαγραφή χρήστη", "delete_user_info" => "Η διαγραφή ενός χρήστη θα διαγράψει επίσης όλες τις συνδρομές και τις ρυθμίσεις του.", + "create_user" => "Δημιουργία χρήστη", "smtp_settings" => "SMTP ρυθμίσεις", "smtp_usage_info" => "Θα χρησιμοποιηθεί για ανάκτηση κωδικού πρόσβασης και άλλα μηνύματα ηλεκτρονικού ταχυδρομείου συστήματος.", // Email Verification diff --git a/includes/i18n/en.php b/includes/i18n/en.php index 9963bde..b4619d2 100644 --- a/includes/i18n/en.php +++ b/includes/i18n/en.php @@ -281,6 +281,7 @@ $i18n = [ "user_management" => "User Management", "delete_user" => "Delete User", "delete_user_info" => "Deleting a user will also delete all their subscriptions and settings.", + "create_user" => "Create User", "smtp_settings" => "SMTP Settings", "smtp_usage_info" => "Will be used for password recovery and other system emails.", // Email Verification diff --git a/includes/i18n/es.php b/includes/i18n/es.php index d1b5129..69f8fde 100644 --- a/includes/i18n/es.php +++ b/includes/i18n/es.php @@ -281,6 +281,7 @@ $i18n = [ "user_management" => "Gestión de Usuarios", "delete_user" => "Eliminar Usuario", "delete_user_info" => "Al eliminar un usuario, también se eliminarán todas sus suscripciones y configuraciones.", + "create_user" => "Crear Usuario", "smtp_settings" => "Configuración SMTP", "smtp_usage_info" => "Se utilizará para recuperar contraseñas y otros correos electrónicos del sistema.", // Email Verification diff --git a/includes/i18n/fr.php b/includes/i18n/fr.php index 0aa42c8..dfe7010 100644 --- a/includes/i18n/fr.php +++ b/includes/i18n/fr.php @@ -281,6 +281,7 @@ $i18n = [ "user_management" => "Gestion des utilisateurs", "delete_user" => "Supprimer l'utilisateur", "delete_user_info" => "La suppression d'un utilisateur supprimera également tous ses abonnements et paramètres.", + "create_user" => "Créer un utilisateur", "smtp_settings" => "Paramètres SMTP", "smtp_usage_info" => "Sera utilisé pour la récupération du mot de passe et d'autres e-mails système.", // Email Verification diff --git a/includes/i18n/it.php b/includes/i18n/it.php index 3cc2554..eb8670f 100644 --- a/includes/i18n/it.php +++ b/includes/i18n/it.php @@ -299,6 +299,7 @@ $i18n = [ "user_management" => "Gestione utenti", "delete_user" => "Elimina utente", "delete_user_info" => "L'eliminazione di un utente eliminerà anche tutte le sue iscrizioni e impostazioni.", + "create_user" => "Crea utente", "smtp_settings" => "Impostazioni SMTP", "smtp_usage_info" => "Verrà utilizzato per il recupero della password e altre e-mail di sistema.", diff --git a/includes/i18n/jp.php b/includes/i18n/jp.php index fb6dfa6..80c305a 100644 --- a/includes/i18n/jp.php +++ b/includes/i18n/jp.php @@ -281,6 +281,7 @@ $i18n = [ "user_management" => "ユーザー管理", "delete_user" => "ユーザーを削除", "delete_user_info" => "ユーザーを削除すると、そのユーザーのサブスクリプションと設定もすべて削除されます。", + "create_user" => "ユーザーを作成", "smtp_settings" => "SMTP設定", "smtp_usage_info" => "パスワードの回復やその他のシステム電子メールに使用されます。", // Email Verification diff --git a/includes/i18n/ko.php b/includes/i18n/ko.php index 20a0de0..994f0d6 100644 --- a/includes/i18n/ko.php +++ b/includes/i18n/ko.php @@ -282,6 +282,7 @@ $i18n = [ "user_management" => "유저 관리", "delete_user" => "유저 삭제", "delete_user_info" => "사용자를 삭제하면 모든 구독 및 설정도 삭제됩니다.", + "create_user" => "유저 생성", "smtp_settings" => "SMTP 설정", "smtp_usage_info" => "비밀번호 복구 및 기타 시스템 이메일에 사용됩니다.", // Email Verification diff --git a/includes/i18n/pl.php b/includes/i18n/pl.php index 997aae0..82bfcd8 100644 --- a/includes/i18n/pl.php +++ b/includes/i18n/pl.php @@ -281,6 +281,7 @@ $i18n = [ "user_management" => "Zarządzanie użytkownikami", "delete_user" => "Usuń użytkownika", "delete_user_info" => "Usunięcie użytkownika spowoduje również usunięcie wszystkich jego subskrypcji i ustawień.", + "create_user" => "Utwórz użytkownika", "smtp_settings" => "Ustawienia SMTP", "smtp_usage_info" => "Będzie używany do odzyskiwania hasła i innych e-maili systemowych.", // Email Verification diff --git a/includes/i18n/pt.php b/includes/i18n/pt.php index 72b1f8e..a7fb1c0 100644 --- a/includes/i18n/pt.php +++ b/includes/i18n/pt.php @@ -281,6 +281,7 @@ $i18n = [ "user_management" => "Gestão de Utilizadores", "delete_user" => "Apagar Utilizador", "delete_user_info" => "Apagar utilizador irá remover todas as suas subscrições e dados associados.", + "create_user" => "Criar Utilizador", "smtp_settings" => "Definições SMTP", "smtp_usage_info" => "Será usado para recuperações de password e outros emails do sistema.", // Email Verification diff --git a/includes/i18n/pt_br.php b/includes/i18n/pt_br.php index 0c8cc5e..7390421 100644 --- a/includes/i18n/pt_br.php +++ b/includes/i18n/pt_br.php @@ -281,6 +281,7 @@ $i18n = [ "user_management" => "Gerenciamento de usuários", "delete_user" => "Excluir usuário", "delete_user_info" => "Excluir um usuário também excluirá todas as assinaturas e dados associados", + "create_user" => "Criar usuário", "smtp_settings" => "Configurações SMTP", "smtp_usage_info" => "Será usado para recuperação de senha e outros e-mails do sistema.", // Email Verification diff --git a/includes/i18n/ru.php b/includes/i18n/ru.php index 1d61245..0257352 100644 --- a/includes/i18n/ru.php +++ b/includes/i18n/ru.php @@ -281,6 +281,7 @@ $i18n = [ "user_management" => "Управление пользователями", "delete_user" => "Удалить пользователя", "delete_user_info" => "Удаление пользователя также приведет к удалению всех его подписок и настроек.", + "create_user" => "Создать пользователя", "smtp_settings" => "Настройки SMTP", "smtp_usage_info" => "Будет использоваться для восстановления пароля и других системных писем.", // Email Verification diff --git a/includes/i18n/sl.php b/includes/i18n/sl.php index d3f367a..e73224e 100644 --- a/includes/i18n/sl.php +++ b/includes/i18n/sl.php @@ -281,6 +281,7 @@ $i18n = [ "user_management" => "Upravljanje uporabnikov", "delete_user" => "Izbriši uporabnika", "delete_user_info" => "Če izbrišete uporabnika, boste izbrisali tudi vse njegove naročnine in nastavitve.", + "create_user" => "Ustvari uporabnika", "smtp_settings" => "Nastavitve SMTP", "smtp_usage_info" => "Uporabljeno bo za obnovitev gesla in druge sistemske e-pošte.", // Email Verification diff --git a/includes/i18n/sr.php b/includes/i18n/sr.php index d892c48..fc122f7 100644 --- a/includes/i18n/sr.php +++ b/includes/i18n/sr.php @@ -280,6 +280,7 @@ $i18n = [ "user_management" => "Управљање корисницима", "delete_user" => "Обриши корисника", "delete_user_info" => "Брисање корисника ће такође обрисати све његове претплате и податке.", + "create_user" => "Креирај корисника", "smtp_settings" => "SMTP подешавања", "smtp_usage_info" => "SMTP се користи за слање е-поште за обавештења.", // Email Verification diff --git a/includes/i18n/sr_lat.php b/includes/i18n/sr_lat.php index f27495e..35bfe40 100644 --- a/includes/i18n/sr_lat.php +++ b/includes/i18n/sr_lat.php @@ -281,6 +281,7 @@ $i18n = [ "user_management" => "Upravljanje korisnicima", "delete_user" => "Izbriši korisnika", "delete_user_info" => "Brisanjem korisnika izbrisaće se i sve njegove pretplate i podešavanja.", + "create_user" => "Kreiraj korisnika", "smtp_settings" => "SMTP podešavanja", "smtp_usage_info" => "Koristiće se za oporavak lozinke i druge sistemske e-poruke.", // Email Verification diff --git a/includes/i18n/tr.php b/includes/i18n/tr.php index a7e7cda..8763f6d 100644 --- a/includes/i18n/tr.php +++ b/includes/i18n/tr.php @@ -282,6 +282,7 @@ $i18n = [ "user_management" => "Kullanıcı Yönetimi", "delete_user" => "Kullanıcıyı Sil", "delete_user_info" => "Bir kullanıcının silinmesi aynı zamanda tüm aboneliklerinin ve ayarlarının da silinmesine neden olur.", + "create_user" => "Kullanıcı Oluştur", "smtp_settings" => "SMTP Ayarları", "smtp_usage_info" => "Şifre kurtarma ve diğer sistem e-postaları için kullanılacaktır.", // Email Verification diff --git a/includes/i18n/zh_cn.php b/includes/i18n/zh_cn.php index cbbd8d1..6ae63af 100644 --- a/includes/i18n/zh_cn.php +++ b/includes/i18n/zh_cn.php @@ -299,6 +299,7 @@ $i18n = [ "user_management" => "用户管理", "delete_user" => "删除用户", "delete_user_info" => "删除用户也会删除其所有订阅和设置。", + "create_user" => "创建用户", "smtp_settings" => "SMTP 设置", "smtp_usage_info" => "将用于密码恢复和其他系统电子邮件。", diff --git a/includes/i18n/zh_tw.php b/includes/i18n/zh_tw.php index 3e2d8aa..fa97cb6 100644 --- a/includes/i18n/zh_tw.php +++ b/includes/i18n/zh_tw.php @@ -281,6 +281,7 @@ $i18n = [ "user_management" => "使用者管理", "delete_user" => "刪除使用者", "delete_user_info" => "刪除用戶也會刪除其所有訂閱和設定。", + "create_user" => "建立使用者", "smtp_settings" => "SMTP 設定", "smtp_usage_info" => "將用於密碼恢復和其他系統電子郵件。", // Email Verification diff --git a/includes/version.php b/includes/version.php index e9b617b..17cbc8e 100644 --- a/includes/version.php +++ b/includes/version.php @@ -1,3 +1,3 @@ \ No newline at end of file diff --git a/registration.php b/registration.php index ce4dabe..7c88c58 100644 --- a/registration.php +++ b/registration.php @@ -151,7 +151,7 @@ $emailExists = false; $registrationFailed = false; $hasErrors = false; if (isset($_POST['username'])) { - $username = validate($_POST['username']); + $username = validate(strtolower($_POST['username'])); $email = validate($_POST['email']); $password = $_POST['password']; $confirm_password = $_POST['confirm_password']; @@ -263,7 +263,7 @@ if (isset($_POST['username'])) { // Add settings for that user $query = "INSERT INTO settings (dark_theme, monthly_price, convert_currency, remove_background, color_theme, hide_disabled, user_id) - VALUES (0, 0, 0, 0, 'blue', 0, :user_id)"; + VALUES (2, 0, 0, 0, 'blue', 0, :user_id)"; $stmt = $db->prepare($query); $stmt->bindValue(':user_id', $userId, SQLITE3_INTEGER); $stmt->execute(); diff --git a/scripts/admin.js b/scripts/admin.js index aa4e5ac..13e6684 100644 --- a/scripts/admin.js +++ b/scripts/admin.js @@ -224,4 +224,42 @@ function removeUser(userId) { }) .catch(error => showErrorMessage('Error:', error)); +} + +function addUserButton() { + const button = document.getElementById('addUserButton'); + button.disabled = true; + + const username = document.getElementById('newUsername').value; + const email = document.getElementById('newEmail').value; + const password = document.getElementById('newPassword').value; + + const data = { + username: username, + email: email, + password: password + }; + + fetch('endpoints/admin/adduser.php', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(data) + }) + .then(response => response.json()) + .then(data => { + if (data.success) { + showSuccessMessage(data.message); + button.disabled = false; + window.location.reload(); + } else { + showErrorMessage(data.message); + button.disabled = false; + } + }) + .catch(error => { + showErrorMessage(error); + button.disabled = false; + }); } \ No newline at end of file