From 38bbbb32468655b2f260933ebf334841f2486a5a Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 9 Jul 2024 11:31:41 +0200 Subject: [PATCH] Forbids multi device authentication --- PadelClub/Data/DataStore.swift | 8 ++++++++ PadelClub/Data/README.md | 1 + PadelClub/Data/User.swift | 11 ++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/PadelClub/Data/DataStore.swift b/PadelClub/Data/DataStore.swift index 2e9656e..e3d0097 100644 --- a/PadelClub/Data/DataStore.swift +++ b/PadelClub/Data/DataStore.swift @@ -163,8 +163,16 @@ class DataStore: ObservableObject { if await StoreCenter.main.hasPendingAPICalls() { // todo qu'est ce qu'on fait des API Call ? } + + do { + let services = try StoreCenter.main.service() + try await services.logout() + } catch { + Logger.error(error) + } } + StoreCenter.main.disconnect() StoreCenter.main.collectionsCanSynchronize = false diff --git a/PadelClub/Data/README.md b/PadelClub/Data/README.md index 5afddab..334dd01 100644 --- a/PadelClub/Data/README.md +++ b/PadelClub/Data/README.md @@ -13,6 +13,7 @@ Dans Django: - S'il c'est un champ dans **CustomUser**: - Ajouter le champ à la méthode fields_for_update - Ajouter le champ dans UserSerializer > create > create_user dans serializers.py + - L'ajouter aussi dans admin.py si nécéssaire - Faire le *makemigrations* + *migrate* diff --git a/PadelClub/Data/User.swift b/PadelClub/Data/User.swift index 18c53c4..6ce9d08 100644 --- a/PadelClub/Data/User.swift +++ b/PadelClub/Data/User.swift @@ -44,6 +44,8 @@ class User: ModelObject, UserBase, Storable { var groupStageMatchFormatPreference: MatchFormat? var loserBracketMatchFormatPreference: MatchFormat? + var deviceId: String? + init(username: String, email: String, firstName: String, lastName: String, phone: String?, country: String?) { self.username = username self.firstName = firstName @@ -129,7 +131,7 @@ class User: ModelObject, UserBase, Storable { case _bracketMatchFormatPreference = "bracketMatchFormatPreference" case _groupStageMatchFormatPreference = "groupStageMatchFormatPreference" case _loserBracketMatchFormatPreference = "loserBracketMatchFormatPreference" - + case _deviceId = "deviceId" } func encode(to encoder: Encoder) throws { @@ -212,6 +214,13 @@ class User: ModelObject, UserBase, Storable { } else { try container.encodeNil(forKey: ._loserBracketMatchFormatPreference) } + + if let deviceId { + try container.encode(deviceId, forKey: ._deviceId) + } else { + try container.encodeNil(forKey: ._deviceId) + } + } static func placeHolder() -> User {