Initial commit of unified WebGIS projects
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
include __DIR__ . '/../../config/koneksi.php';
|
||||
include __DIR__ . '/mail_helper.php';
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
// Support JSON and form-encoded
|
||||
$data = null;
|
||||
if($_SERVER['REQUEST_METHOD'] === 'POST'){
|
||||
$contentType = $_SERVER['CONTENT_TYPE'] ?? '';
|
||||
if(strpos($contentType, 'application/json') !== false){
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
} else {
|
||||
$data = $_POST;
|
||||
}
|
||||
}
|
||||
|
||||
$email = isset($data['email']) ? strtolower(trim($data['email'])) : null;
|
||||
|
||||
if(!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)){
|
||||
http_response_code(400);
|
||||
echo json_encode(['success'=>false,'error'=>'invalid_email']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Generate 6-digit code
|
||||
$verificationCode = str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
|
||||
$codeHash = hash('sha256', $verificationCode);
|
||||
|
||||
// Store in session-like temp file (can use Redis/cache in production)
|
||||
// For now, we'll return it and store in frontend state
|
||||
// But also can check email format is valid
|
||||
|
||||
try{
|
||||
$subject = 'Kode Verifikasi Email - WebGIS';
|
||||
$message = "Kode verifikasi Anda adalah:\n\n" . $verificationCode . "\n\nKode ini berlaku selama 15 menit. Jangan bagikan kode ini kepada siapapun.\n\nJika Anda tidak melakukan pendaftaran ini, abaikan email ini.";
|
||||
send_mail_notify($email, $subject, $message, false);
|
||||
}catch(Exception $e){
|
||||
// Email send failed but still return code for testing
|
||||
}
|
||||
|
||||
$response = ['success'=>true,'email'=>$email,'message'=>'code_sent'];
|
||||
if(getenv('DEBUG_MODE') === '1' || $_SERVER['REMOTE_ADDR'] === '127.0.0.1'){
|
||||
$response['debug_code'] = $verificationCode;
|
||||
}
|
||||
echo json_encode($response);
|
||||
?>
|
||||
Reference in New Issue
Block a user