Hello! I`m trying to make google authentication. In add.php(templates file) I wrote this javascript code .
function singIn() {//<------this is called when button is pressed
…
var userInfo = JSON.stringify(user);
$.ajax({
method: “POST”,
url: “<?= Router::url(array('controller' => 'Users', 'action' => 'googlesignin')); ?>”,
data: {
userInfo
},
success: function(data) {
console.log(“Signed in google!”);
},
error: function(param) {
console.log("Something went wrong" + param.responseText.message);
console.log("-----------------------");
console.log(param);
}
});
I am getting google pop and everything is working with out any errors but data is not getting passed to controller. My controller
public function googlesignin(){
$user = $this->Users->newEntity();
$user->email = $_POST['data']['email'];
$user->name = $_POST['data']['displayName'];
$this->Users->save($user);
}
I also added this
$builder->connect(’/’, array(‘controller’ => ‘Users’, ‘action’ => ‘googlesignin’));
in routes.php.
Can anyone please help me?