|
43 | 43 | font-size: 0.9em;
|
44 | 44 | }
|
45 | 45 | </style>
|
| 46 | + |
| 47 | + <script src="https://apis.google.com/js/platform.js" async defer></script> |
| 48 | + |
46 | 49 | </head>
|
47 | 50 | <body>
|
48 | 51 | <header class="header-area">
|
@@ -112,6 +115,8 @@ <h3 class="join">Login to join us....</h3>
|
112 | 115 | </table>
|
113 | 116 | <div class="error" id="login-error"></div>
|
114 | 117 | <button type="submit" class="main-btn mt-2 w-100 mb-2" style="padding: 0px;">Sign in</button>
|
| 118 | + <button class="main-btn" id="googleSignInBtn" style="padding: 0px;">Sign in with Google</button> |
| 119 | + |
115 | 120 | </form>
|
116 | 121 | <p class="text-center">Don't have an account? <a href="#" id="registerLink">Register</a></p>
|
117 | 122 | </div>
|
@@ -154,6 +159,7 @@ <h3 class="join">Register to join us....</h3>
|
154 | 159 | </table>
|
155 | 160 | <div class="error" id="register-error"></div>
|
156 | 161 | <button type="submit" class="main-btn mt-2 w-100 mb-3" style="padding: 0px;">Register</button>
|
| 162 | + |
157 | 163 | </form>
|
158 | 164 | <p class="text-center">Already have an account? <a href="#" id="loginLink">Login</a></p>
|
159 | 165 | </div>
|
@@ -390,5 +396,47 @@ <h4 class="title custom-margin">Contact Us</h4>
|
390 | 396 | }
|
391 | 397 | });
|
392 | 398 | </script>
|
| 399 | + <script>// Load the Google API client library |
| 400 | + function onLoad() { |
| 401 | + gapi.load('auth2', function() { |
| 402 | + gapi.auth2.init({ |
| 403 | + client_id: '226572113891-uj0fmt3qe68159fn43p013orr6la5s2u.apps.googleusercontent.com', // Replace with your client ID |
| 404 | + }); |
| 405 | + }); |
| 406 | + } |
| 407 | + |
| 408 | + // Function to handle sign-in |
| 409 | + function signIn() { |
| 410 | + const auth2 = gapi.auth2.getAuthInstance(); |
| 411 | + auth2.signIn().then(function (user) { |
| 412 | + const profile = user.getBasicProfile(); |
| 413 | + console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead. |
| 414 | + console.log('Name: ' + profile.getName()); |
| 415 | + console.log('Image URL: ' + profile.getImageUrl()); |
| 416 | + console.log('Email: ' + profile.getEmail()); |
| 417 | + |
| 418 | + // Send ID token to your backend server for validation |
| 419 | + const id_token = user.getAuthResponse().id_token; |
| 420 | + // Example: send id_token to your server for further processing |
| 421 | + // fetch('/your-backend-endpoint', { |
| 422 | + // method: 'POST', |
| 423 | + // headers: { |
| 424 | + // 'Content-Type': 'application/json' |
| 425 | + // }, |
| 426 | + // body: JSON.stringify({ id_token }) |
| 427 | + // }); |
| 428 | + }).catch(function (error) { |
| 429 | + console.error('Error signing in: ', error); |
| 430 | + }); |
| 431 | + } |
| 432 | + |
| 433 | + // Bind the signIn function to the button click |
| 434 | + document.getElementById('googleSignInBtn').addEventListener('click', signIn); |
| 435 | + |
| 436 | + // Load the API when the window loads |
| 437 | + window.onload = onLoad; |
| 438 | + </script> |
| 439 | + <script src="path/to/google-login.js"></script> |
| 440 | + |
393 | 441 | </body>
|
394 | 442 | </html>
|
0 commit comments