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
|
* Update the email address and ehash
|
||||||
*/
|
*/
|
||||||
await this.update({
|
await this.update({
|
||||||
email: this.encrypt(data.email.new),
|
email: data.email.new,
|
||||||
ehash: hash(clean(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
|
this.clear.data.mfaScratchCodes
|
||||||
)
|
)
|
||||||
let result, mfaScratchCodes
|
let result, mfaScratchCodes
|
||||||
if (Array.isArray(check)) [result, mfaScratchCodes] = check
|
if (Array.isArray(check)) [result] = check
|
||||||
else result = check
|
else result = check
|
||||||
if (result) {
|
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)
|
const check = await this.mfa.verify(body.token, this.clear.mfaSecret, false)
|
||||||
let result, mfaScratchCodes
|
let result, mfaScratchCodes
|
||||||
if (Array.isArray(check)) [result, mfaScratchCodes] = check
|
if (Array.isArray(check)) [result] = check
|
||||||
else result = check
|
else result = check
|
||||||
if (body.secret === this.clear.mfaSecret && result) {
|
if (body.secret === this.clear.mfaSecret && result) {
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -23,7 +23,7 @@ const ns = nsMerge(pageNs, 'account', 'susi')
|
||||||
|
|
||||||
const ConfirmSignUpPage = ({ page }) => {
|
const ConfirmSignUpPage = ({ page }) => {
|
||||||
// Hooks
|
// Hooks
|
||||||
const { setAccount, setToken, token } = useAccount()
|
const { setAccount, token } = useAccount()
|
||||||
const backend = useBackend()
|
const backend = useBackend()
|
||||||
const { setLoadingStatus } = useContext(LoadingStatusContext)
|
const { setLoadingStatus } = useContext(LoadingStatusContext)
|
||||||
const { t } = useTranslation(ns)
|
const { t } = useTranslation(ns)
|
||||||
|
@ -33,6 +33,7 @@ const ConfirmSignUpPage = ({ page }) => {
|
||||||
const [error, setError] = useState(false)
|
const [error, setError] = useState(false)
|
||||||
const [id, setId] = useState()
|
const [id, setId] = useState()
|
||||||
const [check, setCheck] = useState()
|
const [check, setCheck] = useState()
|
||||||
|
const [updated, setUpdated] = useState()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const newId = getSearchParam('id')
|
const newId = getSearchParam('id')
|
||||||
|
@ -47,30 +48,23 @@ const ConfirmSignUpPage = ({ page }) => {
|
||||||
const confirmEmail = async () => {
|
const confirmEmail = async () => {
|
||||||
setLoadingStatus([true, 'status:contactingBackend'])
|
setLoadingStatus([true, 'status:contactingBackend'])
|
||||||
const confirmation = await backend.loadConfirmation({ id, check })
|
const confirmation = await backend.loadConfirmation({ id, check })
|
||||||
if (confirmation?.result === 'success' && confirmation.confirmation) {
|
if (confirmation.success && confirmation.data.confirmation) {
|
||||||
const result = await backend.updateAccount({
|
const result = await backend.updateAccount({
|
||||||
confirm: 'emailchange',
|
confirm: 'emailchange',
|
||||||
confirmation: confirmation.confirmation.id,
|
confirmation: confirmation.data.confirmation.id,
|
||||||
check: confirmation.confirmation.check,
|
check: confirmation.data.confirmation.check,
|
||||||
})
|
})
|
||||||
if (result.success) {
|
if (result.success && !updated) {
|
||||||
setLoadingStatus([true, 'status:settingsSaved', true, true])
|
setLoadingStatus([true, 'status:settingsSaved', true, true])
|
||||||
setAccount(result.data.account)
|
setAccount(result.data.account)
|
||||||
setToken(result.data.token)
|
|
||||||
setError(false)
|
setError(false)
|
||||||
router.push('/account')
|
router.push('/account')
|
||||||
} else {
|
|
||||||
setLoadingStatus([true, 'status:backendError', true, false])
|
|
||||||
setError(true)
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
setLoadingStatus([true, 'status:backendError', true, false])
|
|
||||||
setError(true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Call async methods
|
// Call async methods
|
||||||
if (token) confirmEmail()
|
if (token && id && check && !updated) confirmEmail()
|
||||||
}, [id, check, token, backend, router, setAccount, setToken])
|
}, [id, check, backend, router, setAccount])
|
||||||
|
|
||||||
// Update path with dynamic ID
|
// Update path with dynamic ID
|
||||||
if (!page) return null
|
if (!page) return null
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue