2026-03-10-1
This commit is contained in:
266
lib/views/admin/enceypt/driver_fingerprint_migration.dart
Normal file
266
lib/views/admin/enceypt/driver_fingerprint_migration.dart
Normal file
@@ -0,0 +1,266 @@
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// driver_fingerprint_migration.dart
|
||||
// ───────────────────────────────────────────────────────────────
|
||||
// المنطق ببساطة:
|
||||
// 1. خذ البصمة كما هي من DB
|
||||
// 2. split('_') → احذف آخر جزء (OS version)
|
||||
// 3. join('_') → encrypt → رفع
|
||||
//
|
||||
// مثال:
|
||||
// "abc123_SamsungA51_13" → "abc123_SamsungA51" → encrypt
|
||||
// "TECNO_LH7n-GL_14" → "TECNO_LH7n-GL" → encrypt
|
||||
// "unknown_2412DPC0AG_15" → "unknown_2412DPC0AG" → encrypt
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../constant/links.dart';
|
||||
import '../../../controller/functions/crud.dart';
|
||||
import '../../../controller/functions/encrypt_decrypt.dart';
|
||||
import '../../../print.dart';
|
||||
|
||||
class DriverFingerprintMigrationTool extends StatefulWidget {
|
||||
const DriverFingerprintMigrationTool({super.key});
|
||||
|
||||
@override
|
||||
State<DriverFingerprintMigrationTool> createState() =>
|
||||
_DriverFingerprintMigrationToolState();
|
||||
}
|
||||
|
||||
class _DriverFingerprintMigrationToolState
|
||||
extends State<DriverFingerprintMigrationTool> {
|
||||
bool _isRunning = false;
|
||||
bool _isDone = false;
|
||||
int _total = 0;
|
||||
int _processed = 0;
|
||||
int _updated = 0;
|
||||
int _failed = 0;
|
||||
String _currentLog = '';
|
||||
|
||||
static const int _batchSize = 50;
|
||||
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
// المنطق الأساسي — حذف آخر جزء بعد "_"
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
String _removeLastSegment(String raw) {
|
||||
final parts = raw.split('_');
|
||||
if (parts.length <= 1) return raw; // جزء واحد — ما في شيء نحذفه
|
||||
parts.removeLast();
|
||||
return parts.join('_');
|
||||
}
|
||||
|
||||
Future<void> _startMigration() async {
|
||||
setState(() {
|
||||
_isRunning = true;
|
||||
_isDone = false;
|
||||
_processed = 0;
|
||||
_updated = 0;
|
||||
_failed = 0;
|
||||
_currentLog = 'جارٍ جلب بصمات السائقين...';
|
||||
});
|
||||
|
||||
try {
|
||||
final records = await _fetchAll();
|
||||
if (records == null) {
|
||||
_log('❌ فشل في جلب البيانات');
|
||||
setState(() => _isRunning = false);
|
||||
return;
|
||||
}
|
||||
|
||||
_total = records.length;
|
||||
_log('✅ تم جلب $_total بصمة — بدء المعالجة...');
|
||||
|
||||
for (int i = 0; i < records.length; i += _batchSize) {
|
||||
final batch = records.skip(i).take(_batchSize).toList();
|
||||
_log('⚙️ معالجة ${i + 1} → ${i + batch.length} من $_total');
|
||||
await Future.wait(batch.map(_processSingle));
|
||||
if (i + _batchSize < records.length) {
|
||||
await Future.delayed(const Duration(milliseconds: 300));
|
||||
}
|
||||
}
|
||||
|
||||
_log('🎉 اكتمل!\nمحدَّث: $_updated | فاشل: $_failed');
|
||||
setState(() {
|
||||
_isDone = true;
|
||||
_isRunning = false;
|
||||
});
|
||||
} catch (e) {
|
||||
_log('❌ خطأ: $e');
|
||||
setState(() => _isRunning = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>?> _fetchAll() async {
|
||||
try {
|
||||
final response = await CRUD().post(
|
||||
link: AppLink.getAllDriverFingerprints,
|
||||
payload: {'admin_key': 'iuyweiruinakjbfkajkjlkmalkcxnlahd'},
|
||||
);
|
||||
if (response == 'failure' || response == null) return null;
|
||||
|
||||
final data = response['data'];
|
||||
if (data is! List) return null;
|
||||
|
||||
return List<Map<String, dynamic>>.from(data);
|
||||
} catch (e) {
|
||||
Log.print('fetchAll error: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _processSingle(Map<String, dynamic> record) async {
|
||||
final captainId = record['captain_id']?.toString() ?? '';
|
||||
final rawFp = record['fingerPrint']?.toString() ?? '';
|
||||
|
||||
if (captainId.isEmpty || rawFp.isEmpty) {
|
||||
setState(() {
|
||||
_failed++;
|
||||
_processed++;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// ── حذف آخر جزء (OS version) ─────────────────────────────
|
||||
final String newRaw = _removeLastSegment(rawFp);
|
||||
final String encrypted = EncryptionHelper.instance.encryptData(newRaw);
|
||||
|
||||
Log.print('🔄 [$captainId] "$rawFp" → "$newRaw" → encrypted');
|
||||
|
||||
// ── رفع للسيرفر ──────────────────────────────────────────
|
||||
final res = await CRUD().post(
|
||||
link: AppLink.updateDriverFingerprintAdmin,
|
||||
payload: {
|
||||
'captain_id': captainId,
|
||||
'fingerprint': encrypted,
|
||||
'admin_key': 'iuyweiruinakjbfkajkjlkmalkcxnlahd',
|
||||
},
|
||||
);
|
||||
|
||||
if (res != 'failure' && res?['status'] == 'success') {
|
||||
setState(() {
|
||||
_updated++;
|
||||
_processed++;
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
_failed++;
|
||||
_processed++;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
Log.print('❌ [$captainId]: $e');
|
||||
setState(() {
|
||||
_failed++;
|
||||
_processed++;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _log(String msg) {
|
||||
Log.print(msg);
|
||||
setState(() => _currentLog = msg);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Driver FP Migration')),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orange.shade50,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: Colors.orange.shade200),
|
||||
),
|
||||
child: const Text(
|
||||
'⚠️ تُستخدم مرة واحدة فقط\n\n'
|
||||
'"abc123_Samsung_13" → "abc123_Samsung" → encrypt\n'
|
||||
'"TECNO_LH7n_14" → "TECNO_LH7n" → encrypt',
|
||||
style:
|
||||
TextStyle(fontSize: 13, height: 1.7, fontFamily: 'monospace'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
if (_total > 0) ...[
|
||||
Text('التقدم: $_processed / $_total',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 8),
|
||||
LinearProgressIndicator(
|
||||
value: _total > 0 ? _processed / _total : 0,
|
||||
backgroundColor: Colors.grey.shade200,
|
||||
color: _isDone ? Colors.green : Colors.blue,
|
||||
minHeight: 8,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
if (_processed > 0)
|
||||
Row(children: [
|
||||
_chip('محدَّث', _updated, Colors.green),
|
||||
const SizedBox(width: 8),
|
||||
_chip('فاشل', _failed, Colors.red),
|
||||
]),
|
||||
const SizedBox(height: 16),
|
||||
if (_currentLog.isNotEmpty)
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade100,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(_currentLog,
|
||||
style:
|
||||
const TextStyle(fontFamily: 'monospace', fontSize: 12)),
|
||||
),
|
||||
const Spacer(),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 52,
|
||||
child: ElevatedButton(
|
||||
onPressed: (_isRunning || _isDone) ? null : _startMigration,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: _isDone ? Colors.green : Colors.blue,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
),
|
||||
child: _isRunning
|
||||
? const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white, strokeWidth: 2)),
|
||||
SizedBox(width: 12),
|
||||
Text('جارٍ الترحيل...',
|
||||
style:
|
||||
TextStyle(color: Colors.white, fontSize: 16)),
|
||||
],
|
||||
)
|
||||
: Text(
|
||||
_isDone ? '✅ اكتمل الترحيل' : 'بدء ترحيل بصمات السائقين',
|
||||
style: const TextStyle(color: Colors.white, fontSize: 16),
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _chip(String label, int value, Color color) => Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: color.withOpacity(0.3)),
|
||||
),
|
||||
child: Text('$label: $value',
|
||||
style: TextStyle(color: color, fontWeight: FontWeight.bold)),
|
||||
);
|
||||
}
|
||||
855
lib/views/admin/enceypt/encrypt.dart
Normal file
855
lib/views/admin/enceypt/encrypt.dart
Normal file
@@ -0,0 +1,855 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:sefer_admin1/constant/links.dart';
|
||||
import 'package:sefer_admin1/controller/functions/crud.dart';
|
||||
import 'package:sefer_admin1/main.dart';
|
||||
|
||||
import '../../../constant/box_name.dart';
|
||||
|
||||
// ─── Custom Colors ────────────────────────────────────────────────────────────
|
||||
class _AppColors {
|
||||
static const bg = Color(0xFF0A0D14);
|
||||
static const surface = Color(0xFF111622);
|
||||
static const card = Color(0xFF161D2E);
|
||||
static const border = Color(0xFF1F2D4A);
|
||||
static const accent = Color(0xFF00E5FF);
|
||||
static const accentDim = Color(0xFF0097A7);
|
||||
static const accentGlow = Color(0x2200E5FF);
|
||||
static const accentDecrypt = Color(0xFF7C4DFF);
|
||||
static const accentDecryptDim = Color(0xFF512DA8);
|
||||
static const accentDecryptGlow = Color(0x227C4DFF);
|
||||
static const textPrimary = Color(0xFFE8F0FE);
|
||||
static const textSec = Color(0xFF7A8BAA);
|
||||
static const success = Color(0xFF00E676);
|
||||
static const error = Color(0xFFFF5252);
|
||||
}
|
||||
|
||||
class EncryptToolPage extends StatefulWidget {
|
||||
final String adminToken;
|
||||
|
||||
const EncryptToolPage({Key? key, required this.adminToken}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<EncryptToolPage> createState() => _EncryptToolPageState();
|
||||
}
|
||||
|
||||
class _EncryptToolPageState extends State<EncryptToolPage>
|
||||
with SingleTickerProviderStateMixin {
|
||||
final TextEditingController _inputController = TextEditingController();
|
||||
final TextEditingController _outputController = TextEditingController();
|
||||
|
||||
String _output = '';
|
||||
bool _loading = false;
|
||||
String? _error;
|
||||
|
||||
bool _isInputCopied = false;
|
||||
bool _isOutputCopied = false;
|
||||
|
||||
late final AnimationController _glowController;
|
||||
late final Animation<double> _glowAnimation;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_glowController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(seconds: 3),
|
||||
)..repeat(reverse: true);
|
||||
_glowAnimation = Tween<double>(begin: 0.4, end: 1.0).animate(
|
||||
CurvedAnimation(parent: _glowController, curve: Curves.easeInOut),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_inputController.dispose();
|
||||
_outputController.dispose();
|
||||
_glowController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// ─── Logic (unchanged) ──────────────────────────────────────────────────────
|
||||
|
||||
Future<void> _callTool(String action) async {
|
||||
FocusScope.of(context).unfocus();
|
||||
|
||||
setState(() {
|
||||
_loading = true;
|
||||
_error = null;
|
||||
_output = '';
|
||||
_outputController.clear();
|
||||
_isInputCopied = false;
|
||||
_isOutputCopied = false;
|
||||
});
|
||||
|
||||
try {
|
||||
final response = await CRUD().post(
|
||||
link: '${AppLink.server}/ggg.php',
|
||||
payload: {
|
||||
'action': action,
|
||||
'text': _inputController.text,
|
||||
'admin_phone': box.read(BoxName.adminPhone) ?? '',
|
||||
},
|
||||
);
|
||||
|
||||
if (response == 'failure') {
|
||||
setState(() => _error = 'حدث خطأ في الاتصال بالخادم. حاول مرة أخرى.');
|
||||
} else {
|
||||
if (response['status'] == 'success') {
|
||||
setState(() {
|
||||
_output = (response['result'] ?? '').toString();
|
||||
_outputController.text = _output;
|
||||
});
|
||||
} else {
|
||||
setState(() =>
|
||||
_error = response['message']?.toString() ?? 'حدث خطأ غير معروف.');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
setState(() => _error = 'مشكلة في الشبكة: $e');
|
||||
} finally {
|
||||
setState(() => _loading = false);
|
||||
}
|
||||
}
|
||||
|
||||
void _showSnackBar(String message, {bool isError = false}) {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Row(
|
||||
children: [
|
||||
Icon(isError ? Icons.error_outline : Icons.check_circle,
|
||||
color: isError ? _AppColors.error : _AppColors.success),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
message,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Cairo',
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
backgroundColor:
|
||||
isError ? const Color(0xFF1A0808) : const Color(0xFF081A0F),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
side: BorderSide(
|
||||
color: isError ? _AppColors.error : _AppColors.success,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
margin: const EdgeInsets.all(16),
|
||||
duration: const Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _copyText(bool isInput) async {
|
||||
final textToCopy = isInput ? _inputController.text : _outputController.text;
|
||||
|
||||
if (textToCopy.isEmpty) {
|
||||
_showSnackBar('لا يوجد نص لنسخه!', isError: true);
|
||||
return;
|
||||
}
|
||||
|
||||
await Clipboard.setData(ClipboardData(text: textToCopy));
|
||||
|
||||
if (isInput) {
|
||||
setState(() => _isInputCopied = true);
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
if (mounted) setState(() => _isInputCopied = false);
|
||||
});
|
||||
} else {
|
||||
setState(() => _isOutputCopied = true);
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
if (mounted) setState(() => _isOutputCopied = false);
|
||||
});
|
||||
}
|
||||
|
||||
_showSnackBar('تم النسخ بنجاح!');
|
||||
}
|
||||
|
||||
Future<void> _pasteText(bool isInput) async {
|
||||
final clipboardData = await Clipboard.getData(Clipboard.kTextPlain);
|
||||
final textToPaste = clipboardData?.text ?? '';
|
||||
|
||||
if (textToPaste.isEmpty) {
|
||||
_showSnackBar('الحافظة فارغة!', isError: true);
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
if (isInput) {
|
||||
_inputController.text = textToPaste;
|
||||
} else {
|
||||
_output = textToPaste;
|
||||
_outputController.text = textToPaste;
|
||||
}
|
||||
});
|
||||
|
||||
_showSnackBar('تم اللصق بنجاح!');
|
||||
}
|
||||
|
||||
// ─── UI Helpers ─────────────────────────────────────────────────────────────
|
||||
|
||||
Widget _buildActionButtons({
|
||||
required bool isInput,
|
||||
required bool isCopied,
|
||||
Color accentColor = _AppColors.accent,
|
||||
}) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_MiniIconButton(
|
||||
label: 'لصق',
|
||||
icon: Icons.content_paste_rounded,
|
||||
color: accentColor,
|
||||
onTap: () => _pasteText(isInput),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
_MiniIconButton(
|
||||
label: isCopied ? 'تم!' : 'نسخ',
|
||||
icon: isCopied ? Icons.check_circle_rounded : Icons.copy_rounded,
|
||||
color: isCopied ? _AppColors.success : accentColor,
|
||||
onTap: () => _copyText(isInput),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
InputDecoration _buildInputDecoration(String hint) => InputDecoration(
|
||||
hintText: hint,
|
||||
hintStyle: const TextStyle(color: _AppColors.textSec, fontSize: 14),
|
||||
filled: true,
|
||||
fillColor: const Color(0xFF0C1120),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
borderSide: const BorderSide(color: _AppColors.border, width: 1),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
borderSide: const BorderSide(color: _AppColors.accent, width: 1.5),
|
||||
),
|
||||
contentPadding: const EdgeInsets.all(16),
|
||||
);
|
||||
|
||||
// ─── Build ──────────────────────────────────────────────────────────────────
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: _AppColors.bg,
|
||||
body: Stack(
|
||||
children: [
|
||||
// ── Ambient background glow ──────────────────────────────────────────
|
||||
Positioned(
|
||||
top: -120,
|
||||
left: -80,
|
||||
child: AnimatedBuilder(
|
||||
animation: _glowAnimation,
|
||||
builder: (_, __) => Opacity(
|
||||
opacity: _glowAnimation.value * 0.25,
|
||||
child: Container(
|
||||
width: 380,
|
||||
height: 380,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: RadialGradient(
|
||||
colors: [Color(0xFF00E5FF), Colors.transparent],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
bottom: -100,
|
||||
right: -60,
|
||||
child: AnimatedBuilder(
|
||||
animation: _glowAnimation,
|
||||
builder: (_, __) => Opacity(
|
||||
opacity: (1 - _glowAnimation.value) * 0.2,
|
||||
child: Container(
|
||||
width: 320,
|
||||
height: 320,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: RadialGradient(
|
||||
colors: [Color(0xFF7C4DFF), Colors.transparent],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// ── Content ──────────────────────────────────────────────────────────
|
||||
SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
// ── AppBar ─────────────────────────────────────────────────────
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(8, 8, 16, 0),
|
||||
child: Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.arrow_back_ios_new_rounded,
|
||||
color: _AppColors.textSec, size: 20),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
const Spacer(),
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: _AppColors.accent,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _AppColors.accentGlow,
|
||||
blurRadius: 8,
|
||||
spreadRadius: 2,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
const Text(
|
||||
'أداة التشفير',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _AppColors.textPrimary,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: _AppColors.accentGlow,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(
|
||||
color: _AppColors.accent.withOpacity(0.3)),
|
||||
),
|
||||
child: const Text(
|
||||
'AES-256',
|
||||
style: TextStyle(
|
||||
color: _AppColors.accent,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: 1.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// ── Scrollable body ───────────────────────────────────────────
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(20, 24, 20, 32),
|
||||
physics: const BouncingScrollPhysics(),
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 650),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// ─── Input Card ─────────────────────────────────────
|
||||
_GlassCard(
|
||||
borderColor: _AppColors.accent.withOpacity(0.2),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Header
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: _AppColors.accentGlow,
|
||||
borderRadius:
|
||||
BorderRadius.circular(10),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.text_fields_rounded,
|
||||
color: _AppColors.accent,
|
||||
size: 18),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Text(
|
||||
'النص الأصلي',
|
||||
style: TextStyle(
|
||||
color: _AppColors.textPrimary,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
_buildActionButtons(
|
||||
isInput: true,
|
||||
isCopied: _isInputCopied,
|
||||
accentColor: _AppColors.accent,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Input field
|
||||
TextField(
|
||||
controller: _inputController,
|
||||
maxLines: 5,
|
||||
minLines: 3,
|
||||
textDirection: TextDirection.ltr,
|
||||
style: const TextStyle(
|
||||
color: _AppColors.textPrimary,
|
||||
fontSize: 15,
|
||||
height: 1.6,
|
||||
fontFamily: 'monospace',
|
||||
),
|
||||
onTap: () {
|
||||
if (_inputController.text.isNotEmpty) {
|
||||
_inputController.selection =
|
||||
TextSelection(
|
||||
baseOffset: 0,
|
||||
extentOffset:
|
||||
_inputController.text.length,
|
||||
);
|
||||
}
|
||||
},
|
||||
decoration: _buildInputDecoration(
|
||||
'اكتب أو الصق النص هنا...'),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Action buttons row
|
||||
Row(
|
||||
children: [
|
||||
// Encrypt
|
||||
Expanded(
|
||||
child: _ActionButton(
|
||||
label: 'تشفير',
|
||||
icon: Icons.lock_rounded,
|
||||
isLoading: _loading,
|
||||
onPressed: _loading
|
||||
? null
|
||||
: () => _callTool('encrypt'),
|
||||
gradient: const LinearGradient(
|
||||
colors: [
|
||||
Color(0xFF00B4D8),
|
||||
Color(0xFF00E5FF)
|
||||
],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
glowColor: _AppColors.accentGlow,
|
||||
borderColor: _AppColors.accent,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
// Decrypt
|
||||
Expanded(
|
||||
child: _ActionButton(
|
||||
label: 'فك التشفير',
|
||||
icon: Icons.lock_open_rounded,
|
||||
isLoading: _loading,
|
||||
onPressed: _loading
|
||||
? null
|
||||
: () => _callTool('decrypt'),
|
||||
gradient: const LinearGradient(
|
||||
colors: [
|
||||
Color(0xFF5B2EA6),
|
||||
Color(0xFF7C4DFF)
|
||||
],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
glowColor:
|
||||
_AppColors.accentDecryptGlow,
|
||||
borderColor: _AppColors.accentDecrypt,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// ─── Error message ───────────────────────────────────
|
||||
AnimatedSize(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
child: _error != null
|
||||
? Container(
|
||||
margin: const EdgeInsets.only(top: 16),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF1A0808),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(
|
||||
color: _AppColors.error
|
||||
.withOpacity(0.4)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.error_outline_rounded,
|
||||
color: _AppColors.error,
|
||||
size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_error!,
|
||||
style: const TextStyle(
|
||||
color: _AppColors.error,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
|
||||
// ─── Output Card ─────────────────────────────────────
|
||||
const SizedBox(height: 20),
|
||||
_GlassCard(
|
||||
borderColor:
|
||||
_AppColors.accentDecrypt.withOpacity(0.25),
|
||||
headerWidget: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 20, vertical: 14),
|
||||
decoration: const BoxDecoration(
|
||||
color: Color(0xFF16102A),
|
||||
borderRadius: BorderRadius.vertical(
|
||||
top: Radius.circular(20)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: _AppColors.accentDecryptGlow,
|
||||
borderRadius:
|
||||
BorderRadius.circular(10),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.shield_rounded,
|
||||
color: _AppColors.accentDecrypt,
|
||||
size: 18),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Text(
|
||||
'النتيجة',
|
||||
style: TextStyle(
|
||||
color: _AppColors.textPrimary,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
_buildActionButtons(
|
||||
isInput: false,
|
||||
isCopied: _isOutputCopied,
|
||||
accentColor: _AppColors.accentDecrypt,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: TextField(
|
||||
controller: _outputController,
|
||||
readOnly: true,
|
||||
maxLines: 5,
|
||||
minLines: 3,
|
||||
textDirection: TextDirection.ltr,
|
||||
style: const TextStyle(
|
||||
color: _AppColors.textPrimary,
|
||||
fontSize: 15,
|
||||
height: 1.6,
|
||||
fontFamily: 'monospace',
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'ستظهر النتيجة هنا...',
|
||||
hintStyle: TextStyle(
|
||||
color: _AppColors.textSec,
|
||||
fontSize: 14),
|
||||
border: InputBorder.none,
|
||||
isDense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
onTap: () {
|
||||
if (_outputController.text.isNotEmpty) {
|
||||
_outputController.selection =
|
||||
TextSelection(
|
||||
baseOffset: 0,
|
||||
extentOffset:
|
||||
_outputController.text.length,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// ─── Footer hint ─────────────────────────────────────
|
||||
const SizedBox(height: 24),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.info_outline_rounded,
|
||||
color: _AppColors.textSec, size: 13),
|
||||
const SizedBox(width: 6),
|
||||
const Text(
|
||||
'البيانات مشفرة بالكامل ولا تُخزَّن على الخادم',
|
||||
style: TextStyle(
|
||||
color: _AppColors.textSec,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Reusable Widgets ──────────────────────────────────────────────────────────
|
||||
|
||||
/// Glass card with optional custom header widget
|
||||
class _GlassCard extends StatelessWidget {
|
||||
final Widget child;
|
||||
final Widget? headerWidget;
|
||||
final Color borderColor;
|
||||
|
||||
const _GlassCard({
|
||||
required this.child,
|
||||
this.headerWidget,
|
||||
this.borderColor = _AppColors.border,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: _AppColors.card,
|
||||
borderRadius: BorderRadius.circular(22),
|
||||
border: Border.all(color: borderColor, width: 1.2),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.35),
|
||||
blurRadius: 24,
|
||||
offset: const Offset(0, 8),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(22),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (headerWidget != null) headerWidget!,
|
||||
if (headerWidget == null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 20, 20, 0),
|
||||
child: child,
|
||||
)
|
||||
else
|
||||
child,
|
||||
if (headerWidget == null) const SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Gradient action button with glow
|
||||
class _ActionButton extends StatefulWidget {
|
||||
final String label;
|
||||
final IconData icon;
|
||||
final bool isLoading;
|
||||
final VoidCallback? onPressed;
|
||||
final Gradient gradient;
|
||||
final Color glowColor;
|
||||
final Color borderColor;
|
||||
|
||||
const _ActionButton({
|
||||
required this.label,
|
||||
required this.icon,
|
||||
required this.isLoading,
|
||||
required this.onPressed,
|
||||
required this.gradient,
|
||||
required this.glowColor,
|
||||
required this.borderColor,
|
||||
});
|
||||
|
||||
@override
|
||||
State<_ActionButton> createState() => _ActionButtonState();
|
||||
}
|
||||
|
||||
class _ActionButtonState extends State<_ActionButton>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _ctrl;
|
||||
late final Animation<double> _scale;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_ctrl = AnimationController(
|
||||
vsync: this, duration: const Duration(milliseconds: 120));
|
||||
_scale = Tween<double>(begin: 1.0, end: 0.95)
|
||||
.animate(CurvedAnimation(parent: _ctrl, curve: Curves.easeOut));
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_ctrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTapDown: (_) => _ctrl.forward(),
|
||||
onTapUp: (_) => _ctrl.reverse(),
|
||||
onTapCancel: () => _ctrl.reverse(),
|
||||
onTap: widget.onPressed,
|
||||
child: AnimatedBuilder(
|
||||
animation: _scale,
|
||||
builder: (_, child) =>
|
||||
Transform.scale(scale: _scale.value, child: child),
|
||||
child: AnimatedOpacity(
|
||||
opacity: widget.onPressed == null ? 0.4 : 1.0,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
decoration: BoxDecoration(
|
||||
gradient: widget.gradient,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: widget.glowColor,
|
||||
blurRadius: 16,
|
||||
spreadRadius: 1,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: widget.isLoading
|
||||
? [
|
||||
const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white, strokeWidth: 2),
|
||||
),
|
||||
]
|
||||
: [
|
||||
Icon(widget.icon, color: Colors.white, size: 18),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
widget.label,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: 0.3,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Small inline icon button (copy/paste)
|
||||
class _MiniIconButton extends StatelessWidget {
|
||||
final String label;
|
||||
final IconData icon;
|
||||
final Color color;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _MiniIconButton({
|
||||
required this.label,
|
||||
required this.icon,
|
||||
required this.color,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: color.withOpacity(0.25)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, color: color, size: 14),
|
||||
const SizedBox(width: 5),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
355
lib/views/admin/enceypt/fingerprint_migration.dart
Normal file
355
lib/views/admin/enceypt/fingerprint_migration.dart
Normal file
@@ -0,0 +1,355 @@
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// fingerprint_migration.dart
|
||||
// ───────────────────────────────────────────────────────────────
|
||||
// أداة ترحيل البصمات القديمة للنظام الجديد
|
||||
// ───────────────────────────────────────────────────────────────
|
||||
// المشكلة:
|
||||
// البصمة القديمة = encrypt(androidId_model_osVersion)
|
||||
// البصمة الجديدة = encrypt(androidId_model)
|
||||
//
|
||||
// الحل:
|
||||
// 1. نجيب كل البصمات من السيرفر (batch 50 في المرة)
|
||||
// 2. نفك تشفير كل بصمة بـ EncryptionHelper
|
||||
// 3. نحذف آخر جزء (osVersion) مع الـ _ قبله
|
||||
// 4. نعيد التشفير
|
||||
// 5. نرفع البصمة المحدّثة للسيرفر
|
||||
//
|
||||
// يُستخدم مرة واحدة فقط ثم يُحذف من التطبيق
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../../constant/links.dart';
|
||||
import '../../../controller/functions/crud.dart';
|
||||
import '../../../controller/functions/encrypt_decrypt.dart';
|
||||
import '../../../print.dart';
|
||||
|
||||
class FingerprintMigrationTool extends StatefulWidget {
|
||||
const FingerprintMigrationTool({super.key});
|
||||
|
||||
@override
|
||||
State<FingerprintMigrationTool> createState() =>
|
||||
_FingerprintMigrationToolState();
|
||||
}
|
||||
|
||||
class _FingerprintMigrationToolState extends State<FingerprintMigrationTool> {
|
||||
// ── حالة الترحيل ──────────────────────────────────────────
|
||||
bool _isRunning = false;
|
||||
bool _isDone = false;
|
||||
int _total = 0;
|
||||
int _processed = 0;
|
||||
int _updated = 0; // بصمات تم تحديثها
|
||||
int _skipped = 0; // بصمات كانت بالفعل بالنظام الجديد
|
||||
int _failed = 0; // فشل في المعالجة
|
||||
String _currentLog = '';
|
||||
|
||||
static const int _batchSize = 50;
|
||||
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
// الدالة الرئيسية للترحيل
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
Future<void> _startMigration() async {
|
||||
setState(() {
|
||||
_isRunning = true;
|
||||
_isDone = false;
|
||||
_processed = 0;
|
||||
_updated = 0;
|
||||
_skipped = 0;
|
||||
_failed = 0;
|
||||
_currentLog = 'جارٍ جلب البصمات من السيرفر...';
|
||||
});
|
||||
|
||||
try {
|
||||
// ── 1. جلب كل البصمات من السيرفر ──────────────────────
|
||||
final allFingerprints = await _fetchAllFingerprints();
|
||||
|
||||
if (allFingerprints == null) {
|
||||
_log('❌ فشل في جلب البيانات من السيرفر');
|
||||
setState(() => _isRunning = false);
|
||||
return;
|
||||
}
|
||||
|
||||
_total = allFingerprints.length;
|
||||
_log('✅ تم جلب $_total بصمة — بدء المعالجة...');
|
||||
|
||||
// ── 2. معالجة على batches ──────────────────────────────
|
||||
for (int i = 0; i < allFingerprints.length; i += _batchSize) {
|
||||
final batch = allFingerprints.skip(i).take(_batchSize).toList();
|
||||
|
||||
_log('⚙️ معالجة ${i + 1} → ${i + batch.length} من $_total');
|
||||
|
||||
// معالجة الـ batch بالتوازي
|
||||
await Future.wait(
|
||||
batch.map((record) => _processSingleRecord(record)),
|
||||
);
|
||||
|
||||
// استراحة قصيرة بين الـ batches لحماية السيرفر
|
||||
if (i + _batchSize < allFingerprints.length) {
|
||||
await Future.delayed(const Duration(milliseconds: 300));
|
||||
}
|
||||
}
|
||||
|
||||
_log('🎉 اكتمل الترحيل!\n'
|
||||
'محدَّث: $_updated | متجاوز: $_skipped | فاشل: $_failed');
|
||||
|
||||
setState(() {
|
||||
_isDone = true;
|
||||
_isRunning = false;
|
||||
});
|
||||
} catch (e) {
|
||||
_log('❌ خطأ عام: $e');
|
||||
setState(() => _isRunning = false);
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
// جلب كل البصمات من السيرفر
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
Future<List<Map<String, dynamic>>?> _fetchAllFingerprints() async {
|
||||
try {
|
||||
final response = await CRUD().post(
|
||||
link: AppLink.getAllFingerprints, // أضفه في AppLink
|
||||
payload: {
|
||||
'admin_key': 'iuyweiruinakjbfkajkjlkmalkcxnlahd'
|
||||
}, // مفتاح أمان للـ endpoint
|
||||
);
|
||||
|
||||
if (response == 'failure' || response == null) return null;
|
||||
|
||||
final data = response['data'];
|
||||
if (data is! List) return null;
|
||||
|
||||
return List<Map<String, dynamic>>.from(data);
|
||||
} catch (e) {
|
||||
Log.print('fetchAllFingerprints error: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
// معالجة بصمة واحدة
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
Future<void> _processSingleRecord(Map<String, dynamic> record) async {
|
||||
final String passengerID = record['passengerID']?.toString() ?? '';
|
||||
final String encryptedFp = record['fingerPrint']?.toString() ?? '';
|
||||
final String userType = record['userType']?.toString() ?? 'passenger';
|
||||
|
||||
if (passengerID.isEmpty || encryptedFp.isEmpty) {
|
||||
setState(() {
|
||||
_failed++;
|
||||
_processed++;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// ── فك التشفير ────────────────────────────────────────
|
||||
final String rawFp = EncryptionHelper.instance.decryptData(encryptedFp);
|
||||
|
||||
// ── تحليل البصمة ──────────────────────────────────────
|
||||
// الشكل القديم: "androidId_model_osVersion" (3 أجزاء أو أكثر)
|
||||
// الشكل الجديد: "androidId_model" (جزءان فقط)
|
||||
final List<String> parts = rawFp.split('_');
|
||||
|
||||
if (parts.length <= 2) {
|
||||
// البصمة بالفعل بالنظام الجديد — تجاوزها
|
||||
setState(() {
|
||||
_skipped++;
|
||||
_processed++;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// ── حذف آخر جزء (osVersion) ──────────────────────────
|
||||
// مثال: "abc123_SamsungA51_13" → "abc123_SamsungA51"
|
||||
// نأخذ أول جزأين فقط بغض النظر عن عدد الأجزاء
|
||||
final String newRawFp = '${parts[0]}_${parts[1]}';
|
||||
|
||||
// ── إعادة التشفير ─────────────────────────────────────
|
||||
final String newEncryptedFp =
|
||||
EncryptionHelper.instance.encryptData(newRawFp);
|
||||
|
||||
// ── رفع البصمة الجديدة للسيرفر ───────────────────────
|
||||
final response = await CRUD().post(
|
||||
link: AppLink.updateFingerprintAdmin, // أضفه في AppLink
|
||||
payload: {
|
||||
'passengerID': passengerID,
|
||||
'fingerprint': newEncryptedFp,
|
||||
'userType': userType,
|
||||
'admin_key': 'iuyweiruinakjbfkajkjlkmalkcxnlahd',
|
||||
},
|
||||
);
|
||||
|
||||
if (response != 'failure' && response?['status'] == 'success') {
|
||||
setState(() {
|
||||
_updated++;
|
||||
_processed++;
|
||||
});
|
||||
Log.print('✅ Updated: $passengerID | $rawFp → $newRawFp');
|
||||
} else {
|
||||
setState(() {
|
||||
_failed++;
|
||||
_processed++;
|
||||
});
|
||||
Log.print('❌ Failed update: $passengerID');
|
||||
}
|
||||
} catch (e) {
|
||||
// فشل فك التشفير أو إعادة التشفير
|
||||
setState(() {
|
||||
_failed++;
|
||||
_processed++;
|
||||
});
|
||||
Log.print('❌ Process error for $passengerID: $e');
|
||||
}
|
||||
}
|
||||
|
||||
void _log(String message) {
|
||||
Log.print(message);
|
||||
setState(() => _currentLog = message);
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
// UI
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Fingerprint Migration Tool')),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// ── شرح الأداة ──────────────────────────────────
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orange.shade50,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: Colors.orange.shade200),
|
||||
),
|
||||
child: const Text(
|
||||
'⚠️ هذه الأداة تُستخدم مرة واحدة فقط\n'
|
||||
'تقوم بتحديث بصمات الأجهزة القديمة\n'
|
||||
'لتكون متوافقة مع النظام الجديد (بدون OS version)',
|
||||
style: TextStyle(fontSize: 14, height: 1.6),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
print(EncryptionHelper.instance.decryptData(
|
||||
'dab40749cdecbfddf4696566448b384f0d272705b08b4ff779e085fbf3257026'));
|
||||
},
|
||||
child: Text(
|
||||
"Decrypt Test",
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
print(EncryptionHelper.instance.encryptData(
|
||||
'1B501143-C579-461C-B556-4E8B390EEFE1_iPhone'));
|
||||
},
|
||||
child: Text(
|
||||
"Encrypt Test",
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// ── شريط التقدم ─────────────────────────────────
|
||||
if (_total > 0) ...[
|
||||
Text('التقدم: $_processed / $_total'),
|
||||
const SizedBox(height: 8),
|
||||
LinearProgressIndicator(
|
||||
value: _total > 0 ? _processed / _total : 0,
|
||||
backgroundColor: Colors.grey.shade200,
|
||||
color: _isDone ? Colors.green : Colors.blue,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
|
||||
// ── إحصائيات ────────────────────────────────────
|
||||
if (_processed > 0)
|
||||
Row(children: [
|
||||
_statChip('محدَّث', _updated, Colors.green),
|
||||
const SizedBox(width: 8),
|
||||
_statChip('متجاوز', _skipped, Colors.blue),
|
||||
const SizedBox(width: 8),
|
||||
_statChip('فاشل', _failed, Colors.red),
|
||||
]),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// ── السجل الحالي ─────────────────────────────────
|
||||
if (_currentLog.isNotEmpty)
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade100,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(_currentLog,
|
||||
style: const TextStyle(fontFamily: 'monospace')),
|
||||
),
|
||||
|
||||
const Spacer(),
|
||||
|
||||
// ── زر التشغيل ──────────────────────────────────
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 50,
|
||||
child: ElevatedButton(
|
||||
onPressed: (_isRunning || _isDone) ? null : _startMigration,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: _isDone ? Colors.green : Colors.blue,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
),
|
||||
child: _isRunning
|
||||
? const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white, strokeWidth: 2),
|
||||
),
|
||||
SizedBox(width: 12),
|
||||
Text('جارٍ الترحيل...',
|
||||
style: TextStyle(color: Colors.white)),
|
||||
],
|
||||
)
|
||||
: Text(
|
||||
_isDone ? '✅ اكتمل الترحيل' : 'بدء الترحيل',
|
||||
style:
|
||||
const TextStyle(color: Colors.white, fontSize: 16),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _statChip(String label, int value, Color color) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: color.withOpacity(0.3)),
|
||||
),
|
||||
child: Text('$label: $value',
|
||||
style: TextStyle(color: color, fontWeight: FontWeight.bold)),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user