I just want to ask, why when i clicked the login with google button, it is not working and not shown anything at all?
Below is my code:
index.php file:
<?php require "../../Controller/SigninController.php"; use AmppAuth; use AmppValidate; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign In</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap" rel="stylesheet">
<link rel="stylesheet" href="../../assets/css/main.css">
</head>
<body>
<div class="wrapper">
<div class="container">
<form action="" method="post" class="frm">
<h2>Sign In</h2>
<div class="form-group">
<?php if (!empty(Auth::$error[2])) echo "<span class='err'>" . Auth::$error[2] . "</span>"; ?>
</div>
<div class="form-group">
<label for="uname">Username</label>
<input type="text" name="uname" value="<?php if(!empty($_POST["uname"])) echo trim($_POST["uname"]); else { if(isset($_COOKIE["memberid"])) echo $_COOKIE["memberid"]; } ?>" id="uname" class="form-control">
<?php if (!empty(Auth::$error[0])) echo "<span class='err'>" . Auth::$error[0] . "</span>"; ?>
</div>
<div class="form-group">
<label for="upass">Password</label>
<input type="password" name="upass" value="<?php if(isset($_COOKIE["memberpassword"])) echo $_COOKIE["memberpassword"]; ?>" id="upass" class="form-control">
<?php if (!empty(Auth::$error[1])) echo "<span class='err'>" . Auth::$error[1] . "</span>"; ?>
</div>
<div class="form-group">
<input type="submit" value="signin" name="signin" class="btn">
</div>
<div class="form-group">
<div class="chkinbox flt-left">
<input type="checkbox" name="remember" class="chkbox" <?php if(isset($_COOKIE["memberid"])) echo "checked"; ?>>
<span class="checkmark"></span>
</div>
<div class="chklblbox flt-left">Remember me</div>
<a href="../signup" class="goto flt-right">New user?</a>
</div>
<div class="clear"></div>
<div class="form-group">
<input type="submit" value="Google" name="btngoogle">
</div>
</form>
</div>
</div>
</body>
</html>
startup.php file:
session_start();
require_once "vendor/autoload.php";
SigninController.php file:
if (isset($_POST["btngoogle"]))
{
$client = new GoogleClient();
$client->setClientId("my_client_id.apps.googleusercontent.com");
$client->setClientSecret("my_client_secret");
$client->setRedirectUri("../../signin");
$client->addScope("email");
$client->addScope("profile");
}
if (isset($_GET["code"]))
{
$client = new GoogleClient();
$token = $client->fetchAccessTokenWithAuthCode($_GET["code"]);
if (isset($token["error"]))
{
$client->setAccessToken($token["access_token"]);
$_SESSION["access_token"] = $token["access_token"];
$google_service = new Google_Service_Oauth2($client);
$data = $google_service->userinfo->get();
if (!empty($data["given_name"]) || !empty($data["family_name"]) || !empty($data["email"]) || !empty($data["gender"]) || !empty($data["picture"]))
{
if (Auth::RegisterProfile($data["given_name"], $data["family_name"], $data["email"], $data["gender"], $data["picture"]) &&
Auth::RegisterSessions($data["email"], "google"))
{
Redirect::TO("../home");
}
}
}
}
When run all above code, the browser just loading a little only and nothing more.
Your suggestion and advice really am appreciated.