curl --request POST \
--url https://api.example.com/auth/check_user.php \
--header 'Accept: <accept>' \
--header 'Content-Type: <content-type>' \
--data '
{
"email": "<string>"
}
'{
"exists": true
}Check if a user account exists for an email address
curl --request POST \
--url https://api.example.com/auth/check_user.php \
--header 'Accept: <accept>' \
--header 'Content-Type: <content-type>' \
--data '
{
"email": "<string>"
}
'{
"exists": true
}POST /auth/check_user.php
application/jsonapplication/jsontrue if a user with this email exists, false otherwisecurl -X POST https://76.13.114.194/auth/check_user.php \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"email": "[email protected]"
}'
{
"exists": true
}
Future<void> validateEmail(String email) async {
final exists = await checkEmailExists(email);
if (exists) {
showError('Este email ya está registrado. ¿Desea iniciar sesión?');
// Show login option
} else {
// Proceed with registration
navigateToRegistrationForm(email);
}
}
async function initiatePasswordReset(email) {
const exists = await checkEmailExists(email);
if (!exists) {
alert('No hay cuenta asociada con este email');
return;
}
// Send password reset email
await sendPasswordResetEmail(email);
}
Future<void> handleEmailSubmit(String email) async {
final exists = await checkEmailExists(email);
if (exists) {
// Show password field for login
setState(() {
showPasswordField = true;
isLoginMode = true;
});
} else {
// Navigate to registration
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => RegisterScreen(email: email),
),
);
}
}
{"exists": false} on any error or if the request times out. This prevents exposing information about whether emails exist in the database during error conditions.Future<Map<String, dynamic>> checkUserExists(String email) async {
try {
final response = await client.post(
Uri.parse('$_baseUrl/check_user.php'),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: jsonEncode({'email': email}),
).timeout(AppConfig.connectionTimeout);
if (response.statusCode == 200) {
return jsonDecode(response.body) as Map<String, dynamic>;
}
return {'exists': false};
} catch (e) {
return {'exists': false};
}
}