Skip to content

Commit 70c049b

Browse files
committedMay 5, 2020
Add delete account capabilities
1 parent a3c176f commit 70c049b

File tree

5 files changed

+157
-84
lines changed

5 files changed

+157
-84
lines changed
 

‎ios-base/Base.lproj/Main.storyboard

+38-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="aXS-GV-C4h">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15702" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="aXS-GV-C4h">
33
<device id="retina4_7" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15510"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15704"/>
77
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
88
</dependencies>
99
<scenes>
@@ -222,51 +222,74 @@ RS iOS BASE.</string>
222222
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
223223
<subviews>
224224
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="You are signed in/up" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="deB-Nf-PW5">
225-
<rect key="frame" x="32" y="72" width="277.5" height="38.5"/>
225+
<rect key="frame" x="49" y="72" width="277.5" height="38.5"/>
226226
<fontDescription key="fontDescription" type="system" pointSize="32"/>
227227
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
228228
<nil key="highlightedColor"/>
229229
</label>
230-
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="aMM-gP-X0k">
231-
<rect key="frame" x="75" y="570" width="225" height="45"/>
232-
<color key="backgroundColor" red="0.69471571180555558" green="0.27205175823635525" blue="0.35792462901418848" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
230+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="03z-HI-tG7">
231+
<rect key="frame" x="75" y="583" width="225" height="44"/>
232+
<color key="backgroundColor" red="0.69471571180000002" green="0.27205175819999999" blue="0.35792462899999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
233233
<accessibility key="accessibilityConfiguration" identifier="LogoutButton"/>
234234
<constraints>
235-
<constraint firstAttribute="height" constant="45" id="8xm-R0-ZOt"/>
235+
<constraint firstAttribute="height" constant="44" id="GFl-9u-Vux"/>
236236
</constraints>
237237
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="15"/>
238-
<state key="normal" title="LOG OUT">
238+
<state key="normal" title="DELETE ACCOUNT">
239239
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
240240
</state>
241241
<connections>
242-
<action selector="tapOnLogOutButton:" destination="K4y-mn-w4p" eventType="touchUpInside" id="7k9-jn-HZL"/>
242+
<action selector="tapOnDeleteAccount:" destination="K4y-mn-w4p" eventType="touchUpInside" id="PvN-DK-BxP"/>
243+
<action selector="tapOnLogOutButton:" destination="K4y-mn-w4p" eventType="touchUpInside" id="gCc-47-Ziz"/>
243244
</connections>
244245
</button>
245246
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="sla-gz-amO">
246-
<rect key="frame" x="136.5" y="514" width="102" height="32"/>
247+
<rect key="frame" x="75" y="317.5" width="225" height="32"/>
247248
<fontDescription key="fontDescription" type="system" pointSize="16"/>
248249
<state key="normal" title="Get my profile">
249-
<color key="titleColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
250+
<color key="titleColor" systemColor="linkColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
250251
</state>
251252
<connections>
252253
<action selector="tapOnGetMyProfile:" destination="K4y-mn-w4p" eventType="touchUpInside" id="HQj-iH-IxE"/>
253254
</connections>
254255
</button>
256+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="aMM-gP-X0k">
257+
<rect key="frame" x="75" y="524" width="225" height="44"/>
258+
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
259+
<accessibility key="accessibilityConfiguration" identifier="LogoutButton"/>
260+
<constraints>
261+
<constraint firstAttribute="height" constant="44" id="8xm-R0-ZOt"/>
262+
</constraints>
263+
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="15"/>
264+
<state key="normal" title="LOG OUT">
265+
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
266+
</state>
267+
<connections>
268+
<action selector="tapOnLogOutButton:" destination="K4y-mn-w4p" eventType="touchUpInside" id="7k9-jn-HZL"/>
269+
</connections>
270+
</button>
255271
</subviews>
256272
<color key="backgroundColor" red="0.95331488720000002" green="0.95331488720000002" blue="0.95331488720000002" alpha="1" colorSpace="calibratedRGB"/>
257273
<accessibility key="accessibilityConfiguration" identifier="AfterLoginSignupView"/>
258274
<constraints>
259-
<constraint firstItem="deB-Nf-PW5" firstAttribute="leading" secondItem="YnO-i4-MwY" secondAttribute="leading" constant="32" id="FiE-id-ex3"/>
275+
<constraint firstItem="03z-HI-tG7" firstAttribute="width" secondItem="aMM-gP-X0k" secondAttribute="width" id="2pu-9r-RmA"/>
276+
<constraint firstItem="sla-gz-amO" firstAttribute="centerY" secondItem="YnO-i4-MwY" secondAttribute="centerY" id="8N9-aS-plH"/>
277+
<constraint firstItem="sla-gz-amO" firstAttribute="centerX" secondItem="YnO-i4-MwY" secondAttribute="centerX" id="FHY-9p-b9J"/>
278+
<constraint firstItem="03z-HI-tG7" firstAttribute="top" secondItem="aMM-gP-X0k" secondAttribute="bottom" constant="15" id="Fcf-yj-QwV"/>
279+
<constraint firstItem="deB-Nf-PW5" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="YnO-i4-MwY" secondAttribute="leading" constant="20" id="FiE-id-ex3"/>
260280
<constraint firstItem="aMM-gP-X0k" firstAttribute="width" secondItem="YnO-i4-MwY" secondAttribute="width" multiplier="0.6" id="KPU-cF-icn"/>
261-
<constraint firstItem="aMM-gP-X0k" firstAttribute="top" secondItem="sla-gz-amO" secondAttribute="bottom" constant="24" id="Nt1-9I-wPr"/>
281+
<constraint firstItem="03z-HI-tG7" firstAttribute="centerX" secondItem="YnO-i4-MwY" secondAttribute="centerX" id="KXa-jh-Vyd"/>
282+
<constraint firstItem="gRs-YP-uAr" firstAttribute="top" secondItem="03z-HI-tG7" secondAttribute="bottom" constant="40" id="PAz-Ar-RVt"/>
262283
<constraint firstItem="deB-Nf-PW5" firstAttribute="top" secondItem="b07-nt-cIs" secondAttribute="bottom" constant="72" id="WXh-be-LfA"/>
263-
<constraint firstItem="gRs-YP-uAr" firstAttribute="top" secondItem="aMM-gP-X0k" secondAttribute="bottom" constant="52" id="anW-vP-uEH"/>
264284
<constraint firstItem="aMM-gP-X0k" firstAttribute="centerX" secondItem="YnO-i4-MwY" secondAttribute="centerX" id="fmE-ac-Poo"/>
265-
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="deB-Nf-PW5" secondAttribute="trailing" constant="44" id="nuh-nK-gKC"/>
285+
<constraint firstItem="sla-gz-amO" firstAttribute="width" secondItem="aMM-gP-X0k" secondAttribute="width" id="hh9-wD-xFh"/>
286+
<constraint firstItem="deB-Nf-PW5" firstAttribute="centerX" secondItem="YnO-i4-MwY" secondAttribute="centerX" id="lU9-l9-VKr"/>
287+
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="deB-Nf-PW5" secondAttribute="trailing" constant="20" id="nuh-nK-gKC"/>
266288
<constraint firstItem="sla-gz-amO" firstAttribute="centerX" secondItem="YnO-i4-MwY" secondAttribute="centerX" id="oiT-yw-cnD"/>
267289
</constraints>
268290
</view>
269291
<connections>
292+
<outlet property="deleteAccountButton" destination="03z-HI-tG7" id="UXu-M7-no3"/>
270293
<outlet property="logOut" destination="aMM-gP-X0k" id="jXY-nY-53e"/>
271294
<outlet property="welcomeLabel" destination="deB-Nf-PW5" id="vQb-ZK-INh"/>
272295
</connections>

‎ios-base/Home/ViewModels/HomeViewModel.swift

+18-3
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,26 @@ class HomeViewModel {
3737
func logoutUser() {
3838
state = .loading
3939
UserService.sharedInstance.logout({ [weak self] in
40-
self?.state = .idle
41-
AppNavigator.shared.navigate(to: OnboardingRoutes.firstScreen, with: .changeRoot)
42-
AnalyticsManager.shared.reset()
40+
self?.didlogOutAccount()
4341
}, failure: { [weak self] error in
4442
self?.state = .error(error.localizedDescription)
4543
})
4644
}
45+
46+
func deleteAccount() {
47+
state = .loading
48+
UserService.sharedInstance.deleteAccount({ [weak self] in
49+
self?.didlogOutAccount()
50+
}, failure: { [weak self] error in
51+
self?.state = .error(error.localizedDescription)
52+
})
53+
}
54+
55+
private func didlogOutAccount() {
56+
AppNavigator.shared.navigate(
57+
to: OnboardingRoutes.firstScreen,
58+
with: .changeRoot
59+
)
60+
AnalyticsManager.shared.reset()
61+
}
4762
}

‎ios-base/Home/Views/HomeViewController.swift

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class HomeViewController: UIViewController {
1414

1515
@IBOutlet weak var welcomeLabel: UILabel!
1616
@IBOutlet weak var logOut: UIButton!
17+
@IBOutlet weak var deleteAccountButton: UIButton!
1718

1819
var viewModel: HomeViewModel!
1920

@@ -22,6 +23,7 @@ class HomeViewController: UIViewController {
2223
super.viewDidLoad()
2324
viewModel.delegate = self
2425
logOut.setRoundBorders(22)
26+
deleteAccountButton.setRoundBorders(22)
2527
}
2628

2729
// MARK: - Actions
@@ -33,6 +35,10 @@ class HomeViewController: UIViewController {
3335
@IBAction func tapOnLogOutButton(_ sender: Any) {
3436
viewModel.logoutUser()
3537
}
38+
39+
@IBAction func tapOnDeleteAccount(_ sender: Any) {
40+
viewModel.deleteAccount()
41+
}
3642
}
3743

3844
extension HomeViewController: HomeViewModelDelegate {

‎ios-base/Networking/Services/UserResource.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum UserResource: TargetType {
1717
case profile
1818
case fbLogin(String)
1919
case logout
20+
case deleteAccount
2021

2122
var path: String {
2223
let authBasePath = "/users"
@@ -34,6 +35,8 @@ enum UserResource: TargetType {
3435
return "\(userBasePath)/facebook"
3536
case .logout:
3637
return "\(authBasePath)/sign_out"
38+
case .deleteAccount:
39+
return "\(userBasePath)/delete_account"
3740
}
3841
}
3942

@@ -43,7 +46,7 @@ enum UserResource: TargetType {
4346
return .post
4447
case .profile:
4548
return .get
46-
case .logout:
49+
case .logout, .deleteAccount:
4750
return .delete
4851
}
4952
}

‎ios-base/Networking/Services/UserService.swift

+91-65
Original file line numberDiff line numberDiff line change
@@ -20,72 +20,81 @@ enum UserServiceError: Error {
2020
class UserService: BaseApiService<UserResource> {
2121
static let sharedInstance = UserService()
2222

23-
func login(_ email: String,
24-
password: String,
25-
success: @escaping () -> Void,
26-
failure: @escaping (_ error: Error) -> Void) {
27-
request(for: .login(email, password),
28-
at: "user",
29-
onSuccess: { [weak self] (result: User, response) -> Void in
30-
guard let headers = response.response?.allHeaderFields else {
31-
failure(UserServiceError.noResponse)
32-
return
33-
}
34-
self?.saveUserSession(user: result, headers: headers)
35-
success()
36-
}, onFailure: { error, _ in
37-
failure(error)
38-
})
23+
func login(
24+
_ email: String,
25+
password: String,
26+
success: @escaping () -> Void,
27+
failure: @escaping (_ error: Error) -> Void
28+
) {
29+
request(
30+
for: .login(email, password),
31+
at: "user",
32+
onSuccess: { [weak self] (result: User, response) -> Void in
33+
guard let headers = response.response?.allHeaderFields else {
34+
failure(UserServiceError.noResponse)
35+
return
36+
}
37+
self?.saveUserSession(user: result, headers: headers)
38+
success()
39+
}, onFailure: { error, _ in
40+
failure(error)
41+
})
3942
}
4043

41-
func signup(_ email: String,
42-
password: String,
43-
avatar64: UIImage,
44-
success: @escaping () -> Void,
45-
failure: @escaping (_ error: Error) -> Void) {
46-
request(for: .signup(email, password, avatar64),
47-
at: "user",
48-
onSuccess: { [weak self] (result: User, response) -> Void in
49-
guard let headers = response.response?.allHeaderFields else {
50-
failure(UserServiceError.noResponse)
51-
return
52-
}
53-
self?.saveUserSession(user: result, headers: headers)
54-
success()
55-
}, onFailure: { error, _ in
56-
failure(error)
57-
})
44+
func signup(
45+
_ email: String,
46+
password: String,
47+
avatar64: UIImage,
48+
success: @escaping () -> Void,
49+
failure: @escaping (_ error: Error) -> Void
50+
) {
51+
request(
52+
for: .signup(email, password, avatar64),
53+
at: "user",
54+
onSuccess: { [weak self] (result: User, response) -> Void in
55+
guard let headers = response.response?.allHeaderFields else {
56+
failure(UserServiceError.noResponse)
57+
return
58+
}
59+
self?.saveUserSession(user: result, headers: headers)
60+
success()
61+
}, onFailure: { error, _ in
62+
failure(error)
63+
})
5864
}
5965

6066
func getMyProfile(
6167
_ success: @escaping (_ user: User) -> Void,
6268
failure: @escaping (_ error: Error) -> Void
6369
) {
64-
request(for: .profile,
65-
at: "user",
66-
onSuccess: { (result: User, _) -> Void in
67-
success(result)
68-
},
69-
onFailure: { error, _ in
70-
failure(error)
71-
})
70+
request(
71+
for: .profile,
72+
at: "user",
73+
onSuccess: { (result: User, _) -> Void in
74+
success(result)
75+
},
76+
onFailure: { error, _ in
77+
failure(error)
78+
})
7279
}
7380

7481
func loginWithFacebook(
75-
token: String, success: @escaping () -> Void, failure: @escaping (_ error: Error)
76-
-> Void) {
77-
request(for: .fbLogin(token),
78-
onSuccess: { [weak self] (result: User, response) -> Void in
79-
guard let headers = response.response?.allHeaderFields else {
80-
failure(UserServiceError.noResponse)
81-
return
82-
}
83-
self?.saveUserSession(user: result, headers: headers)
84-
success()
85-
},
86-
onFailure: { error, _ in
87-
failure(error)
88-
})
82+
token: String, success: @escaping () -> Void,
83+
failure: @escaping (_ error: Error) -> Void
84+
) {
85+
request(
86+
for: .fbLogin(token),
87+
onSuccess: { [weak self] (result: User, response) -> Void in
88+
guard let headers = response.response?.allHeaderFields else {
89+
failure(UserServiceError.noResponse)
90+
return
91+
}
92+
self?.saveUserSession(user: result, headers: headers)
93+
success()
94+
},
95+
onFailure: { error, _ in
96+
failure(error)
97+
})
8998
}
9099

91100
func saveUserSession(user: User, headers: [AnyHashable: Any]) {
@@ -96,15 +105,32 @@ class UserService: BaseApiService<UserResource> {
96105
}
97106

98107
func logout(
99-
_ success: @escaping () -> Void, failure: @escaping (_ error: Error)
100-
-> Void) {
101-
request(for: UserResource.logout,
102-
onSuccess: { _ in
103-
UserDataManager.deleteUser()
104-
SessionManager.deleteSession()
105-
success()
106-
}, onFailure: { error, _ in
107-
failure(error)
108-
})
108+
_ success: @escaping () -> Void,
109+
failure: @escaping (_ error: Error) -> Void
110+
) {
111+
request(
112+
for: UserResource.logout,
113+
onSuccess: { _ in
114+
UserDataManager.deleteUser()
115+
SessionManager.deleteSession()
116+
success()
117+
}, onFailure: { error, _ in
118+
failure(error)
119+
})
120+
}
121+
122+
func deleteAccount(
123+
_ success: @escaping () -> Void,
124+
failure: @escaping (_ error: Error) -> Void
125+
) {
126+
request(
127+
for: UserResource.deleteAccount,
128+
onSuccess: { _ in
129+
UserDataManager.deleteUser()
130+
SessionManager.deleteSession()
131+
success()
132+
}, onFailure: { error, _ in
133+
failure(error)
134+
})
109135
}
110136
}

0 commit comments

Comments
 (0)
Please sign in to comment.