GOOGLE_CLIENT_ID, 'client_secret' => GOOGLE_CLIENT_SECRET, 'redirect_uri' => GOOGLE_REDIRECT_URI, 'grant_type' => 'authorization_code', 'code' => $code ])); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $token_data = json_decode($response, true); if (isset($token_data['access_token'])) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/oauth2/v3/userinfo"); curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Bearer " . $token_data['access_token']]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $user_data = json_decode(curl_exec($ch), true); curl_close($ch); if (isset($user_data['email'])) { $email = $user_data['email']; $name = $user_data['name']; $state_role = $_GET['state'] ?? 'guest'; $role = in_array($state_role, ['guest', 'petugas']) ? $state_role : 'guest'; $stmt = $pdo->prepare("SELECT * FROM users WHERE email = ? OR username = ?"); $stmt->execute([$email, $email]); $existing_user = $stmt->fetch(); if ($existing_user) { if ($existing_user['status'] === 'pending') { $sweetAlertScript = "Swal.fire({icon: 'warning', title: 'Menunggu Persetujuan', text: 'Akun Anda sedang menunggu persetujuan Admin.', confirmButtonColor: '#e11d48'});"; } else { $_SESSION['user_id'] = $existing_user['id']; $_SESSION['username'] = $existing_user['username']; $_SESSION['role'] = $existing_user['role']; header('Location: dashboard.php'); exit; } } else { $status = ($role === 'petugas') ? 'pending' : 'active'; $username = explode('@', $email)[0] . rand(100,999); $stmt = $pdo->prepare("INSERT INTO users (username, email, nama_lengkap, password, role, status, auth_provider) VALUES (?, ?, ?, ?, ?, ?, 'google')"); $stmt->execute([$username, $email, $name, password_hash(bin2hex(random_bytes(8)), PASSWORD_DEFAULT), $role, $status]); if ($role === 'petugas') { $sweetAlertScript = "Swal.fire({icon: 'success', title: 'Pendaftaran Berhasil', text: 'Pendaftaran via Google berhasil. Akun Anda menunggu persetujuan Admin.', confirmButtonColor: '#e11d48'}).then(() => { window.location.href = 'login.php'; });"; } else { $_SESSION['user_id'] = $pdo->lastInsertId(); $_SESSION['username'] = $username; $_SESSION['role'] = 'guest'; header('Location: dashboard.php'); exit; } } } } else { $sweetAlertScript = "Swal.fire({icon: 'error', title: 'Google Login Gagal', text: 'Terjadi kesalahan kredensial OAuth.', confirmButtonColor: '#e11d48'});"; } } // Proses Registrasi Lokal if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['register'])) { $nama_lengkap = trim($_POST['nama_lengkap'] ?? ''); $email = trim($_POST['email'] ?? ''); $password = trim($_POST['password'] ?? ''); $role = trim($_POST['role'] ?? 'guest'); if ($nama_lengkap && $email && $password && in_array($role, ['guest', 'petugas'])) { $stmt = $pdo->prepare("SELECT id FROM users WHERE email = ? OR username = ?"); $stmt->execute([$email, $email]); if ($stmt->fetch()) { $sweetAlertScript = "Swal.fire({icon: 'error', title: 'Registrasi Gagal', text: 'Email tersebut sudah terdaftar.', confirmButtonColor: '#e11d48'});"; } else { $status = ($role === 'petugas') ? 'pending' : 'active'; $username = explode('@', $email)[0] . rand(100,999); $stmt = $pdo->prepare("INSERT INTO users (username, email, nama_lengkap, password, role, status, auth_provider) VALUES (?, ?, ?, ?, ?, ?, 'local')"); if ($stmt->execute([$username, $email, $nama_lengkap, password_hash($password, PASSWORD_DEFAULT), $role, $status])) { if ($role === 'petugas') { $sweetAlertScript = "Swal.fire({icon: 'success', title: 'Pendaftaran Berhasil', text: 'Pendaftaran berhasil. Menunggu persetujuan Admin.', confirmButtonColor: '#e11d48'}).then(() => { window.location.href = 'login.php'; });"; } else { $sweetAlertScript = "Swal.fire({icon: 'success', title: 'Pendaftaran Berhasil', text: 'Akun Anda aktif, silakan masuk ke sistem.', confirmButtonColor: '#e11d48'}).then(() => { window.location.href = 'login.php'; });"; } } else { $sweetAlertScript = "Swal.fire({icon: 'error', title: 'Gagal', text: 'Terjadi kesalahan sistem internal.', confirmButtonColor: '#e11d48'});"; } } } else { $sweetAlertScript = "Swal.fire({icon: 'warning', title: 'Data Belum Lengkap', text: 'Harap lengkapi semua bidang yang tersedia.', confirmButtonColor: '#e11d48'});"; } } // URL OAuth Google $google_auth_url = "https://accounts.google.com/o/oauth2/v2/auth?client_id=" . GOOGLE_CLIENT_ID . "&redirect_uri=" . urlencode(GOOGLE_REDIRECT_URI) . "&response_type=code&scope=email%20profile"; ?> Register – WebGIS Pengentasan Kemiskinan

Buat Akun Baru

Isi data di bawah ini untuk membuat akun WebGIS Anda.

atau dengan email
Sudah punya akun? Masuk di sini

© WebGIS Geospasial · Kementerian Analisis Spasial