Attendance validation involving Location Detection + Facial Recoginition with Liveness Detection
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
@@ -92,6 +93,64 @@ class ProfileController {
|
||||
}
|
||||
await _client.auth.updateUser(UserAttributes(password: password));
|
||||
}
|
||||
|
||||
/// Upload a profile avatar image and update the profile record.
|
||||
Future<String> uploadAvatar({
|
||||
required String userId,
|
||||
required Uint8List bytes,
|
||||
required String fileName,
|
||||
}) async {
|
||||
final ext = fileName.split('.').last.toLowerCase();
|
||||
final path = '$userId/avatar.$ext';
|
||||
await _client.storage
|
||||
.from('avatars')
|
||||
.uploadBinary(
|
||||
path,
|
||||
bytes,
|
||||
fileOptions: const FileOptions(upsert: true),
|
||||
);
|
||||
final url = _client.storage.from('avatars').getPublicUrl(path);
|
||||
await _client.from('profiles').update({'avatar_url': url}).eq('id', userId);
|
||||
return url;
|
||||
}
|
||||
|
||||
/// Upload a face enrollment photo and update the profile record.
|
||||
Future<String> uploadFacePhoto({
|
||||
required String userId,
|
||||
required Uint8List bytes,
|
||||
required String fileName,
|
||||
}) async {
|
||||
final ext = fileName.split('.').last.toLowerCase();
|
||||
final path = '$userId/face.$ext';
|
||||
await _client.storage
|
||||
.from('face-enrollment')
|
||||
.uploadBinary(
|
||||
path,
|
||||
bytes,
|
||||
fileOptions: const FileOptions(upsert: true),
|
||||
);
|
||||
final url = _client.storage.from('face-enrollment').getPublicUrl(path);
|
||||
await _client
|
||||
.from('profiles')
|
||||
.update({
|
||||
'face_photo_url': url,
|
||||
'face_enrolled_at': DateTime.now().toUtc().toIso8601String(),
|
||||
})
|
||||
.eq('id', userId);
|
||||
return url;
|
||||
}
|
||||
|
||||
/// Download the face enrollment photo bytes for the given user.
|
||||
/// Uses Supabase authenticated storage API (works with private buckets).
|
||||
Future<Uint8List?> downloadFacePhoto(String userId) async {
|
||||
try {
|
||||
return await _client.storage
|
||||
.from('face-enrollment')
|
||||
.download('$userId/face.jpg');
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final isAdminProvider = Provider<bool>((ref) {
|
||||
|
||||
Reference in New Issue
Block a user