attendence login/logout has been implemented
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
import 'package:coda_project/data/datasources/attendance_remote_data_source.dart';
|
||||||
|
import 'package:coda_project/data/repositories/attendance_repository_impl.dart';
|
||||||
|
import 'package:coda_project/domain/repositories/attendance_repository.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:get_it/get_it.dart';
|
import 'package:get_it/get_it.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
@@ -7,6 +10,8 @@ import '../../data/datasources/user_local_data_source.dart';
|
|||||||
import '../../data/repositories/auth_repository_impl.dart';
|
import '../../data/repositories/auth_repository_impl.dart';
|
||||||
import '../../domain/repositories/auth_repository.dart';
|
import '../../domain/repositories/auth_repository.dart';
|
||||||
import '../../domain/usecases/login_usecase.dart';
|
import '../../domain/usecases/login_usecase.dart';
|
||||||
|
import '../../domain/usecases/attendance_login_usecase.dart';
|
||||||
|
import '../../domain/usecases/attendance_logout_usecase.dart';
|
||||||
import '../../presentation/blocs/login/login_bloc.dart';
|
import '../../presentation/blocs/login/login_bloc.dart';
|
||||||
|
|
||||||
final sl = GetIt.instance;
|
final sl = GetIt.instance;
|
||||||
@@ -14,7 +19,7 @@ final sl = GetIt.instance;
|
|||||||
Future<void> initializeDependencies() async {
|
Future<void> initializeDependencies() async {
|
||||||
// External
|
// External
|
||||||
sl.registerLazySingleton<Dio>(() => Dio());
|
sl.registerLazySingleton<Dio>(() => Dio());
|
||||||
|
|
||||||
// SharedPreferences
|
// SharedPreferences
|
||||||
final sharedPreferences = await SharedPreferences.getInstance();
|
final sharedPreferences = await SharedPreferences.getInstance();
|
||||||
sl.registerLazySingleton<SharedPreferences>(() => sharedPreferences);
|
sl.registerLazySingleton<SharedPreferences>(() => sharedPreferences);
|
||||||
@@ -28,17 +33,14 @@ Future<void> initializeDependencies() async {
|
|||||||
sl.registerLazySingleton<AuthRemoteDataSource>(
|
sl.registerLazySingleton<AuthRemoteDataSource>(
|
||||||
() => AuthRemoteDataSourceImpl(apiClient: sl()),
|
() => AuthRemoteDataSourceImpl(apiClient: sl()),
|
||||||
);
|
);
|
||||||
|
|
||||||
sl.registerLazySingleton<UserLocalDataSource>(
|
sl.registerLazySingleton<UserLocalDataSource>(
|
||||||
() => UserLocalDataSourceImpl(sharedPreferences: sl()),
|
() => UserLocalDataSourceImpl(sharedPreferences: sl()),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Repositories
|
// Repositories
|
||||||
sl.registerLazySingleton<AuthRepository>(
|
sl.registerLazySingleton<AuthRepository>(
|
||||||
() => AuthRepositoryImpl(
|
() => AuthRepositoryImpl(remoteDataSource: sl(), localDataSource: sl()),
|
||||||
remoteDataSource: sl(),
|
|
||||||
localDataSource: sl(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Use cases
|
// Use cases
|
||||||
@@ -46,4 +48,17 @@ Future<void> initializeDependencies() async {
|
|||||||
|
|
||||||
// Blocs
|
// Blocs
|
||||||
sl.registerFactory(() => LoginBloc(loginUseCase: sl()));
|
sl.registerFactory(() => LoginBloc(loginUseCase: sl()));
|
||||||
|
|
||||||
|
//Attendence
|
||||||
|
sl.registerLazySingleton<AttendanceRemoteDataSource>(
|
||||||
|
() => AttendanceRemoteDataSourceImpl(apiClient: sl()),
|
||||||
|
);
|
||||||
|
|
||||||
|
sl.registerLazySingleton<AttendanceRepository>(
|
||||||
|
() => AttendanceRepositoryImpl(remoteDataSource: sl()),
|
||||||
|
);
|
||||||
|
|
||||||
|
sl.registerLazySingleton(() => AttendanceLoginUsecase(repository: sl()));
|
||||||
|
|
||||||
|
sl.registerLazySingleton(() => AttendanceLogoutUseCase(repository: sl()));
|
||||||
}
|
}
|
||||||
|
|||||||
58
lib/data/datasources/attendance_remote_data_source.dart
Normal file
58
lib/data/datasources/attendance_remote_data_source.dart
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import '../../core/network/api_client.dart';
|
||||||
|
import '../dto/attendance_response_dto.dart';
|
||||||
|
|
||||||
|
abstract class AttendanceRemoteDataSource {
|
||||||
|
Future<AttendanceResponseDto> login({
|
||||||
|
required String employeeId,
|
||||||
|
required File faceImage,
|
||||||
|
});
|
||||||
|
|
||||||
|
Future<AttendanceResponseDto> logout({
|
||||||
|
required String employeeId,
|
||||||
|
required File faceImage,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class AttendanceRemoteDataSourceImpl implements AttendanceRemoteDataSource {
|
||||||
|
final ApiClient apiClient;
|
||||||
|
|
||||||
|
AttendanceRemoteDataSourceImpl({required this.apiClient});
|
||||||
|
@override
|
||||||
|
Future<AttendanceResponseDto> login({
|
||||||
|
required String employeeId,
|
||||||
|
required File faceImage,
|
||||||
|
}) async {
|
||||||
|
final formData = FormData.fromMap({
|
||||||
|
'EmployeeId': employeeId,
|
||||||
|
'FaceImage': await MultipartFile.fromFile(faceImage.path),
|
||||||
|
});
|
||||||
|
|
||||||
|
final response = await apiClient.post(
|
||||||
|
'/Attendance/login',
|
||||||
|
data: formData,
|
||||||
|
options: Options(contentType: 'multipart/form-data'),
|
||||||
|
);
|
||||||
|
return AttendanceResponseDto.fromJson(response.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<AttendanceResponseDto> logout({
|
||||||
|
required String employeeId,
|
||||||
|
required File faceImage,
|
||||||
|
}) async {
|
||||||
|
final formData = FormData.fromMap({
|
||||||
|
'EmployeeId': employeeId,
|
||||||
|
'FaceImage': await MultipartFile.fromFile(faceImage.path),
|
||||||
|
});
|
||||||
|
|
||||||
|
final response = await apiClient.post(
|
||||||
|
'/Attendance/logout',
|
||||||
|
data: formData,
|
||||||
|
options: Options(contentType: 'multipart/form-data'),
|
||||||
|
);
|
||||||
|
|
||||||
|
return AttendanceResponseDto.fromJson(response.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,10 +16,7 @@ class AuthRemoteDataSourceImpl implements AuthRemoteDataSource {
|
|||||||
@override
|
@override
|
||||||
Future<LoginResponseDto> login(LoginDto dto) async {
|
Future<LoginResponseDto> login(LoginDto dto) async {
|
||||||
try {
|
try {
|
||||||
final response = await apiClient.post(
|
final response = await apiClient.post('/Auth/login', data: dto.toJson());
|
||||||
'/Auth/login',
|
|
||||||
data: dto.toJson(),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||||
final responseData = response.data;
|
final responseData = response.data;
|
||||||
@@ -47,7 +44,8 @@ class AuthRemoteDataSourceImpl implements AuthRemoteDataSource {
|
|||||||
} else if (e.response?.statusCode == 500) {
|
} else if (e.response?.statusCode == 500) {
|
||||||
throw ServerException(message: 'خطأ في الخادم يرجى المحاولة لاحقا');
|
throw ServerException(message: 'خطأ في الخادم يرجى المحاولة لاحقا');
|
||||||
} else if (e.response != null) {
|
} else if (e.response != null) {
|
||||||
final message = e.response?.data?['message'] ??
|
final message =
|
||||||
|
e.response?.data?['message'] ??
|
||||||
e.response?.data?['error'] ??
|
e.response?.data?['error'] ??
|
||||||
'فشل تسجيل الدخول';
|
'فشل تسجيل الدخول';
|
||||||
|
|
||||||
@@ -57,8 +55,8 @@ class AuthRemoteDataSourceImpl implements AuthRemoteDataSource {
|
|||||||
message.toString().toLowerCase().contains('incorrect')
|
message.toString().toLowerCase().contains('incorrect')
|
||||||
? 'رقم الهاتف أو كلمة المرور غير صحيحة'
|
? 'رقم الهاتف أو كلمة المرور غير صحيحة'
|
||||||
: message.toString().toLowerCase().contains('not found')
|
: message.toString().toLowerCase().contains('not found')
|
||||||
? 'المستخدم غير موجود'
|
? 'المستخدم غير موجود'
|
||||||
: message;
|
: message;
|
||||||
|
|
||||||
throw ServerException(
|
throw ServerException(
|
||||||
message: customMessage,
|
message: customMessage,
|
||||||
|
|||||||
@@ -4,11 +4,14 @@ abstract class UserLocalDataSource {
|
|||||||
Future<void> cacheUserToken(String token);
|
Future<void> cacheUserToken(String token);
|
||||||
Future<String?> getCachedUserToken();
|
Future<String?> getCachedUserToken();
|
||||||
Future<void> clearCache();
|
Future<void> clearCache();
|
||||||
|
Future<void> cacheEmployeeId(String id);
|
||||||
|
Future<String?> getCachedEmployeeId();
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserLocalDataSourceImpl implements UserLocalDataSource {
|
class UserLocalDataSourceImpl implements UserLocalDataSource {
|
||||||
final SharedPreferences sharedPreferences;
|
final SharedPreferences sharedPreferences;
|
||||||
static const String _tokenKey = 'user_token';
|
static const String _tokenKey = 'user_token';
|
||||||
|
static const String _employeeIdKey = 'employee_id';
|
||||||
|
|
||||||
UserLocalDataSourceImpl({required this.sharedPreferences});
|
UserLocalDataSourceImpl({required this.sharedPreferences});
|
||||||
|
|
||||||
@@ -25,5 +28,16 @@ class UserLocalDataSourceImpl implements UserLocalDataSource {
|
|||||||
@override
|
@override
|
||||||
Future<void> clearCache() async {
|
Future<void> clearCache() async {
|
||||||
await sharedPreferences.remove(_tokenKey);
|
await sharedPreferences.remove(_tokenKey);
|
||||||
|
await sharedPreferences.remove(_employeeIdKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> cacheEmployeeId(String id) async {
|
||||||
|
await sharedPreferences.setString(_employeeIdKey, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<String?> getCachedEmployeeId() async {
|
||||||
|
return sharedPreferences.getString(_employeeIdKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
lib/data/dto/attendance_response_dto.dart
Normal file
24
lib/data/dto/attendance_response_dto.dart
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
class AttendanceResponseDto {
|
||||||
|
final String id;
|
||||||
|
final String employeeId;
|
||||||
|
final DateTime? login;
|
||||||
|
final DateTime? logout;
|
||||||
|
|
||||||
|
AttendanceResponseDto({
|
||||||
|
required this.id,
|
||||||
|
required this.employeeId,
|
||||||
|
this.login,
|
||||||
|
this.logout,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory AttendanceResponseDto.fromJson(Map<String, dynamic> json) {
|
||||||
|
final data = json['data'];
|
||||||
|
|
||||||
|
return AttendanceResponseDto(
|
||||||
|
id: data['id'],
|
||||||
|
employeeId: data['employeeId'],
|
||||||
|
login: data['login'],
|
||||||
|
logout: data['logout'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -57,15 +57,17 @@ class LoginDataDto {
|
|||||||
return LoginDataDto(
|
return LoginDataDto(
|
||||||
token: json['token'],
|
token: json['token'],
|
||||||
id: json['id'],
|
id: json['id'],
|
||||||
employeeId: json['employeeId'],
|
employeeId:
|
||||||
|
json['employeeId'] ?? json['EmployeeId'] ?? json['employee_id'],
|
||||||
username: json['username'],
|
username: json['username'],
|
||||||
fullName: json['fullName'],
|
fullName: json['fullName'],
|
||||||
role: json['role'],
|
role: json['role'],
|
||||||
email: json['email'],
|
email: json['email'],
|
||||||
phoneNumber: json['phoneNumber'],
|
phoneNumber: json['phoneNumber'],
|
||||||
permissions: json['permissions'] != null
|
permissions:
|
||||||
? List<String>.from(json['permissions'])
|
json['permissions'] != null
|
||||||
: null,
|
? List<String>.from(json['permissions'])
|
||||||
|
: null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
41
lib/data/repositories/attendance_repository_impl.dart
Normal file
41
lib/data/repositories/attendance_repository_impl.dart
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import '../../domain/models/attendance_login_request.dart';
|
||||||
|
import '../../domain/models/attendance_logout_request.dart';
|
||||||
|
import '../../domain/models/attendance_response_model.dart';
|
||||||
|
import '../../domain/repositories/attendance_repository.dart';
|
||||||
|
import '../datasources/attendance_remote_data_source.dart';
|
||||||
|
|
||||||
|
class AttendanceRepositoryImpl implements AttendanceRepository {
|
||||||
|
final AttendanceRemoteDataSource remoteDataSource;
|
||||||
|
|
||||||
|
AttendanceRepositoryImpl({required this.remoteDataSource});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<AttendanceResponseModel> login(AttendanceLoginRequest request) async {
|
||||||
|
final dto = await remoteDataSource.login(
|
||||||
|
employeeId: request.employeeId,
|
||||||
|
faceImage: request.faceImage,
|
||||||
|
);
|
||||||
|
|
||||||
|
return AttendanceResponseModel(
|
||||||
|
id: dto.id,
|
||||||
|
employeeId: dto.employeeId,
|
||||||
|
login: dto.login,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<AttendanceResponseModel> logout(
|
||||||
|
AttendanceLogoutRequest request,
|
||||||
|
) async {
|
||||||
|
final dto = await remoteDataSource.logout(
|
||||||
|
employeeId: request.employeeId,
|
||||||
|
faceImage: request.faceImage,
|
||||||
|
);
|
||||||
|
|
||||||
|
return AttendanceResponseModel(
|
||||||
|
id: dto.id,
|
||||||
|
employeeId: dto.employeeId,
|
||||||
|
logout: dto.logout,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@ import '../../core/error/failures.dart';
|
|||||||
import '../datasources/auth_remote_data_source.dart';
|
import '../datasources/auth_remote_data_source.dart';
|
||||||
import '../datasources/user_local_data_source.dart';
|
import '../datasources/user_local_data_source.dart';
|
||||||
import '../dto/login_dto.dart';
|
import '../dto/login_dto.dart';
|
||||||
import '../dto/login_response_dto.dart';
|
|
||||||
import '../../domain/models/login_request.dart';
|
import '../../domain/models/login_request.dart';
|
||||||
import '../../domain/models/login_response_model.dart';
|
import '../../domain/models/login_response_model.dart';
|
||||||
import '../../domain/repositories/auth_repository.dart';
|
import '../../domain/repositories/auth_repository.dart';
|
||||||
@@ -19,7 +18,9 @@ class AuthRepositoryImpl implements AuthRepository {
|
|||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Either<Failure, LoginResponseModel>> login(LoginRequest request) async {
|
Future<Either<Failure, LoginResponseModel>> login(
|
||||||
|
LoginRequest request,
|
||||||
|
) async {
|
||||||
try {
|
try {
|
||||||
final dto = LoginDto(
|
final dto = LoginDto(
|
||||||
phoneNumber: request.phoneNumber,
|
phoneNumber: request.phoneNumber,
|
||||||
@@ -27,30 +28,38 @@ class AuthRepositoryImpl implements AuthRepository {
|
|||||||
);
|
);
|
||||||
|
|
||||||
final responseDto = await remoteDataSource.login(dto);
|
final responseDto = await remoteDataSource.login(dto);
|
||||||
|
print("LOGIN RESPONSE DATA: ${responseDto.toJson()}"); // Debugging Log
|
||||||
|
|
||||||
// Cache the token locally
|
// Cache the token locally
|
||||||
if (responseDto.data?.token != null) {
|
if (responseDto.data?.token != null) {
|
||||||
await localDataSource.cacheUserToken(responseDto.data!.token!);
|
await localDataSource.cacheUserToken(responseDto.data!.token!);
|
||||||
}
|
}
|
||||||
|
if (responseDto.data?.employeeId != null) {
|
||||||
|
print("AUTH_REPO: Caching EmployeeId: ${responseDto.data!.employeeId}");
|
||||||
|
await localDataSource.cacheEmployeeId(responseDto.data!.employeeId!);
|
||||||
|
} else {
|
||||||
|
print("AUTH_REPO: EmployeeId is NULL in response!");
|
||||||
|
}
|
||||||
|
|
||||||
// Convert DTO to Model
|
// Convert DTO to Model
|
||||||
final responseModel = LoginResponseModel(
|
final responseModel = LoginResponseModel(
|
||||||
statusCode: responseDto.statusCode,
|
statusCode: responseDto.statusCode,
|
||||||
isSuccess: responseDto.isSuccess,
|
isSuccess: responseDto.isSuccess,
|
||||||
message: responseDto.message,
|
message: responseDto.message,
|
||||||
data: responseDto.data != null
|
data:
|
||||||
? LoginDataModel(
|
responseDto.data != null
|
||||||
token: responseDto.data!.token,
|
? LoginDataModel(
|
||||||
id: responseDto.data!.id,
|
token: responseDto.data!.token,
|
||||||
employeeId: responseDto.data!.employeeId,
|
id: responseDto.data!.id,
|
||||||
username: responseDto.data!.username,
|
employeeId: responseDto.data!.employeeId,
|
||||||
fullName: responseDto.data!.fullName,
|
username: responseDto.data!.username,
|
||||||
role: responseDto.data!.role,
|
fullName: responseDto.data!.fullName,
|
||||||
email: responseDto.data!.email,
|
role: responseDto.data!.role,
|
||||||
phoneNumber: responseDto.data!.phoneNumber,
|
email: responseDto.data!.email,
|
||||||
permissions: responseDto.data!.permissions,
|
phoneNumber: responseDto.data!.phoneNumber,
|
||||||
)
|
permissions: responseDto.data!.permissions,
|
||||||
: null,
|
)
|
||||||
|
: null,
|
||||||
);
|
);
|
||||||
|
|
||||||
return Right(responseModel);
|
return Right(responseModel);
|
||||||
|
|||||||
8
lib/domain/models/attendance_login_request.dart
Normal file
8
lib/domain/models/attendance_login_request.dart
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
class AttendanceLoginRequest {
|
||||||
|
final String employeeId;
|
||||||
|
final File faceImage;
|
||||||
|
|
||||||
|
AttendanceLoginRequest({required this.employeeId, required this.faceImage});
|
||||||
|
}
|
||||||
8
lib/domain/models/attendance_logout_request.dart
Normal file
8
lib/domain/models/attendance_logout_request.dart
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
class AttendanceLogoutRequest {
|
||||||
|
final String employeeId;
|
||||||
|
final File faceImage;
|
||||||
|
|
||||||
|
AttendanceLogoutRequest({required this.employeeId, required this.faceImage});
|
||||||
|
}
|
||||||
13
lib/domain/models/attendance_response_model.dart
Normal file
13
lib/domain/models/attendance_response_model.dart
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
class AttendanceResponseModel {
|
||||||
|
final String id;
|
||||||
|
final String employeeId;
|
||||||
|
final DateTime? login;
|
||||||
|
final DateTime? logout;
|
||||||
|
|
||||||
|
AttendanceResponseModel({
|
||||||
|
required this.id,
|
||||||
|
required this.employeeId,
|
||||||
|
this.login,
|
||||||
|
this.logout,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -2,8 +2,5 @@ class LoginRequest {
|
|||||||
final String phoneNumber;
|
final String phoneNumber;
|
||||||
final String password;
|
final String password;
|
||||||
|
|
||||||
LoginRequest({
|
LoginRequest({required this.phoneNumber, required this.password});
|
||||||
required this.phoneNumber,
|
|
||||||
required this.password,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
12
lib/domain/repositories/attendance_repository.dart
Normal file
12
lib/domain/repositories/attendance_repository.dart
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import '../models/attendance_login_request.dart';
|
||||||
|
import '../models/attendance_logout_request.dart';
|
||||||
|
import '../models/attendance_response_model.dart';
|
||||||
|
|
||||||
|
//in the following polymorphism is being used , a quich recap it is where th esame method but opperate in a different way
|
||||||
|
|
||||||
|
//one Repo two requests
|
||||||
|
abstract class AttendanceRepository {
|
||||||
|
Future<AttendanceResponseModel> login(AttendanceLoginRequest request);
|
||||||
|
|
||||||
|
Future<AttendanceResponseModel> logout(AttendanceLogoutRequest request);
|
||||||
|
}
|
||||||
15
lib/domain/usecases/attendance_login_usecase.dart
Normal file
15
lib/domain/usecases/attendance_login_usecase.dart
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import '../models/attendance_login_request.dart';
|
||||||
|
import '../models/attendance_response_model.dart';
|
||||||
|
import '../repositories/attendance_repository.dart';
|
||||||
|
|
||||||
|
//always remmber that the usecase uses the repo
|
||||||
|
|
||||||
|
class AttendanceLoginUsecase {
|
||||||
|
final AttendanceRepository repository;
|
||||||
|
|
||||||
|
AttendanceLoginUsecase({required this.repository});
|
||||||
|
|
||||||
|
Future<AttendanceResponseModel> call(AttendanceLoginRequest request) {
|
||||||
|
return repository.login(request);
|
||||||
|
}
|
||||||
|
}
|
||||||
13
lib/domain/usecases/attendance_logout_usecase.dart
Normal file
13
lib/domain/usecases/attendance_logout_usecase.dart
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import '../models/attendance_logout_request.dart';
|
||||||
|
import '../models/attendance_response_model.dart';
|
||||||
|
import '../repositories/attendance_repository.dart';
|
||||||
|
|
||||||
|
class AttendanceLogoutUseCase {
|
||||||
|
final AttendanceRepository repository;
|
||||||
|
|
||||||
|
AttendanceLogoutUseCase({required this.repository});
|
||||||
|
|
||||||
|
Future<AttendanceResponseModel> call(AttendanceLogoutRequest request) {
|
||||||
|
return repository.logout(request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,12 @@ import 'package:coda_project/presentation/screens/user_settings_screen.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import '../widgets/settings_bar.dart';
|
import '../widgets/settings_bar.dart';
|
||||||
|
import '../../core/di/injection_container.dart';
|
||||||
|
import '../../domain/models/attendance_login_request.dart';
|
||||||
|
import '../../domain/models/attendance_logout_request.dart';
|
||||||
|
import '../../domain/usecases/attendance_login_usecase.dart';
|
||||||
|
import '../../domain/usecases/attendance_logout_usecase.dart';
|
||||||
|
import '../../data/datasources/user_local_data_source.dart';
|
||||||
|
|
||||||
class AttendanceScreen extends StatelessWidget {
|
class AttendanceScreen extends StatelessWidget {
|
||||||
const AttendanceScreen({super.key});
|
const AttendanceScreen({super.key});
|
||||||
@@ -138,12 +144,40 @@ class AttendanceScreen extends StatelessWidget {
|
|||||||
child: _FingerButton(
|
child: _FingerButton(
|
||||||
icon: "assets/images/faceLogin.svg",
|
icon: "assets/images/faceLogin.svg",
|
||||||
label: "تسجيل الدخول",
|
label: "تسجيل الدخول",
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
Navigator.of(context).push(
|
final employeeId =
|
||||||
MaterialPageRoute(
|
await sl<UserLocalDataSource>().getCachedEmployeeId();
|
||||||
builder: (_) => OvalCameraCapturePage(isLogin: true),
|
print("ATTENDANCE_SCREEN: Retrieved EmployeeId: $employeeId");
|
||||||
),
|
if (employeeId == null) {
|
||||||
);
|
if (context.mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('خطأ: لم يتم العثور على رقم الموظف'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (context.mounted) {
|
||||||
|
Navigator.of(context).push(
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder:
|
||||||
|
(_) => OvalCameraCapturePage(
|
||||||
|
isLogin: true,
|
||||||
|
onCapture: (imageFile) async {
|
||||||
|
final loginUseCase =
|
||||||
|
sl<AttendanceLoginUsecase>();
|
||||||
|
await loginUseCase(
|
||||||
|
AttendanceLoginRequest(
|
||||||
|
employeeId: employeeId,
|
||||||
|
faceImage: imageFile,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -178,12 +212,39 @@ class AttendanceScreen extends StatelessWidget {
|
|||||||
child: _FingerButton(
|
child: _FingerButton(
|
||||||
icon: "assets/images/faceLogout.svg",
|
icon: "assets/images/faceLogout.svg",
|
||||||
label: "تسجيل خروج",
|
label: "تسجيل خروج",
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
Navigator.of(context).push(
|
final employeeId =
|
||||||
MaterialPageRoute(
|
await sl<UserLocalDataSource>().getCachedEmployeeId();
|
||||||
builder: (_) => OvalCameraCapturePage(isLogin: false),
|
if (employeeId == null) {
|
||||||
),
|
if (context.mounted) {
|
||||||
);
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('خطأ: لم يتم العثور على رقم الموظف'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (context.mounted) {
|
||||||
|
Navigator.of(context).push(
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder:
|
||||||
|
(_) => OvalCameraCapturePage(
|
||||||
|
isLogin: false,
|
||||||
|
onCapture: (imageFile) async {
|
||||||
|
final logoutUseCase =
|
||||||
|
sl<AttendanceLogoutUseCase>();
|
||||||
|
await logoutUseCase(
|
||||||
|
AttendanceLogoutRequest(
|
||||||
|
employeeId: employeeId,
|
||||||
|
faceImage: imageFile,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -2,10 +2,17 @@ import 'package:camera/camera.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
class OvalCameraCapturePage extends StatefulWidget {
|
class OvalCameraCapturePage extends StatefulWidget {
|
||||||
final bool isLogin;
|
final bool isLogin;
|
||||||
const OvalCameraCapturePage({super.key, this.isLogin = true});
|
final Future<void> Function(File image) onCapture;
|
||||||
|
|
||||||
|
const OvalCameraCapturePage({
|
||||||
|
super.key,
|
||||||
|
this.isLogin = true,
|
||||||
|
required this.onCapture,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<OvalCameraCapturePage> createState() => _OvalCameraCapturePageState();
|
State<OvalCameraCapturePage> createState() => _OvalCameraCapturePageState();
|
||||||
@@ -77,20 +84,7 @@ class _OvalCameraCapturePageState extends State<OvalCameraCapturePage> {
|
|||||||
_errorMessage = null;
|
_errorMessage = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
_timer = Timer(const Duration(seconds: 3), () {
|
_startScan();
|
||||||
if (mounted) {
|
|
||||||
setState(() {
|
|
||||||
_isSuccess = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Auto-close after 2 seconds
|
|
||||||
Future.delayed(const Duration(seconds: 2), () {
|
|
||||||
if (mounted) {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
|
|
||||||
@@ -102,6 +96,51 @@ class _OvalCameraCapturePageState extends State<OvalCameraCapturePage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _startScan() async {
|
||||||
|
try {
|
||||||
|
// Simulate scanning delay
|
||||||
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
|
|
||||||
|
if (!mounted ||
|
||||||
|
_cameraController == null ||
|
||||||
|
!_cameraController!.value.isInitialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final xFile = await _cameraController!.takePicture();
|
||||||
|
final file = File(xFile.path);
|
||||||
|
|
||||||
|
await widget.onCapture(file);
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
_isSuccess = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Auto-close after 2 seconds
|
||||||
|
Future.delayed(const Duration(seconds: 2), () {
|
||||||
|
if (mounted) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
_errorMessage = e.toString(); // Show error to user
|
||||||
|
});
|
||||||
|
|
||||||
|
// Auto-close or let user retry? For now let's just show error.
|
||||||
|
// If we want to auto-close on error:
|
||||||
|
Future.delayed(const Duration(seconds: 3), () {
|
||||||
|
if (mounted) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_cameraController?.dispose();
|
_cameraController?.dispose();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../widgets/app_background.dart';
|
import '../widgets/app_background.dart';
|
||||||
import '../../widgets/floatingnavbar.dart';
|
import '../widgets/FloatingNavBar.dart';
|
||||||
import 'attendence_screen.dart';
|
import 'attendence_screen.dart';
|
||||||
import 'finance_screen.dart';
|
import 'finance_screen.dart';
|
||||||
import 'holiday_screen.dart';
|
import 'holiday_screen.dart';
|
||||||
@@ -15,20 +15,17 @@ class MainPage extends StatefulWidget {
|
|||||||
class _MainPageState extends State<MainPage> {
|
class _MainPageState extends State<MainPage> {
|
||||||
int _currentIndex = 0;
|
int _currentIndex = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final screenHeight = MediaQuery.sizeOf(context).height;
|
// final screenHeight = MediaQuery.sizeOf(context).height;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Stack(
|
body: Stack(
|
||||||
children: [
|
children: [
|
||||||
|
|
||||||
/// BACKGROUND
|
/// BACKGROUND
|
||||||
const AppBackground(child: SizedBox()),
|
const AppBackground(child: SizedBox()),
|
||||||
|
|
||||||
/// ACTIVE SCREEN (fills entire screen - content will extend behind navbar)
|
/// ACTIVE SCREEN (fills entire screen - content will extend behind navbar)
|
||||||
///
|
///
|
||||||
Positioned.fill(
|
Positioned.fill(
|
||||||
child: IndexedStack(
|
child: IndexedStack(
|
||||||
index: _currentIndex,
|
index: _currentIndex,
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ import '../widgets/settings_bar.dart';
|
|||||||
import 'about_screen.dart';
|
import 'about_screen.dart';
|
||||||
import 'auth_screen.dart';
|
import 'auth_screen.dart';
|
||||||
import '../widgets/change_password_modal.dart';
|
import '../widgets/change_password_modal.dart';
|
||||||
|
import '../../core/di/injection_container.dart';
|
||||||
|
import '../../data/datasources/user_local_data_source.dart';
|
||||||
|
|
||||||
class UserSettingsScreen extends StatefulWidget {
|
class UserSettingsScreen extends StatefulWidget {
|
||||||
const UserSettingsScreen({super.key});
|
const UserSettingsScreen({super.key});
|
||||||
@@ -143,8 +144,8 @@ class _UserSettingsScreenState extends State<UserSettingsScreen> {
|
|||||||
duration: const Duration(
|
duration: const Duration(
|
||||||
milliseconds: 250,
|
milliseconds: 250,
|
||||||
),
|
),
|
||||||
width: 75,
|
width: 75,
|
||||||
height: 30,
|
height: 30,
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
horizontal: 4,
|
horizontal: 4,
|
||||||
),
|
),
|
||||||
@@ -227,13 +228,18 @@ class _UserSettingsScreenState extends State<UserSettingsScreen> {
|
|||||||
_settingsRow(
|
_settingsRow(
|
||||||
label: "تسجيل خروج",
|
label: "تسجيل خروج",
|
||||||
icon: "assets/images/logout2.svg",
|
icon: "assets/images/logout2.svg",
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
Navigator.push(
|
await sl<UserLocalDataSource>()
|
||||||
context,
|
.clearCache();
|
||||||
MaterialPageRoute(
|
if (context.mounted) {
|
||||||
builder: (_) => const AuthScreen(),
|
Navigator.pushAndRemoveUntil(
|
||||||
),
|
context,
|
||||||
);
|
MaterialPageRoute(
|
||||||
|
builder: (_) => const AuthScreen(),
|
||||||
|
),
|
||||||
|
(route) => false,
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -123,135 +123,143 @@ class _AuthFormState extends State<AuthForm> {
|
|||||||
textDirection: TextDirection.rtl,
|
textDirection: TextDirection.rtl,
|
||||||
child: FocusScope(
|
child: FocusScope(
|
||||||
child: Stack(
|
child: Stack(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
children: [
|
children: [
|
||||||
// Border container - decorative element behind the form
|
// Border container - decorative element behind the form
|
||||||
Container(
|
Container(
|
||||||
width: borderWidth,
|
width: borderWidth,
|
||||||
constraints: BoxConstraints(
|
constraints: BoxConstraints(
|
||||||
minHeight: formHeight + 40,
|
minHeight: formHeight + 40,
|
||||||
maxHeight:
|
maxHeight:
|
||||||
formHeight + 80, // Allows shrinking when keyboard opens
|
formHeight + 80, // Allows shrinking when keyboard opens
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.transparent,
|
||||||
|
borderRadius: BorderRadius.circular(32),
|
||||||
|
border: Border.all(color: const Color(0xDD00C28E), width: 1),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.transparent,
|
|
||||||
borderRadius: BorderRadius.circular(32),
|
|
||||||
border: Border.all(color: const Color(0xDD00C28E), width: 1),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
// Main form container
|
// Main form container
|
||||||
Container(
|
Container(
|
||||||
width: formWidth,
|
width: formWidth,
|
||||||
padding: EdgeInsets.symmetric(
|
padding: EdgeInsets.symmetric(
|
||||||
horizontal: horizontalPadding,
|
horizontal: horizontalPadding,
|
||||||
vertical: verticalPadding,
|
vertical: verticalPadding,
|
||||||
),
|
),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: const Color(0xFFEEFFFA),
|
color: const Color(0xFFEEFFFA),
|
||||||
borderRadius: BorderRadius.circular(28),
|
borderRadius: BorderRadius.circular(28),
|
||||||
boxShadow: const [
|
boxShadow: const [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: Colors.black26,
|
color: Colors.black26,
|
||||||
blurRadius: 10,
|
blurRadius: 10,
|
||||||
offset: Offset(0, 5),
|
offset: Offset(0, 5),
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
/// Title
|
|
||||||
Center(
|
|
||||||
child: Text(
|
|
||||||
"تسجيل دخول",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: titleFontSize,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Colors.black87,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
|
),
|
||||||
SizedBox(height: verticalSpacing),
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
/// Phone Number Label
|
mainAxisSize: MainAxisSize.min,
|
||||||
Align(
|
children: [
|
||||||
alignment: Alignment.centerRight,
|
/// Title
|
||||||
child: Text(
|
Center(
|
||||||
"رقم الهاتف",
|
child: Text(
|
||||||
style: TextStyle(
|
"تسجيل دخول",
|
||||||
fontSize: labelFontSize,
|
style: TextStyle(
|
||||||
color: Colors.black87,
|
fontSize: titleFontSize,
|
||||||
),
|
fontWeight: FontWeight.bold,
|
||||||
),
|
color: Colors.black87,
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
|
|
||||||
_buildField(
|
|
||||||
controller: _phoneNumberController,
|
|
||||||
hint: "رقم الهاتف",
|
|
||||||
obscure: false,
|
|
||||||
keyboardType: TextInputType.phone,
|
|
||||||
focusNode: _phoneNumberFocusNode,
|
|
||||||
textInputAction: TextInputAction.next,
|
|
||||||
onSubmitted: (_) {
|
|
||||||
// Move focus to password field when next is pressed
|
|
||||||
FocusScope.of(context).requestFocus(_passwordFocusNode);
|
|
||||||
},
|
|
||||||
fontSize: fieldFontSize,
|
|
||||||
),
|
|
||||||
|
|
||||||
SizedBox(height: fieldSpacing),
|
|
||||||
|
|
||||||
/// Password Label
|
|
||||||
Align(
|
|
||||||
alignment: Alignment.centerRight,
|
|
||||||
child: Text(
|
|
||||||
"كلمة المرور",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: labelFontSize,
|
|
||||||
color: Colors.black87,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
|
|
||||||
_buildField(
|
|
||||||
controller: _passwordController,
|
|
||||||
hint: "كلمة المرور",
|
|
||||||
obscure: _obscure,
|
|
||||||
hasEye: true,
|
|
||||||
focusNode: _passwordFocusNode,
|
|
||||||
textInputAction: TextInputAction.done,
|
|
||||||
onSubmitted: (_) => _handleLogin(),
|
|
||||||
fontSize: fieldFontSize,
|
|
||||||
),
|
|
||||||
|
|
||||||
SizedBox(height: buttonSpacing), // Responsive spacing
|
|
||||||
|
|
||||||
BlocBuilder<LoginBloc, LoginState>(
|
|
||||||
builder: (context, state) {
|
|
||||||
final isLoading = state is LoginLoading;
|
|
||||||
return Center(
|
|
||||||
child: OnboardingButton(
|
|
||||||
text: isLoading ? "جاري تسجيل الدخول..." : "تسجيل دخول",
|
|
||||||
backgroundColor: const Color.fromARGB(239, 35, 87, 74),
|
|
||||||
onPressed: isLoading ? null : _handleLogin,
|
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
},
|
),
|
||||||
),
|
|
||||||
|
|
||||||
SizedBox(height: bottomSpacing),
|
SizedBox(height: verticalSpacing),
|
||||||
],
|
|
||||||
|
/// Phone Number Label
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
child: Text(
|
||||||
|
"رقم الهاتف",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: labelFontSize,
|
||||||
|
color: Colors.black87,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
|
||||||
|
_buildField(
|
||||||
|
controller: _phoneNumberController,
|
||||||
|
hint: "رقم الهاتف",
|
||||||
|
obscure: false,
|
||||||
|
keyboardType: TextInputType.phone,
|
||||||
|
focusNode: _phoneNumberFocusNode,
|
||||||
|
textInputAction: TextInputAction.next,
|
||||||
|
onSubmitted: (_) {
|
||||||
|
// Move focus to password field when next is pressed
|
||||||
|
FocusScope.of(context).requestFocus(_passwordFocusNode);
|
||||||
|
},
|
||||||
|
fontSize: fieldFontSize,
|
||||||
|
),
|
||||||
|
|
||||||
|
SizedBox(height: fieldSpacing),
|
||||||
|
|
||||||
|
/// Password Label
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
child: Text(
|
||||||
|
"كلمة المرور",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: labelFontSize,
|
||||||
|
color: Colors.black87,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
|
||||||
|
_buildField(
|
||||||
|
controller: _passwordController,
|
||||||
|
hint: "كلمة المرور",
|
||||||
|
obscure: _obscure,
|
||||||
|
hasEye: true,
|
||||||
|
focusNode: _passwordFocusNode,
|
||||||
|
textInputAction: TextInputAction.done,
|
||||||
|
onSubmitted: (_) => _handleLogin(),
|
||||||
|
fontSize: fieldFontSize,
|
||||||
|
),
|
||||||
|
|
||||||
|
SizedBox(height: buttonSpacing), // Responsive spacing
|
||||||
|
|
||||||
|
BlocBuilder<LoginBloc, LoginState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
final isLoading = state is LoginLoading;
|
||||||
|
return Center(
|
||||||
|
child: OnboardingButton(
|
||||||
|
text:
|
||||||
|
isLoading
|
||||||
|
? "جاري تسجيل الدخول..."
|
||||||
|
: "تسجيل دخول",
|
||||||
|
backgroundColor: const Color.fromARGB(
|
||||||
|
239,
|
||||||
|
35,
|
||||||
|
87,
|
||||||
|
74,
|
||||||
|
),
|
||||||
|
onPressed: isLoading ? null : _handleLogin,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
|
||||||
|
SizedBox(height: bottomSpacing),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user