recover password feature
This commit is contained in:
@@ -128,6 +128,23 @@ export const verificarDocumentosParaDownload = async (
|
||||
return para;
|
||||
};
|
||||
|
||||
/** Remove documentos descarregados e checksums (ex.: no logout). */
|
||||
export const clearDownloadedDocuments = async (): Promise<void> => {
|
||||
try {
|
||||
const keys = await AsyncStorage.getAllKeys();
|
||||
const docKeys = keys.filter((key) => key.startsWith("@cruiseLovers:documento:"));
|
||||
if (docKeys.length > 0) {
|
||||
await AsyncStorage.multiRemove(docKeys);
|
||||
}
|
||||
const info = await FileSystem.getInfoAsync(DOCUMENTOS_DIR);
|
||||
if (info.exists) {
|
||||
await FileSystem.deleteAsync(DOCUMENTOS_DIR, { idempotent: true });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Erro ao limpar documentos locais:", error);
|
||||
}
|
||||
};
|
||||
|
||||
// Descarrega múltiplos documentos
|
||||
export const downloadDocumentos = async (
|
||||
documentos: DocumentoChecksum[],
|
||||
|
||||
@@ -166,9 +166,11 @@ export const clearCache = async (): Promise<void> => {
|
||||
export const clearReservasCache = async (): Promise<void> => {
|
||||
try {
|
||||
const keys = await AsyncStorage.getAllKeys();
|
||||
const reservaKeys = keys.filter(key =>
|
||||
key === STORAGE_KEYS.RESERVAS ||
|
||||
key.startsWith(STORAGE_KEYS.RESERVA_DETAIL)
|
||||
const reservaKeys = keys.filter(
|
||||
(key) =>
|
||||
key === STORAGE_KEYS.RESERVAS ||
|
||||
key.startsWith(STORAGE_KEYS.RESERVA_DETAIL) ||
|
||||
key.startsWith(STORAGE_KEYS.RESERVA_FULL),
|
||||
);
|
||||
await AsyncStorage.multiRemove(reservaKeys);
|
||||
} catch (error) {
|
||||
@@ -176,6 +178,22 @@ export const clearReservasCache = async (): Promise<void> => {
|
||||
}
|
||||
};
|
||||
|
||||
/** Dados de sessão do utilizador — mantém contactos da agência (partilhados). */
|
||||
export const clearUserSessionCache = async (): Promise<void> => {
|
||||
try {
|
||||
const keys = await AsyncStorage.getAllKeys();
|
||||
const sessionKeys = keys.filter(
|
||||
(key) =>
|
||||
key.startsWith("@cruiseLovers:") &&
|
||||
key !== STORAGE_KEYS.CONTACTS &&
|
||||
key !== STORAGE_KEYS.SOCIALS,
|
||||
);
|
||||
await AsyncStorage.multiRemove(sessionKeys);
|
||||
} catch (error) {
|
||||
console.error("Erro ao limpar cache da sessão:", error);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Armazena informações do perfil no cache
|
||||
*/
|
||||
|
||||
50
assets/services/passwordRecovery.ts
Normal file
50
assets/services/passwordRecovery.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { API_ENDPOINTS, buildApiUrl } from '@/assets/config/api';
|
||||
import { ApiMessageResponse } from '@/assets/types';
|
||||
import CryptoJS from 'crypto-js';
|
||||
|
||||
async function postToEndpoint(
|
||||
endpoint: string,
|
||||
fields: Record<string, string>,
|
||||
): Promise<ApiMessageResponse> {
|
||||
const formData = new FormData();
|
||||
Object.entries(fields).forEach(([key, value]) => formData.append(key, value));
|
||||
|
||||
const response = await fetch(buildApiUrl(endpoint), {
|
||||
method: 'POST',
|
||||
headers: { Accept: 'application/json' },
|
||||
body: formData,
|
||||
});
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function recoverPassword(email: string): Promise<ApiMessageResponse> {
|
||||
return postToEndpoint(API_ENDPOINTS.RECOVER_PASSWORD, { email: email.trim() });
|
||||
}
|
||||
|
||||
export async function confirmRecoveryToken(
|
||||
email: string,
|
||||
token: string,
|
||||
): Promise<ApiMessageResponse> {
|
||||
return postToEndpoint(API_ENDPOINTS.CONFIRM_TOKEN, {
|
||||
email: email.trim(),
|
||||
token: token.trim(),
|
||||
});
|
||||
}
|
||||
|
||||
export async function resetPassword(
|
||||
email: string,
|
||||
token: string,
|
||||
password: string,
|
||||
confirmPassword: string,
|
||||
): Promise<ApiMessageResponse> {
|
||||
const encryptedPassword = CryptoJS.MD5(password).toString();
|
||||
const encryptedConfirm = CryptoJS.MD5(confirmPassword).toString();
|
||||
|
||||
return postToEndpoint(API_ENDPOINTS.RESET_PASSWORD, {
|
||||
email: email.trim(),
|
||||
token: token.trim(),
|
||||
password: encryptedPassword,
|
||||
confirmPassword: encryptedConfirm,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user