40 lines
No EOL
1.3 KiB
Dart
40 lines
No EOL
1.3 KiB
Dart
import 'package:contacts_plus_plus/config.dart';
|
|
|
|
class AuthenticationData {
|
|
static const _unauthenticated = AuthenticationData(userId: "", token: "", secretMachineIdHash: "", isAuthenticated: false);
|
|
final String userId;
|
|
final String token;
|
|
final String secretMachineIdHash;
|
|
final bool isAuthenticated;
|
|
|
|
const AuthenticationData({
|
|
required this.userId, required this.token, required this.secretMachineIdHash, required this.isAuthenticated
|
|
});
|
|
|
|
factory AuthenticationData.fromMap(Map map) {
|
|
map = map["entity"];
|
|
final userId = map["userId"];
|
|
final token = map["token"];
|
|
final machineId = map["secretMachineIdHash"];
|
|
if (userId == null || token == null || machineId == null) {
|
|
return _unauthenticated;
|
|
}
|
|
return AuthenticationData(userId: userId, token: token, secretMachineIdHash: machineId, isAuthenticated: true);
|
|
}
|
|
|
|
factory AuthenticationData.unauthenticated() => _unauthenticated;
|
|
|
|
Map<String, String> get authorizationHeader => {
|
|
"Authorization": "res $userId:$token",
|
|
"SecretClientAccessKey": Config.secretClientKey,
|
|
"UID":"2cde2bd72c104d1785af28ae77c29fc2",
|
|
};
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
"userId": userId,
|
|
"token": token,
|
|
"secretMachineId": secretMachineIdHash,
|
|
};
|
|
}
|
|
} |