Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log out user account after account deletion success #1395

Merged
merged 16 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract_target 'Automattic' do
#
pod 'Automattic-Tracks-iOS', '~> 0.6'
# pod 'Automattic-Tracks-iOS', :git => 'https://github.com/Automattic/Automattic-Tracks-iOS.git', :branch => 'add/support-for-tracking-crashes'
pod 'Simperium', '1.8.0'
pod 'Simperium', '1.9.0'
pod 'WordPress-Ratings-iOS', '0.0.2'

# Testing Target
Expand Down
28 changes: 14 additions & 14 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ PODS:
- Sentry (4.5.0):
- Sentry/Core (= 4.5.0)
- Sentry/Core (4.5.0)
- Simperium (1.8.0):
- Simperium/DiffMatchPach (= 1.8.0)
- Simperium/JRSwizzle (= 1.8.0)
- Simperium/SocketTrust (= 1.8.0)
- Simperium/SPReachability (= 1.8.0)
- Simperium/SSKeychain (= 1.8.0)
- Simperium/DiffMatchPach (1.8.0)
- Simperium/JRSwizzle (1.8.0)
- Simperium/SocketTrust (1.8.0)
- Simperium/SPReachability (1.8.0)
- Simperium/SSKeychain (1.8.0)
- Simperium (1.9.0):
- Simperium/DiffMatchPach (= 1.9.0)
- Simperium/JRSwizzle (= 1.9.0)
- Simperium/SocketTrust (= 1.9.0)
- Simperium/SPReachability (= 1.9.0)
- Simperium/SSKeychain (= 1.9.0)
- Simperium/DiffMatchPach (1.9.0)
- Simperium/JRSwizzle (1.9.0)
- Simperium/SocketTrust (1.9.0)
- Simperium/SPReachability (1.9.0)
- Simperium/SSKeychain (1.9.0)
- Sodium-Fork (0.8.2)
- UIDeviceIdentifier (1.6.0)
- WordPress-Ratings-iOS (0.0.2)
Expand All @@ -44,7 +44,7 @@ DEPENDENCIES:
- AppCenter/Distribute (~> 2.5.1)
- Automattic-Tracks-iOS (~> 0.6)
- Gridicons (~> 0.18)
- Simperium (= 1.8.0)
- Simperium (= 1.9.0)
- WordPress-Ratings-iOS (= 0.0.2)
- ZIPFoundation (~> 0.9.9)

Expand All @@ -69,12 +69,12 @@ SPEC CHECKSUMS:
Gridicons: dc92efbe5fd60111d2e8ea051d84a60cca552abc
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
Sentry: ab6c209f23700d1460691dbc90e19ed0a05d496b
Simperium: a9cae2ac607858fc09103b444494ca15b56c3f6c
Simperium: 45d828d68aad71f3449371346f270013943eff78
Sodium-Fork: 45fe3a7c675898ca0635af4eadcb34985477e868
UIDeviceIdentifier: f4bf3b343581a1beacdbf5fb1a8825bd5f05a4a4
WordPress-Ratings-iOS: 9f83dbba6e728c5121b1fd21b5683cf2fd120646
ZIPFoundation: b1f0de4eed33e74a676f76e12559ab6b75990197

PODFILE CHECKSUM: b0c5c0c547076d1c49fcd33c1a513076f42c5055
PODFILE CHECKSUM: 93b73220f99019d67a192eb4ef23eaacde3a9720

COCOAPODS: 1.10.0
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private struct AccountDeletion {
static let cancel = NSLocalizedString("Cancel", comment: "Cancel button title")

static let succesAlertTitle = NSLocalizedString("Check Your Email", comment: "Title for delete account succes alert")
static let successAlertMessage = NSLocalizedString("An email has been sent to %@ Check your inbox and follow the instructions to confirm account deletion.\n\nYour account won't be deleted until we receive your confirmation", comment: "Delete account confirmation instructions")
static let successAlertMessage = NSLocalizedString("An email has been sent to %@. Check your inbox and follow the instructions to confirm account deletion.\n\nYour account won't be deleted until we receive your confirmation.", comment: "Delete account confirmation instructions")
static let ok = NSLocalizedString("Ok", comment: "Confirm alert message")

static let errorTitle = NSLocalizedString("Error", comment: "Deletion Error Title")
Expand Down
11 changes: 8 additions & 3 deletions Simplenote/Controllers/AccountDeletionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import Foundation
class AccountDeletionController: NSObject {
private var accountDeletionRequestDate: Date?

var deletionTokenHasExpired: Bool {
var hasValidDeletionRequest: Bool {
guard let expirationDate = accountDeletionRequestDate?.increased(byDays: 1) else {
return true
return false
}

return Date() > expirationDate
return Date() < expirationDate
}

func requestAccountDeletion(_ user: SPUser, completion: @escaping (_ result: Result<Data?, RemoteError>) -> Void) {
Expand All @@ -20,4 +20,9 @@ class AccountDeletionController: NSObject {
completion(result)
}
}

@objc
func clearRequestToken() {
accountDeletionRequestDate = nil
}
}
25 changes: 21 additions & 4 deletions Simplenote/SPAppDelegate+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,17 @@ extension SPAppDelegate: SimperiumDelegate {

public func simperium(_ simperium: Simperium, didFailWithError error: Error) {
SPTracker.refreshMetadataForAnonymousUser()

guard let simperiumError = SPSimperiumErrors(rawValue: (error as NSError).code) else {
return
}

switch simperiumError {
case .invalidToken:
logOutIfAccountDeletionRequested()
default:
break
}
}
}

Expand Down Expand Up @@ -408,16 +419,22 @@ extension SPAppDelegate {
//
extension SPAppDelegate {
@objc
func authenticateSimperiumIfNeeded() {
guard let deletionController = accountDeletionController else {
func authenticateSimperiumIfAccountDeletionRequested() {
guard let deletionController = accountDeletionController,
deletionController.hasValidDeletionRequest else {
charliescheer marked this conversation as resolved.
Show resolved Hide resolved
return
}

if deletionController.deletionTokenHasExpired {
simperium.authenticateIfNecessary()
}

@objc
func logOutIfAccountDeletionRequested() {
guard accountDeletionController?.hasValidDeletionRequest == true else {
return
}

simperium.authenticateIfNecessary()
logoutAndReset(self)
}
}

Expand Down
21 changes: 10 additions & 11 deletions Simplenote/SPAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ - (void)applicationDidEnterBackground:(UIApplication *)application
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[self dismissPasscodeLockIfPossible];
[self authenticateSimperiumIfNeeded];
[self authenticateSimperiumIfAccountDeletionRequested];
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
Expand Down Expand Up @@ -286,13 +286,14 @@ - (void)presentSettingsViewController
- (void)logoutAndReset:(id)sender
{
self.bSigningUserOut = YES;

[self dismissAllModalsAnimated:YES completion:nil];
self.signOutActivityIndicator = [SPModalActivityIndicator show];

// Remove WordPress token
// Reset State
[SPKeychain deletePasswordForService:kSimplenoteWPServiceName account:self.simperium.user.email];

// Remove Siri Shortcuts
[[ShortcutsHandler shared] unregisterSimplenoteActivities];
[self.accountDeletionController clearRequestToken];

// Actual Simperium Logout
double delayInSeconds = 0.75;
Expand All @@ -315,13 +316,11 @@ - (void)logoutAndReset:(id)sender

// hide sidebar of notelist
[self.sidebarViewController hideSidebarWithAnimation:NO];

[self dismissAllModalsAnimated:YES completion:^{

[self.simperium authenticateIfNecessary];
self.bSigningUserOut = NO;
}];
}];
[self.signOutActivityIndicator dismiss:YES completion:nil];

[self.simperium authenticateIfNecessary];
self.bSigningUserOut = NO;
}];
});
}

Expand Down