Skip to content

Commit

Permalink
feat: add "delete account" button in profile page to fulfill Apple re…
Browse files Browse the repository at this point in the history
…view

Signed-off-by: Bofu Chen (bafu) <[email protected]>
  • Loading branch information
bafu committed Jul 31, 2022
1 parent b7cb9b1 commit 693d3aa
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/app/features/profile/profile.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,7 @@
<button (click)="logout()" class="expand" color="primary" mat-stroked-button>
{{ t('logout') }}
</button>
<button (click)="delete()" class="expand" color="warn" mat-raised-button>
{{ t('delete') }}
</button>
</div>
30 changes: 30 additions & 0 deletions src/app/features/profile/profile.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,36 @@ export class ProfilePage {
)
.subscribe();
}

/**
* // TODO: Integrate Storage Backend delete function after it's ready.
* Delete user account from Storage Backend.
*/
async delete() {
const email: string = await this.diaBackendAuthService.getEmail();

const action$ = this.diaBackendAuthService.deleteUser$(email).pipe(
// logout
concatMapTo(defer(() => this.mediaStore.clear())),
concatMapTo(defer(() => this.database.clear())),
concatMapTo(defer(() => this.preferenceManager.clear())),
concatMapTo(defer(reloadApp)),
catchError((err: unknown) => this.errorService.toastError$(err))
);

return defer(() =>
this.confirmAlert.present({
message: this.translocoService.translate('message.confirmDelete'),
})
)
.pipe(
concatMap(result =>
iif(() => result, this.blockingActionService.run$(action$))
),
untilDestroyed(this)
)
.subscribe();
}
}

// Reload the app to force app to re-run the initialization in AppModule.
Expand Down
23 changes: 23 additions & 0 deletions src/app/shared/dia-backend/auth/dia-backend-auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,29 @@ export class DiaBackendAuthService {
);
}

deleteUser$(email: string) {
return defer(() => this.getAuthHeaders()).pipe(
concatMap(headers =>
this.httpClient.post<UpdateUserResponse>(
`https://node.numbersprotocol.io/api/1.1/wf/delete_user`,
{
account: email,
token: headers.authorization,
},
{ headers }
)
),
concatMapTo(this.readUser$()),
concatMap(response =>
forkJoin([
this.setUsername(response.username),
this.setEmail(response.email),
this.setRerferralCode(response.referral_code),
])
)
);
}

uploadAvatar$({ picture }: { picture: File }) {
const formData = new FormData();
formData.append('profile_picture', picture);
Expand Down
3 changes: 2 additions & 1 deletion src/assets/i18n/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"preview": "Preview",
"owner": "Owner",
"digitalAsset": "Digital Asset",
"delete": "Delete",
"delete": "Delete Account",
"share": "Share",
"saveToLocal": "Save to Local",
"copyCertificate": "Copy Certificate",
Expand Down Expand Up @@ -173,6 +173,7 @@
"deregisterFromNetwork": "Deregister from network",
"viewOnCaptureClub": "View on CaptureClub",
"viewBlockchainCertificate": "View blockchain certificate",
"confirmDelete": "Your local data will be wiped out after deletion. Please double-check that you have created a backup and understand the risk.",
"confirmLogout": "Your local data will be wipe out after logout. You can restore your Captures after login again.",
"resetPasswordEnterEmail": "To reset the password, you have to enter your registered email.",
"resetPasswordEmailSent": "An email has been sent to your registered email inbox. To reset your password, please click the link in the email.",
Expand Down
3 changes: 2 additions & 1 deletion src/assets/i18n/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"preview": "預覽",
"owner": "擁有者",
"digitalAsset": "數位資產",
"delete": "刪除",
"delete": "刪除帳號",
"share": "分享",
"saveToLocal": "另存至本地",
"copyCertificate": "複製證書",
Expand Down Expand Up @@ -173,6 +173,7 @@
"deregisterFromNetwork": "刪除並從影像網絡註銷",
"viewOnCaptureClub": "在 CaptureClub 檢視",
"viewBlockchainCertificate": "檢視區塊鏈證書",
"confirmDelete": "所有您的本地資料將會在刪除帳號後清除。請再次確認您已備份資料並了解其中的風險。",
"confirmLogout": "所有您的本地資料將會在登出後清除。再次登入後可以復原您的拍攝。",
"resetPasswordEnterEmail": "請輸入您的註冊信箱以重新設定密碼。",
"resetPasswordEmailSent": "重新設定密碼的連結已經寄送至您註冊的電子信箱,請開啟您的電子信箱並點擊該連結以重新設定密碼。",
Expand Down

0 comments on commit 693d3aa

Please sign in to comment.