pvanand commited on
Commit
6acd93d
·
verified ·
1 Parent(s): 0fe476a

Create auth.html

Browse files
Files changed (1) hide show
  1. static/auth.html +157 -0
static/auth.html ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
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;
10
+ display: flex;
11
+ justify-content: center;
12
+ align-items: center;
13
+ height: 100vh;
14
+ margin: 0;
15
+ background-color: #f0f0f0;
16
+ }
17
+ .auth-container {
18
+ background-color: white;
19
+ padding: 2rem;
20
+ border-radius: 8px;
21
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
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
+ padding: 0.5rem;
32
+ margin-bottom: 1rem;
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
+ border-radius: 4px;
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="auth-container">
81
+ <h1 id="form-title">Login</h1>
82
+ <form id="auth-form">
83
+ <input type="email" id="email" placeholder="Email" required>
84
+ <input type="password" id="password" placeholder="Password" required>
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
+ <div class="popup" id="popup">
92
+ <h2>Success!</h2>
93
+ <p id="popup-message"></p>
94
+ <button id="close-popup">Close</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
101
+ .setEndpoint('https://cloud.appwrite.io/v1')
102
+ .setProject('66c2f6c7000abed7f1f9');
103
+
104
+ const account = new Appwrite.Account(client);
105
+
106
+ let isLoginForm = true;
107
+ const formTitle = document.getElementById('form-title');
108
+ const submitBtn = document.getElementById('submit-btn');
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
+ authForm.addEventListener('submit', async (e) => {
125
+ e.preventDefault();
126
+ const email = document.getElementById('email').value;
127
+ const password = document.getElementById('password').value;
128
+
129
+ try {
130
+ let result;
131
+ if (isLoginForm) {
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
+ function showPopup(message) {
148
+ popupMessage.textContent = message;
149
+ popup.style.display = 'block';
150
+ }
151
+
152
+ closePopup.addEventListener('click', () => {
153
+ popup.style.display = 'none';
154
+ });
155
+ </script>
156
+ </body>
157
+ </html>