Merge pull request #5421 from freesewing/joost
fix(org/backend): Fix issue with email change. Closes #5420
This commit is contained in:
commit
2ad0d471d0
2 changed files with 15 additions and 17 deletions
|
@ -1432,9 +1432,13 @@ UserModel.prototype.guardedUpdate = async function ({ body, user }) {
|
|||
* Update the email address and ehash
|
||||
*/
|
||||
await this.update({
|
||||
email: this.encrypt(data.email.new),
|
||||
email: data.email.new,
|
||||
ehash: hash(clean(data.email.new)),
|
||||
})
|
||||
/*
|
||||
* Remove the confirmation
|
||||
*/
|
||||
await this.Confirmation.delete()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1515,7 +1519,7 @@ UserModel.prototype.guardedMfaUpdate = async function ({ body, user, ip }) {
|
|||
this.clear.data.mfaScratchCodes
|
||||
)
|
||||
let result, mfaScratchCodes
|
||||
if (Array.isArray(check)) [result, mfaScratchCodes] = check
|
||||
if (Array.isArray(check)) [result] = check
|
||||
else result = check
|
||||
if (result) {
|
||||
/*
|
||||
|
@ -1553,7 +1557,7 @@ UserModel.prototype.guardedMfaUpdate = async function ({ body, user, ip }) {
|
|||
*/
|
||||
const check = await this.mfa.verify(body.token, this.clear.mfaSecret, false)
|
||||
let result, mfaScratchCodes
|
||||
if (Array.isArray(check)) [result, mfaScratchCodes] = check
|
||||
if (Array.isArray(check)) [result] = check
|
||||
else result = check
|
||||
if (body.secret === this.clear.mfaSecret && result) {
|
||||
/*
|
||||
|
|
|
@ -23,7 +23,7 @@ const ns = nsMerge(pageNs, 'account', 'susi')
|
|||
|
||||
const ConfirmSignUpPage = ({ page }) => {
|
||||
// Hooks
|
||||
const { setAccount, setToken, token } = useAccount()
|
||||
const { setAccount, token } = useAccount()
|
||||
const backend = useBackend()
|
||||
const { setLoadingStatus } = useContext(LoadingStatusContext)
|
||||
const { t } = useTranslation(ns)
|
||||
|
@ -33,6 +33,7 @@ const ConfirmSignUpPage = ({ page }) => {
|
|||
const [error, setError] = useState(false)
|
||||
const [id, setId] = useState()
|
||||
const [check, setCheck] = useState()
|
||||
const [updated, setUpdated] = useState()
|
||||
|
||||
useEffect(() => {
|
||||
const newId = getSearchParam('id')
|
||||
|
@ -47,30 +48,23 @@ const ConfirmSignUpPage = ({ page }) => {
|
|||
const confirmEmail = async () => {
|
||||
setLoadingStatus([true, 'status:contactingBackend'])
|
||||
const confirmation = await backend.loadConfirmation({ id, check })
|
||||
if (confirmation?.result === 'success' && confirmation.confirmation) {
|
||||
if (confirmation.success && confirmation.data.confirmation) {
|
||||
const result = await backend.updateAccount({
|
||||
confirm: 'emailchange',
|
||||
confirmation: confirmation.confirmation.id,
|
||||
check: confirmation.confirmation.check,
|
||||
confirmation: confirmation.data.confirmation.id,
|
||||
check: confirmation.data.confirmation.check,
|
||||
})
|
||||
if (result.success) {
|
||||
if (result.success && !updated) {
|
||||
setLoadingStatus([true, 'status:settingsSaved', true, true])
|
||||
setAccount(result.data.account)
|
||||
setToken(result.data.token)
|
||||
setError(false)
|
||||
router.push('/account')
|
||||
} else {
|
||||
setLoadingStatus([true, 'status:backendError', true, false])
|
||||
setError(true)
|
||||
}
|
||||
} else {
|
||||
setLoadingStatus([true, 'status:backendError', true, false])
|
||||
setError(true)
|
||||
}
|
||||
}
|
||||
// Call async methods
|
||||
if (token) confirmEmail()
|
||||
}, [id, check, token, backend, router, setAccount, setToken])
|
||||
if (token && id && check && !updated) confirmEmail()
|
||||
}, [id, check, backend, router, setAccount])
|
||||
|
||||
// Update path with dynamic ID
|
||||
if (!page) return null
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue