`),
+ )
+ return { success: true }
+}
+
+export async function confirmNewEmail(hash: string): Promise {
+ const [rows] = await db(DB.default).query(
+ 'SELECT id, email, old_email, password FROM home_accountactivation WHERE hash = ? AND is_new_email_used = 0 AND old_email IS NOT NULL',
+ [hash],
+ )
+ const act = rows[0]
+ if (!act) return { success: false, error: 'invalidLink' }
+ await db(DB.default).query('UPDATE home_accountactivation SET is_new_email_used = 1 WHERE id = ?', [act.id])
+
+ const newNorm = normalizeEmail(act.email)
+ const oldNorm = normalizeEmail(act.old_email || '')
+ try {
+ const reg = bnetMakeRegistration(newNorm, act.password)
+ const [bnetRows] = await db(DB.auth).query(
+ 'SELECT id FROM battlenet_accounts WHERE email = ?',
+ [oldNorm],
+ )
+ if (!bnetRows[0]) return { success: false, error: 'accountNotFound' }
+ const bnetId = bnetRows[0].id
+ await db(DB.auth).query(
+ 'UPDATE battlenet_accounts SET email = ?, srp_version = ?, salt = ?, verifier = ? WHERE id = ?',
+ [newNorm, reg.srpVersion, reg.salt, reg.verifier, bnetId],
+ )
+ await db(DB.auth).query('UPDATE account SET email = ?, reg_mail = ? WHERE battlenet_account = ?', [
+ newNorm,
+ newNorm,
+ bnetId,
+ ])
+ } catch {
+ return { success: false, error: 'genericError' }
+ }
+ await db(DB.default).query('DELETE FROM home_accountactivation WHERE id = ?', [act.id])
+ return { success: true }
+}
diff --git a/web-next/messages/en.json b/web-next/messages/en.json
index e143ebe..f6f0090 100644
--- a/web-next/messages/en.json
+++ b/web-next/messages/en.json
@@ -206,5 +206,36 @@
"wrongCurrentPassword": "The current password is incorrect.",
"accountNotFound": "Account not found.",
"genericError": "Something went wrong. Please try again later."
+ },
+ "ChangeEmail": {
+ "title": "Change email",
+ "info": "The current email must be entered exactly, respecting case. The new email must be a Gmail address. You need a security token.",
+ "currentPassword": "Current password",
+ "currentEmail": "Current email",
+ "newEmail": "New email",
+ "confEmail": "Confirm new email",
+ "token": "Security token",
+ "submit": "Change email",
+ "sending": "Sending…",
+ "success": "A confirmation email has been sent to your current email.",
+ "missingFields": "Please fill in all fields.",
+ "wrongCurrentEmail": "The current email is not correct.",
+ "invalidEmail": "The new email is not valid.",
+ "invalidToken": "The security token is incorrect.",
+ "wrongCurrentPassword": "The current password is incorrect.",
+ "genericError": "Something went wrong. Please try again later."
+ },
+ "ConfirmOldEmail": {
+ "title": "Confirm email change",
+ "activating": "Confirming…",
+ "success": "Current email confirmed. Check your NEW email to complete the second step.",
+ "error": "The link is invalid or has already been used."
+ },
+ "ConfirmNewEmail": {
+ "title": "Confirm new email",
+ "activating": "Applying the change…",
+ "success": "Email changed successfully! You can now sign in with the new email.",
+ "error": "The link is invalid, expired or the account was not found.",
+ "goLogin": "Go to sign in"
}
}
diff --git a/web-next/messages/es.json b/web-next/messages/es.json
index 700437f..8a0ce81 100644
--- a/web-next/messages/es.json
+++ b/web-next/messages/es.json
@@ -206,5 +206,36 @@
"wrongCurrentPassword": "La contraseña actual es incorrecta.",
"accountNotFound": "No se ha encontrado la cuenta.",
"genericError": "Algo ha salido mal. Inténtalo más tarde."
+ },
+ "ChangeEmail": {
+ "title": "Cambiar correo",
+ "info": "El correo actual debe escribirse tal cual, respetando mayúsculas/minúsculas. El nuevo correo debe ser de Gmail. Necesitas un token de seguridad.",
+ "currentPassword": "Contraseña actual",
+ "currentEmail": "Correo actual",
+ "newEmail": "Nuevo correo",
+ "confEmail": "Confirmar nuevo correo",
+ "token": "Token de seguridad",
+ "submit": "Cambiar correo",
+ "sending": "Enviando…",
+ "success": "Se ha enviado un correo de confirmación a tu correo actual.",
+ "missingFields": "Por favor, complete todos los campos.",
+ "wrongCurrentEmail": "El correo actual no es correcto.",
+ "invalidEmail": "El nuevo correo no es válido.",
+ "invalidToken": "El token de seguridad es incorrecto.",
+ "wrongCurrentPassword": "La contraseña actual es incorrecta.",
+ "genericError": "Algo ha salido mal. Inténtalo más tarde."
+ },
+ "ConfirmOldEmail": {
+ "title": "Confirmar cambio de correo",
+ "activating": "Confirmando…",
+ "success": "Correo actual confirmado. Revisa tu NUEVO correo para completar el segundo paso.",
+ "error": "El enlace no es válido o ya se ha usado."
+ },
+ "ConfirmNewEmail": {
+ "title": "Confirmar nuevo correo",
+ "activating": "Aplicando el cambio…",
+ "success": "¡Correo cambiado con éxito! Ya puedes iniciar sesión con el nuevo correo.",
+ "error": "El enlace no es válido, ha caducado o no se ha encontrado la cuenta.",
+ "goLogin": "Ir a iniciar sesión"
}
}