Skip to content

Commit cd2ce1f

Browse files
created google login for the login page
1 parent 4ef3f46 commit cd2ce1f

4 files changed

+51
-0
lines changed
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google-site-verification: google585d479acf355cc6.html

google585d479acf355cc6 (1).html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google-site-verification: google585d479acf355cc6.html

google585d479acf355cc6.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google-site-verification: google585d479acf355cc6.html

login.html

+48
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
font-size: 0.9em;
4444
}
4545
</style>
46+
47+
<script src="https://apis.google.com/js/platform.js" async defer></script>
48+
4649
</head>
4750
<body>
4851
<header class="header-area">
@@ -112,6 +115,8 @@ <h3 class="join">Login to join us....</h3>
112115
</table>
113116
<div class="error" id="login-error"></div>
114117
<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+
115120
</form>
116121
<p class="text-center">Don't have an account? <a href="#" id="registerLink">Register</a></p>
117122
</div>
@@ -154,6 +159,7 @@ <h3 class="join">Register to join us....</h3>
154159
</table>
155160
<div class="error" id="register-error"></div>
156161
<button type="submit" class="main-btn mt-2 w-100 mb-3" style="padding: 0px;">Register</button>
162+
157163
</form>
158164
<p class="text-center">Already have an account? <a href="#" id="loginLink">Login</a></p>
159165
</div>
@@ -390,5 +396,47 @@ <h4 class="title custom-margin">Contact Us</h4>
390396
}
391397
});
392398
</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+
393441
</body>
394442
</html>

0 commit comments

Comments
 (0)