abdullahalioo commited on
Commit
75badac
·
verified ·
1 Parent(s): afc16ff

Update templates/register.html

Browse files
Files changed (1) hide show
  1. templates/register.html +29 -14
templates/register.html CHANGED
@@ -1,5 +1,6 @@
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, maximum-scale=1.0, user-scalable=no">
@@ -8,17 +9,19 @@
8
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
9
  <link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">
10
  </head>
 
11
  <body class="register-page">
12
  <div class="container-fluid h-100">
13
  <div class="row h-100 justify-content-center align-items-center">
14
  <div class="col-md-6 col-lg-4">
15
  <div class="register-card">
16
  <div class="text-center mb-4">
17
- <img src="{{ url_for('static', filename='images/logo.svg') }}" alt="WhatsApp Clone" class="logo-small">
 
18
  <h2 class="mt-3">Create Account</h2>
19
  <p class="text-muted">Join our messaging platform</p>
20
  </div>
21
-
22
  <form id="registerForm">
23
  <div class="mb-3">
24
  <label for="name" class="form-label">Full Name</label>
@@ -27,7 +30,7 @@
27
  <input type="text" class="form-control" id="name" name="name" required>
28
  </div>
29
  </div>
30
-
31
  <div class="mb-3">
32
  <label for="email" class="form-label">Email Address</label>
33
  <div class="input-group">
@@ -35,20 +38,20 @@
35
  <input type="email" class="form-control" id="email" name="email" required>
36
  </div>
37
  </div>
38
-
39
  <div class="d-grid mb-3">
40
  <button type="submit" class="btn btn-success btn-lg">
41
  <i class="fas fa-user-plus me-2"></i>Create Account
42
  </button>
43
  </div>
44
  </form>
45
-
46
  <div class="text-center">
47
  <a href="/" class="text-muted">
48
  <i class="fas fa-arrow-left me-1"></i>Back to Home
49
  </a>
50
  </div>
51
-
52
  <div id="alert-container"></div>
53
  </div>
54
  </div>
@@ -58,20 +61,28 @@
58
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
59
  <script src="{{ url_for('static', filename='js/main.js') }}"></script>
60
  <script>
 
 
 
 
 
 
 
 
61
  document.getElementById('registerForm').addEventListener('submit', async (e) => {
62
  e.preventDefault();
63
-
64
  const formData = new FormData(e.target);
65
  const data = {
66
  name: formData.get('name').trim(),
67
  email: formData.get('email').trim()
68
  };
69
-
70
  if (!data.name || !data.email) {
71
  showAlert('Please fill in all fields', 'danger');
72
  return;
73
  }
74
-
75
  try {
76
  const response = await fetch('/api/register', {
77
  method: 'POST',
@@ -80,10 +91,12 @@
80
  },
81
  body: JSON.stringify(data)
82
  });
83
-
84
  const result = await response.json();
85
-
86
  if (result.success) {
 
 
87
  showAlert('Account created successfully! Redirecting...', 'success');
88
  setTimeout(() => {
89
  window.location.href = '/chat';
@@ -96,7 +109,7 @@
96
  showAlert('Registration failed. Please try again.', 'danger');
97
  }
98
  });
99
-
100
  function showAlert(message, type) {
101
  const alertContainer = document.getElementById('alert-container');
102
  const alert = document.createElement('div');
@@ -104,7 +117,7 @@
104
  alert.textContent = message;
105
  alertContainer.innerHTML = '';
106
  alertContainer.appendChild(alert);
107
-
108
  if (type === 'success') {
109
  setTimeout(() => {
110
  alert.remove();
@@ -112,5 +125,7 @@
112
  }
113
  }
114
  </script>
 
115
  </body>
116
- </html>
 
 
1
  <!DOCTYPE html>
2
  <html lang="en">
3
+
4
  <head>
5
  <meta charset="UTF-8">
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
 
9
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
10
  <link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">
11
  </head>
12
+
13
  <body class="register-page">
14
  <div class="container-fluid h-100">
15
  <div class="row h-100 justify-content-center align-items-center">
16
  <div class="col-md-6 col-lg-4">
17
  <div class="register-card">
18
  <div class="text-center mb-4">
19
+ <img src="{{ url_for('static', filename='images/logo.svg') }}" alt="WhatsApp Clone"
20
+ class="logo-small">
21
  <h2 class="mt-3">Create Account</h2>
22
  <p class="text-muted">Join our messaging platform</p>
23
  </div>
24
+
25
  <form id="registerForm">
26
  <div class="mb-3">
27
  <label for="name" class="form-label">Full Name</label>
 
30
  <input type="text" class="form-control" id="name" name="name" required>
31
  </div>
32
  </div>
33
+
34
  <div class="mb-3">
35
  <label for="email" class="form-label">Email Address</label>
36
  <div class="input-group">
 
38
  <input type="email" class="form-control" id="email" name="email" required>
39
  </div>
40
  </div>
41
+
42
  <div class="d-grid mb-3">
43
  <button type="submit" class="btn btn-success btn-lg">
44
  <i class="fas fa-user-plus me-2"></i>Create Account
45
  </button>
46
  </div>
47
  </form>
48
+
49
  <div class="text-center">
50
  <a href="/" class="text-muted">
51
  <i class="fas fa-arrow-left me-1"></i>Back to Home
52
  </a>
53
  </div>
54
+
55
  <div id="alert-container"></div>
56
  </div>
57
  </div>
 
61
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
62
  <script src="{{ url_for('static', filename='js/main.js') }}"></script>
63
  <script>
64
+ // Check if user is already stored in localStorage
65
+ const existingUser = localStorage.getItem('chat_user');
66
+
67
+ if (existingUser) {
68
+ // Redirect to chat if already registered
69
+ window.location.href = '/chat';
70
+ }
71
+
72
  document.getElementById('registerForm').addEventListener('submit', async (e) => {
73
  e.preventDefault();
74
+
75
  const formData = new FormData(e.target);
76
  const data = {
77
  name: formData.get('name').trim(),
78
  email: formData.get('email').trim()
79
  };
80
+
81
  if (!data.name || !data.email) {
82
  showAlert('Please fill in all fields', 'danger');
83
  return;
84
  }
85
+
86
  try {
87
  const response = await fetch('/api/register', {
88
  method: 'POST',
 
91
  },
92
  body: JSON.stringify(data)
93
  });
94
+
95
  const result = await response.json();
96
+
97
  if (result.success) {
98
+ // Store user locally to prevent re-registration
99
+ localStorage.setItem('chat_user', JSON.stringify(data));
100
  showAlert('Account created successfully! Redirecting...', 'success');
101
  setTimeout(() => {
102
  window.location.href = '/chat';
 
109
  showAlert('Registration failed. Please try again.', 'danger');
110
  }
111
  });
112
+
113
  function showAlert(message, type) {
114
  const alertContainer = document.getElementById('alert-container');
115
  const alert = document.createElement('div');
 
117
  alert.textContent = message;
118
  alertContainer.innerHTML = '';
119
  alertContainer.appendChild(alert);
120
+
121
  if (type === 'success') {
122
  setTimeout(() => {
123
  alert.remove();
 
125
  }
126
  }
127
  </script>
128
+
129
  </body>
130
+
131
+ </html>