Spaces:
Paused
Paused
Deploy Bot commited on
Commit Β·
7e47e6a
1
Parent(s): bfc5154
Implement_API_Key_Generator_For_Future_App_Integration
Browse files- src/controllers/adminController.js +59 -2
- src/main.js +3 -0
src/controllers/adminController.js
CHANGED
|
@@ -11,8 +11,8 @@ const getDashboardButtons = () => {
|
|
| 11 |
[Markup.button.callback("β Mahsulot qo'shish", "admin_add_product"), Markup.button.callback("π Mahsulot o'chirish", "admin_delete_product")],
|
| 12 |
[Markup.button.callback("βοΈ Mahsulotni tahrirlash", "admin_edit_product_list"), Markup.button.callback("π₯ Foydalanuvchilar", "admin_users")],
|
| 13 |
[Markup.button.callback("π Excel Export", "admin_excel_export"), Markup.button.callback("π’ Reklama yuborish", "admin_broadcast")],
|
| 14 |
-
[Markup.button.callback("π₯ Aksiya (Flash Sale)", "admin_flash_sale"), Markup.button.callback("π¦ Ombor Boshqaruvi", "admin_inventory")],
|
| 15 |
-
[Markup.button.callback("βοΈ Do'kon Sozlamalari", "admin_settings")]
|
| 16 |
];
|
| 17 |
};
|
| 18 |
|
|
@@ -257,6 +257,63 @@ exports.showInvoice = async (ctx, orderId) => {
|
|
| 257 |
}
|
| 258 |
};
|
| 259 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
// Reject Order (Refund Logic)
|
| 261 |
exports.rejectOrder = async (ctx, orderId) => {
|
| 262 |
try {
|
|
|
|
| 11 |
[Markup.button.callback("β Mahsulot qo'shish", "admin_add_product"), Markup.button.callback("π Mahsulot o'chirish", "admin_delete_product")],
|
| 12 |
[Markup.button.callback("βοΈ Mahsulotni tahrirlash", "admin_edit_product_list"), Markup.button.callback("π₯ Foydalanuvchilar", "admin_users")],
|
| 13 |
[Markup.button.callback("π Excel Export", "admin_excel_export"), Markup.button.callback("π’ Reklama yuborish", "admin_broadcast")],
|
| 14 |
+
[Markup.button.callback("π₯ Aksiya (Flash Sale)", "admin_flash_sale"), Markup.button.callback("π¦ Ombor Boshqaruvi", "admin_inventory")],
|
| 15 |
+
[Markup.button.callback("βοΈ Do'kon Sozlamalari", "admin_settings"), Markup.button.callback("π API Integratsiya", "admin_api")] // Added API Button
|
| 16 |
];
|
| 17 |
};
|
| 18 |
|
|
|
|
| 257 |
}
|
| 258 |
};
|
| 259 |
|
| 260 |
+
exports.toggleBlockUser = async (ctx, userId, isBlock) => {
|
| 261 |
+
try {
|
| 262 |
+
await User.updateOne({ id: userId }, { isBlocked: isBlock });
|
| 263 |
+
const msg = isBlock ? "Foydalanuvchi bloklandi π«" : "Foydalanuvchi blokdan chiqarildi β
";
|
| 264 |
+
ctx.answerCbQuery(msg);
|
| 265 |
+
exports.manageUser(ctx, userId); // Refresh view
|
| 266 |
+
} catch (e) {
|
| 267 |
+
console.error(e);
|
| 268 |
+
}
|
| 269 |
+
};
|
| 270 |
+
|
| 271 |
+
// --- API Key Management ---
|
| 272 |
+
const crypto = require('crypto');
|
| 273 |
+
const Settings = require('../models/Settings');
|
| 274 |
+
|
| 275 |
+
exports.showApiMenu = async (ctx) => {
|
| 276 |
+
try {
|
| 277 |
+
const apiKeySetting = await Settings.findOne({ key: 'api_secret_key' });
|
| 278 |
+
const apiKey = apiKeySetting ? apiKeySetting.value : "β οΈ Mavjud emas";
|
| 279 |
+
|
| 280 |
+
let text = `π **API Integratsiya Sozlamalari**\n\n` +
|
| 281 |
+
`Sizning API Kalitingiz (Secret Key):\n` +
|
| 282 |
+
`<code>${apiKey}</code>\n\n` +
|
| 283 |
+
`β οΈ **Eslatma:** Bu kalit orqali kelajakdagi APK mobil ilovani bot bazasiga ulashingiz mumkin. Kalitni birovga bermang!`;
|
| 284 |
+
|
| 285 |
+
const keyboard = Markup.inlineKeyboard([
|
| 286 |
+
[Markup.button.callback("π Yangi Kalit Yaratish", "admin_api_generate")],
|
| 287 |
+
[Markup.button.callback("π Orqaga", "admin_dashboard")]
|
| 288 |
+
]);
|
| 289 |
+
|
| 290 |
+
ctx.editMessageText(text, { parse_mode: 'HTML', ...keyboard })
|
| 291 |
+
.catch(e => ctx.replyWithHTML(text, keyboard));
|
| 292 |
+
} catch (e) {
|
| 293 |
+
console.error(e);
|
| 294 |
+
ctx.reply("Xatolik");
|
| 295 |
+
}
|
| 296 |
+
};
|
| 297 |
+
|
| 298 |
+
exports.generateApiKey = async (ctx) => {
|
| 299 |
+
try {
|
| 300 |
+
// Generate new key
|
| 301 |
+
const newKey = "sk_live_" + crypto.randomBytes(16).toString('hex');
|
| 302 |
+
|
| 303 |
+
await Settings.findOneAndUpdate(
|
| 304 |
+
{ key: 'api_secret_key' },
|
| 305 |
+
{ value: newKey },
|
| 306 |
+
{ upsert: true, new: true }
|
| 307 |
+
);
|
| 308 |
+
|
| 309 |
+
ctx.answerCbQuery("Yangi kalit yaratildi β
");
|
| 310 |
+
exports.showApiMenu(ctx);
|
| 311 |
+
} catch (e) {
|
| 312 |
+
console.error(e);
|
| 313 |
+
ctx.answerCbQuery("Xatolik");
|
| 314 |
+
}
|
| 315 |
+
};
|
| 316 |
+
|
| 317 |
// Reject Order (Refund Logic)
|
| 318 |
exports.rejectOrder = async (ctx, orderId) => {
|
| 319 |
try {
|
src/main.js
CHANGED
|
@@ -65,6 +65,9 @@ bot.command('admin', (ctx) => {
|
|
| 65 |
|
| 66 |
// Admin Callbacks
|
| 67 |
bot.action('admin_dashboard', (ctx) => adminController.showDashboard(ctx));
|
|
|
|
|
|
|
|
|
|
| 68 |
bot.action('admin_users', (ctx) => adminController.showUsers(ctx));
|
| 69 |
bot.action(/admin_user_manage_(.+)/, (ctx) => adminController.manageUser(ctx, ctx.match[1]));
|
| 70 |
bot.action(/user_block_(.+)/, (ctx) => adminController.toggleBlockUser(ctx, ctx.match[1], true));
|
|
|
|
| 65 |
|
| 66 |
// Admin Callbacks
|
| 67 |
bot.action('admin_dashboard', (ctx) => adminController.showDashboard(ctx));
|
| 68 |
+
bot.action('admin_api', (ctx) => adminController.showApiMenu(ctx)); // NEW
|
| 69 |
+
bot.action('admin_api_generate', (ctx) => adminController.generateApiKey(ctx)); // NEW
|
| 70 |
+
|
| 71 |
bot.action('admin_users', (ctx) => adminController.showUsers(ctx));
|
| 72 |
bot.action(/admin_user_manage_(.+)/, (ctx) => adminController.manageUser(ctx, ctx.match[1]));
|
| 73 |
bot.action(/user_block_(.+)/, (ctx) => adminController.toggleBlockUser(ctx, ctx.match[1], true));
|