Spaces:
Sleeping
Sleeping
Update static/auth.html
Browse files- static/auth.html +45 -106
static/auth.html
CHANGED
|
@@ -4,6 +4,7 @@
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Appwrite Auth</title>
|
|
|
|
| 7 |
<style>
|
| 8 |
body {
|
| 9 |
font-family: Arial, sans-serif;
|
|
@@ -14,87 +15,45 @@
|
|
| 14 |
margin: 0;
|
| 15 |
background-color: #f0f0f0;
|
| 16 |
}
|
| 17 |
-
.
|
| 18 |
background-color: white;
|
| 19 |
-
padding:
|
| 20 |
-
border-radius:
|
| 21 |
-
box-shadow: 0
|
| 22 |
-
width: 300px;
|
| 23 |
-
}
|
| 24 |
-
h1 {
|
| 25 |
-
text-align: center;
|
| 26 |
-
margin-bottom: 1.5rem;
|
| 27 |
}
|
| 28 |
-
input {
|
| 29 |
display: block;
|
| 30 |
width: 100%;
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
border: 1px solid #ccc;
|
| 34 |
-
border-radius: 4px;
|
| 35 |
}
|
| 36 |
button {
|
| 37 |
-
width: 100%;
|
| 38 |
-
padding: 0.5rem;
|
| 39 |
background-color: #007bff;
|
| 40 |
color: white;
|
| 41 |
border: none;
|
| 42 |
-
|
| 43 |
cursor: pointer;
|
| 44 |
-
margin-bottom: 0.5rem;
|
| 45 |
}
|
| 46 |
button:hover {
|
| 47 |
background-color: #0056b3;
|
| 48 |
}
|
| 49 |
-
#message {
|
| 50 |
-
margin-top: 1rem;
|
| 51 |
-
text-align: center;
|
| 52 |
-
color: #dc3545;
|
| 53 |
-
}
|
| 54 |
-
.toggle-form {
|
| 55 |
-
text-align: center;
|
| 56 |
-
margin-top: 1rem;
|
| 57 |
-
cursor: pointer;
|
| 58 |
-
color: #007bff;
|
| 59 |
-
}
|
| 60 |
-
.popup {
|
| 61 |
-
position: fixed;
|
| 62 |
-
top: 50%;
|
| 63 |
-
left: 50%;
|
| 64 |
-
transform: translate(-50%, -50%);
|
| 65 |
-
background-color: white;
|
| 66 |
-
padding: 2rem;
|
| 67 |
-
border-radius: 8px;
|
| 68 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 69 |
-
display: none;
|
| 70 |
-
text-align: center;
|
| 71 |
-
}
|
| 72 |
-
.popup button {
|
| 73 |
-
margin-top: 1rem;
|
| 74 |
-
width: auto;
|
| 75 |
-
padding: 0.5rem 1rem;
|
| 76 |
-
}
|
| 77 |
</style>
|
| 78 |
</head>
|
| 79 |
<body>
|
| 80 |
-
<div class="
|
| 81 |
-
<
|
| 82 |
-
<
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
<button type="submit" id="submit-btn">Log In</button>
|
| 86 |
-
</form>
|
| 87 |
-
<div id="message"></div>
|
| 88 |
-
<div class="toggle-form" id="toggle-form">Don't have an account? Sign Up</div>
|
| 89 |
-
</div>
|
| 90 |
|
| 91 |
-
|
| 92 |
-
<
|
| 93 |
-
<
|
| 94 |
-
<button
|
|
|
|
|
|
|
| 95 |
</div>
|
| 96 |
|
| 97 |
-
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
|
| 98 |
<script>
|
| 99 |
const client = new Appwrite.Client();
|
| 100 |
client
|
|
@@ -103,55 +62,35 @@
|
|
| 103 |
|
| 104 |
const account = new Appwrite.Account(client);
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
const toggleForm = document.getElementById('toggle-form');
|
| 110 |
-
const authForm = document.getElementById('auth-form');
|
| 111 |
-
const messageElement = document.getElementById('message');
|
| 112 |
-
const popup = document.getElementById('popup');
|
| 113 |
-
const popupMessage = document.getElementById('popup-message');
|
| 114 |
-
const closePopup = document.getElementById('close-popup');
|
| 115 |
-
|
| 116 |
-
toggleForm.addEventListener('click', () => {
|
| 117 |
-
isLoginForm = !isLoginForm;
|
| 118 |
-
formTitle.textContent = isLoginForm ? 'Login' : 'Sign Up';
|
| 119 |
-
submitBtn.textContent = isLoginForm ? 'Log In' : 'Sign Up';
|
| 120 |
-
toggleForm.textContent = isLoginForm ? "Don't have an account? Sign Up" : "Already have an account? Log In";
|
| 121 |
-
messageElement.textContent = '';
|
| 122 |
-
});
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
result = await account.createEmailSession(email, password);
|
| 133 |
-
showPopup('Login successful!');
|
| 134 |
-
} else {
|
| 135 |
-
result = await account.create(Appwrite.ID.unique(), email, password);
|
| 136 |
-
showPopup('Sign up successful! Please check your email for verification.');
|
| 137 |
-
}
|
| 138 |
-
console.log('Result:', result);
|
| 139 |
-
// Redirect or perform actions after successful login/signup
|
| 140 |
-
} catch (error) {
|
| 141 |
-
messageElement.textContent = `${isLoginForm ? 'Login' : 'Sign up'} failed. Please check your credentials.`;
|
| 142 |
-
messageElement.style.color = '#dc3545';
|
| 143 |
-
console.error('Error:', error);
|
| 144 |
-
}
|
| 145 |
-
});
|
| 146 |
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
}
|
| 151 |
-
|
| 152 |
-
closePopup.addEventListener('click', () => {
|
| 153 |
-
popup.style.display = 'none';
|
| 154 |
-
});
|
| 155 |
</script>
|
| 156 |
</body>
|
| 157 |
</html>
|
|
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Appwrite Auth</title>
|
| 7 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
|
| 8 |
<style>
|
| 9 |
body {
|
| 10 |
font-family: Arial, sans-serif;
|
|
|
|
| 15 |
margin: 0;
|
| 16 |
background-color: #f0f0f0;
|
| 17 |
}
|
| 18 |
+
.container {
|
| 19 |
background-color: white;
|
| 20 |
+
padding: 20px;
|
| 21 |
+
border-radius: 5px;
|
| 22 |
+
box-shadow: 0 0 10px rgba(0,0,0,0.1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
}
|
| 24 |
+
input, button {
|
| 25 |
display: block;
|
| 26 |
width: 100%;
|
| 27 |
+
margin-bottom: 10px;
|
| 28 |
+
padding: 5px;
|
|
|
|
|
|
|
| 29 |
}
|
| 30 |
button {
|
|
|
|
|
|
|
| 31 |
background-color: #007bff;
|
| 32 |
color: white;
|
| 33 |
border: none;
|
| 34 |
+
padding: 10px;
|
| 35 |
cursor: pointer;
|
|
|
|
| 36 |
}
|
| 37 |
button:hover {
|
| 38 |
background-color: #0056b3;
|
| 39 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
</style>
|
| 41 |
</head>
|
| 42 |
<body>
|
| 43 |
+
<div class="container">
|
| 44 |
+
<h2>Signup</h2>
|
| 45 |
+
<input type="email" id="signupEmail" placeholder="Email">
|
| 46 |
+
<input type="password" id="signupPassword" placeholder="Password">
|
| 47 |
+
<button onclick="signup()">Sign Up</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
<h2>Login</h2>
|
| 50 |
+
<input type="email" id="loginEmail" placeholder="Email">
|
| 51 |
+
<input type="password" id="loginPassword" placeholder="Password">
|
| 52 |
+
<button onclick="login()">Log In</button>
|
| 53 |
+
|
| 54 |
+
<div id="message"></div>
|
| 55 |
</div>
|
| 56 |
|
|
|
|
| 57 |
<script>
|
| 58 |
const client = new Appwrite.Client();
|
| 59 |
client
|
|
|
|
| 62 |
|
| 63 |
const account = new Appwrite.Account(client);
|
| 64 |
|
| 65 |
+
function signup() {
|
| 66 |
+
const email = document.getElementById('signupEmail').value;
|
| 67 |
+
const password = document.getElementById('signupPassword').value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
+
account.create(Appwrite.ID.unique(), email, password)
|
| 70 |
+
.then(response => {
|
| 71 |
+
document.getElementById('message').innerText = 'Signup successful!';
|
| 72 |
+
console.log(response);
|
| 73 |
+
})
|
| 74 |
+
.catch(error => {
|
| 75 |
+
document.getElementById('message').innerText = 'Signup failed: ' + error.message;
|
| 76 |
+
console.error(error);
|
| 77 |
+
});
|
| 78 |
+
}
|
| 79 |
|
| 80 |
+
function login() {
|
| 81 |
+
const email = document.getElementById('loginEmail').value;
|
| 82 |
+
const password = document.getElementById('loginPassword').value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
+
account.createEmailSession(email, password)
|
| 85 |
+
.then(response => {
|
| 86 |
+
document.getElementById('message').innerText = 'Login successful!';
|
| 87 |
+
console.log(response);
|
| 88 |
+
})
|
| 89 |
+
.catch(error => {
|
| 90 |
+
document.getElementById('message').innerText = 'Login failed: ' + error.message;
|
| 91 |
+
console.error(error);
|
| 92 |
+
});
|
| 93 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
</script>
|
| 95 |
</body>
|
| 96 |
</html>
|