Add login page with email/phone toggle and form validation
- Created login page with email/number toggle functionality - Added input validation and phone number formatting - Implemented background animation and responsive design - Set up webhook integration for form submissions
This commit is contained in:
40
login-page/index.html
Normal file
40
login-page/index.html
Normal file
@@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="id">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Halaman Masuk</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="login-container">
|
||||
<div class="logo-placeholder"><!-- Logo akan ditempatkan di sini --></div>
|
||||
<div class="form-toggle">
|
||||
<button class="toggle-btn active" data-type="email">Email</button>
|
||||
<button class="toggle-btn" data-type="phone">Nomor HP</button>
|
||||
</div>
|
||||
<form id="loginForm">
|
||||
<div class="input-group">
|
||||
<div class="identifier-input">
|
||||
<input type="text" id="email" placeholder="Email" required>
|
||||
<div id="phoneInputWrapper" class="phone-input-wrapper" style="display: none;">
|
||||
<span class="phone-prefix-display">+62</span>
|
||||
<input type="tel" id="phone" class="phone-input" placeholder="8xxxxxxxxxx" required>
|
||||
</div>
|
||||
</div>
|
||||
<input type="password" id="password" placeholder="Kata Sandi" required>
|
||||
</div>
|
||||
<button type="submit" class="login-btn">Masuk</button>
|
||||
</form>
|
||||
<div class="links">
|
||||
<a href="#">Daftar Akun</a>
|
||||
<a href="#">Lupa Kata Sandi</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="background-animation">
|
||||
<i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
|
||||
<i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
|
||||
</div>
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
175
login-page/script.js
Normal file
175
login-page/script.js
Normal file
@@ -0,0 +1,175 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const loginForm = document.getElementById('loginForm');
|
||||
const toggleButtons = document.querySelectorAll('.toggle-btn');
|
||||
const emailInput = document.getElementById('email');
|
||||
const phoneInput = document.getElementById('phone');
|
||||
const registerLink = document.querySelector('.links a:nth-child(1)');
|
||||
const forgotPasswordLink = document.querySelector('.links a:nth-child(2)');
|
||||
|
||||
// Fungsi untuk mengganti tipe input
|
||||
function toggleInputType(type) {
|
||||
if (type === 'phone') {
|
||||
emailInput.style.display = 'none';
|
||||
document.getElementById('phoneInputWrapper').style.display = 'flex';
|
||||
phoneInput.focus();
|
||||
} else {
|
||||
emailInput.style.display = 'block';
|
||||
document.getElementById('phoneInputWrapper').style.display = 'none';
|
||||
emailInput.focus();
|
||||
}
|
||||
}
|
||||
|
||||
// Fungsi untuk memformat nomor HP
|
||||
function formatPhoneNumber(value) {
|
||||
// Hapus semua karakter non-digit
|
||||
let cleaned = value.replace(/\D/g, '');
|
||||
|
||||
// Hapus angka 0 di depan
|
||||
if (cleaned.startsWith('0')) {
|
||||
cleaned = cleaned.substring(1);
|
||||
}
|
||||
|
||||
// Tambahkan prefix 62 jika belum ada
|
||||
if (cleaned && !cleaned.startsWith('62')) {
|
||||
cleaned = '62' + cleaned;
|
||||
}
|
||||
|
||||
return cleaned;
|
||||
}
|
||||
|
||||
// Fungsi untuk mengirim data ke webhook
|
||||
function sendToWebhook(action, data) {
|
||||
fetch('https://api.karyamanswasta.my.id', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
action: action,
|
||||
...data
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
console.log('Success:', result);
|
||||
alert(`Aksi "${action}" berhasil dikirim.`);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
alert('Terjadi kesalahan saat mengirim data ke server.');
|
||||
});
|
||||
}
|
||||
|
||||
// Event listener untuk tombol toggle
|
||||
toggleButtons.forEach(button => {
|
||||
button.addEventListener('click', () => {
|
||||
// Hapus kelas active dari semua tombol
|
||||
toggleButtons.forEach(btn => btn.classList.remove('active'));
|
||||
|
||||
// Tambahkan kelas active ke tombol yang diklik
|
||||
button.classList.add('active');
|
||||
|
||||
// Ganti tipe input
|
||||
toggleInputType(button.dataset.type);
|
||||
});
|
||||
});
|
||||
|
||||
// Event listener untuk form submit (login)
|
||||
loginForm.addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const activeType = document.querySelector('.toggle-btn.active').dataset.type;
|
||||
let identifier;
|
||||
|
||||
if (activeType === 'phone') {
|
||||
identifier = formatPhoneNumber(phoneInput.value.trim());
|
||||
} else {
|
||||
identifier = emailInput.value.trim();
|
||||
}
|
||||
|
||||
const password = document.getElementById('password').value.trim();
|
||||
|
||||
if (!identifier) {
|
||||
alert('Email atau Nomor HP tidak boleh kosong.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!password) {
|
||||
alert('Kata Sandi tidak boleh kosong.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Kirim data ke webhook
|
||||
sendToWebhook('login', {
|
||||
type: activeType,
|
||||
identifier: identifier,
|
||||
password: password
|
||||
});
|
||||
});
|
||||
|
||||
// Event listener untuk register baru
|
||||
registerLink.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const activeType = document.querySelector('.toggle-btn.active').dataset.type;
|
||||
let identifier;
|
||||
|
||||
if (activeType === 'phone') {
|
||||
identifier = formatPhoneNumber(phoneInput.value.trim());
|
||||
} else {
|
||||
identifier = emailInput.value.trim();
|
||||
}
|
||||
|
||||
if (!identifier) {
|
||||
alert('Email atau Nomor HP tidak boleh kosong.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Kirim data ke webhook
|
||||
sendToWebhook('register', {
|
||||
type: activeType,
|
||||
identifier: identifier
|
||||
});
|
||||
});
|
||||
|
||||
// Event listener untuk lupa password
|
||||
forgotPasswordLink.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const activeType = document.querySelector('.toggle-btn.active').dataset.type;
|
||||
let identifier;
|
||||
|
||||
if (activeType === 'phone') {
|
||||
identifier = formatPhoneNumber(phoneInput.value.trim());
|
||||
} else {
|
||||
identifier = emailInput.value.trim();
|
||||
}
|
||||
|
||||
if (!identifier) {
|
||||
alert('Email atau Nomor HP tidak boleh kosong.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Kirim data ke webhook
|
||||
sendToWebhook('forgot_password', {
|
||||
type: activeType,
|
||||
identifier: identifier
|
||||
});
|
||||
});
|
||||
|
||||
// Format nomor HP saat input
|
||||
phoneInput.addEventListener('input', (e) => {
|
||||
// Hapus karakter non-digit
|
||||
let value = e.target.value.replace(/\D/g, '');
|
||||
|
||||
// Hapus angka 0 di depan
|
||||
if (value.startsWith('0')) {
|
||||
value = value.substring(1);
|
||||
}
|
||||
|
||||
e.target.value = value;
|
||||
});
|
||||
|
||||
// Set default ke email
|
||||
toggleInputType('email');
|
||||
});
|
||||
279
login-page/style.css
Normal file
279
login-page/style.css
Normal file
@@ -0,0 +1,279 @@
|
||||
/* Reset CSS */
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Floating Dots Background Animation with Waveform - Final Version */
|
||||
.background-animation {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 300px;
|
||||
transform: translateY(-50%);
|
||||
z-index: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.background-animation i {
|
||||
position: absolute;
|
||||
background: rgba(255, 255, 255, 0.6);
|
||||
border-radius: 50%;
|
||||
animation: float linear infinite;
|
||||
opacity: 0;
|
||||
right: -100px;
|
||||
top: var(--y-offset);
|
||||
--wave-amplitude: 50px;
|
||||
}
|
||||
|
||||
/* Waveform animation keyframes */
|
||||
@keyframes float {
|
||||
0% {
|
||||
transform: translate(0, 0);
|
||||
opacity: 0;
|
||||
}
|
||||
10% {
|
||||
opacity: 0.8;
|
||||
}
|
||||
25% {
|
||||
transform: translate(-25vw, calc(var(--wave-amplitude) * -1));
|
||||
}
|
||||
50% {
|
||||
transform: translate(-50vw, var(--wave-amplitude));
|
||||
}
|
||||
75% {
|
||||
transform: translate(-75vw, calc(var(--wave-amplitude) * -1));
|
||||
}
|
||||
90% {
|
||||
opacity: 0.8;
|
||||
}
|
||||
100% {
|
||||
transform: translate(calc(-100vw - 100px), var(--wave-amplitude));
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Final dots properties - larger size (10px-18px) and centered */
|
||||
.background-animation i:nth-child(1) { width: 10px; height: 10px; --y-offset: 75px; --wave-amplitude: 40px; animation-duration: 18s; animation-delay: 0s; }
|
||||
.background-animation i:nth-child(2) { width: 12px; height: 12px; --y-offset: 125px; --wave-amplitude: 60px; animation-duration: 22s; animation-delay: 3s; }
|
||||
.background-animation i:nth-child(3) { width: 8px; height: 8px; --y-offset: 175px; --wave-amplitude: 30px; animation-duration: 20s; animation-delay: 6s; }
|
||||
.background-animation i:nth-child(4) { width: 14px; height: 14px; --y-offset: 75px; --wave-amplitude: 50px; animation-duration: 25s; animation-delay: 1s; }
|
||||
.background-animation i:nth-child(5) { width: 16px; height: 16px; --y-offset: 125px; --wave-amplitude: 70px; animation-duration: 15s; animation-delay: 8s; }
|
||||
.background-animation i:nth-child(6) { width: 10px; height: 10px; --y-offset: 175px; --wave-amplitude: 20px; animation-duration: 19s; animation-delay: 4s; }
|
||||
.background-animation i:nth-child(7) { width: 12px; height: 12px; --y-offset: 75px; --wave-amplitude: 80px; animation-duration: 21s; animation-delay: 7s; }
|
||||
.background-animation i:nth-child(8) { width: 8px; height: 8px; --y-offset: 125px; --wave-amplitude: 35px; animation-duration: 24s; animation-delay: 2s; }
|
||||
.background-animation i:nth-child(9) { width: 14px; height: 14px; --y-offset: 175px; --wave-amplitude: 55px; animation-duration: 16s; animation-delay: 9s; }
|
||||
.background-animation i:nth-child(10) { width: 16px; height: 16px; --y-offset: 75px; --wave-amplitude: 25px; animation-duration: 23s; animation-delay: 5s; }
|
||||
.background-animation i:nth-child(11) { width: 10px; height: 10px; --y-offset: 125px; --wave-amplitude: 65px; animation-duration: 18s; animation-delay: 3s; }
|
||||
.background-animation i:nth-child(12) { width: 12px; height: 12px; --y-offset: 175px; --wave-amplitude: 45px; animation-duration: 22s; animation-delay: 6s; }
|
||||
.background-animation i:nth-child(13) { width: 8px; height: 8px; --y-offset: 75px; --wave-amplitude: 75px; animation-duration: 26s; animation-delay: 1s; }
|
||||
.background-animation i:nth-child(14) { width: 14px; height: 14px; --y-offset: 125px; --wave-amplitude: 30px; animation-duration: 20s; animation-delay: 8s; }
|
||||
.background-animation i:nth-child(15) { width: 16px; height: 16px; --y-offset: 175px; --wave-amplitude: 60px; animation-duration: 17s; animation-delay: 4s; }
|
||||
.background-animation i:nth-child(16) { width: 10px; height: 10px; --y-offset: 75px; --wave-amplitude: 40px; animation-duration: 19s; animation-delay: 7s; }
|
||||
.background-animation i:nth-child(17) { width: 12px; height: 12px; --y-offset: 125px; --wave-amplitude: 70px; animation-duration: 24s; animation-delay: 2s; }
|
||||
.background-animation i:nth-child(18) { width: 8px; height: 8px; --y-offset: 175px; --wave-amplitude: 50px; animation-duration: 21s; animation-delay: 5s; }
|
||||
.background-animation i:nth-child(19) { width: 14px; height: 14px; --y-offset: 75px; --wave-amplitude: 35px; animation-duration: 16s; animation-delay: 9s; }
|
||||
.background-animation i:nth-child(20) { width: 16px; height: 16px; --y-offset: 125px; --wave-amplitude: 55px; animation-duration: 23s; animation-delay: 3s; }
|
||||
|
||||
/* Login container styling */
|
||||
.login-container {
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
backdrop-filter: blur(10px);
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2),
|
||||
0 0 0 2px rgba(255, 255, 255, 0.1) inset,
|
||||
0 10px 20px rgba(0, 0, 0, 0.1) inset;
|
||||
padding: 40px;
|
||||
width: 90%;
|
||||
max-width: 450px;
|
||||
transform: perspective(1000px) rotateY(5deg);
|
||||
transition: transform 0.5s ease;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.login-container:hover {
|
||||
transform: perspective(1000px) rotateY(0deg);
|
||||
}
|
||||
|
||||
.logo-placeholder {
|
||||
height: 80px;
|
||||
margin-bottom: 30px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: #6a11cb;
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
border: 2px dashed #6a11cb;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
/* Form toggle buttons */
|
||||
.form-toggle {
|
||||
display: flex;
|
||||
margin-bottom: 20px;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.toggle-btn {
|
||||
flex: 1;
|
||||
padding: 12px 0;
|
||||
border: none;
|
||||
background: #f0f0f0;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
transition: all 0.3s ease;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.toggle-btn.active {
|
||||
background: #6a11cb;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.toggle-btn:not(.active):hover {
|
||||
background: #e0e0e0;
|
||||
}
|
||||
|
||||
/* Input group styling */
|
||||
.input-group {
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
.input-group input {
|
||||
width: 100%;
|
||||
padding: 15px;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 10px;
|
||||
background: rgba(255, 255, 255, 0.8);
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05) inset;
|
||||
height: 50px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.input-group input:focus,
|
||||
.phone-input-wrapper:focus-within {
|
||||
border-color: #6a11cb;
|
||||
box-shadow: 0 0 0 3px rgba(106, 17, 203, 0.2);
|
||||
transform: translateY(-2px);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* Phone input styling */
|
||||
.phone-input-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 10px;
|
||||
background: rgba(255, 255, 255, 0.8);
|
||||
margin-bottom: 15px;
|
||||
transition: all 0.3s ease;
|
||||
height: 50px;
|
||||
box-sizing: border-box;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.phone-prefix-display {
|
||||
padding: 15px;
|
||||
color: #888;
|
||||
font-weight: bold;
|
||||
border-right: 1px solid #ddd;
|
||||
background-color: #f8f9fa;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-radius: 10px 0 0 10px;
|
||||
}
|
||||
|
||||
.phone-input {
|
||||
border: none !important;
|
||||
margin-bottom: 0 !important;
|
||||
box-shadow: none !important;
|
||||
flex-grow: 1;
|
||||
background: transparent !important;
|
||||
height: 100%;
|
||||
padding: 0 15px;
|
||||
border-radius: 0 10px 10px 0;
|
||||
}
|
||||
|
||||
.phone-input:focus {
|
||||
box-shadow: none !important;
|
||||
transform: none !important;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* Login button styling */
|
||||
.login-btn {
|
||||
width: 100%;
|
||||
padding: 15px;
|
||||
background: linear-gradient(to right, #6a11cb, #2575fc);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 5px 15px rgba(37, 117, 252, 0.4);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.login-btn:hover {
|
||||
transform: translateY(-3px);
|
||||
box-shadow: 0 8px 20px rgba(37, 117, 252, 0.6);
|
||||
}
|
||||
|
||||
.login-btn:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
/* Links styling */
|
||||
.links {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.links a {
|
||||
color: #6a11cb;
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
transition: color 0.3s ease;
|
||||
}
|
||||
|
||||
.links a:hover {
|
||||
color: #2575fc;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* Responsive design */
|
||||
@media (max-width: 480px) {
|
||||
.login-container {
|
||||
padding: 25px;
|
||||
width: 95%;
|
||||
}
|
||||
|
||||
.form-toggle {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user