-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78ef30f
commit fef67a3
Showing
11 changed files
with
225 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import apiClient from '@/service/api-client'; | ||
import authService from '@/service/auth-service'; | ||
import localAuthService from '@/service/local-auth-service'; | ||
import userService from '@/service/user-service'; | ||
import { userStorage } from '@/store/main-store'; | ||
import { simpleActionSheetConfirm, simpleAlert } from '@/utilities/alert'; | ||
import { useLoadingOverlay } from '@/utilities/loading'; | ||
import { hexToBigint } from '@windwalker-io/srp'; | ||
import { bigintToHex } from 'bigint-toolkit'; | ||
|
||
export default new class { | ||
async deleteMeAndLogout() { | ||
await this.deleteMe(); | ||
|
||
await userService.logoutAndRedirect(); | ||
} | ||
|
||
async deleteMe() { | ||
const v = await simpleActionSheetConfirm( | ||
'This action cannot redo.', | ||
[ | ||
'Delete It', | ||
'Cancel', | ||
], | ||
{ | ||
subHeader: 'Do you really want to delete account?' | ||
} | ||
); | ||
|
||
if (!v) { | ||
return; | ||
} | ||
|
||
const password = await userService.askPassword( | ||
'Your Password', | ||
'Please enter master password again' | ||
); | ||
|
||
if (!password) { | ||
return; | ||
} | ||
|
||
const kek = await localAuthService.validatePasswordAndGetKek(password); | ||
|
||
if (!kek) { | ||
simpleAlert('Invalid password.'); | ||
return; | ||
} | ||
|
||
const { loading, run } = await useLoadingOverlay('Deleting account...'); | ||
|
||
await run(async () => { | ||
const user = userStorage.value!; | ||
const { salt, B, sess } = await authService.challenge(user.email); | ||
|
||
const { A, M1, S } = await authService.runSRPLoginSteps( | ||
user.email, | ||
password, | ||
hexToBigint(salt), | ||
hexToBigint(B), | ||
); | ||
|
||
return this.deleteAccount(A, M1, sess); | ||
}); | ||
} | ||
|
||
async deleteAccount(A: bigint, M1: bigint, sess: string) { | ||
const user = userStorage.value!; | ||
|
||
return apiClient.post( | ||
'auth/delete/me', | ||
{ | ||
email: user.email, | ||
A: bigintToHex(A), | ||
M1: bigintToHex(M1), | ||
sess, | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.