Vote count:
0
I'm having a really hard time implementing G+ and Facebook login into my existing PHP logic with angularJS. The API function in PHP goes as follows:
public function fbAuth($name, $email, $ext_id, $gender, $age){
$response = array();
if(!$this->userExists($ext_id)){
$api_key = $this->generateApiKey();
$stmt = $this->conn->prepare("INSERT INTO users (name, age, email, gender, ext_id, api_key) VALUES (:name, :age, :email, :gender, :ext_id, :api_key)");
$result = $stmt->execute(array(':name'=>$name, ':age'=>$age, ':email'=>$email, ':gender'=>$gender, ':ext_id'=>$ext_id, ':api_key'=>$api_key));
if($result){
$id = $this->conn->lastInsertId();
$stmt = $this->conn->prepare("SELECT id, api_key FROM users WHERE id = :id");
$stmt->execute(array(':id' => $id));
$user = $stmt->fetchObject();
$response['success'] = 1;
$response['key'] = $user->api_key;
$response['id'] = $user->id;
} else {
$response['success'] = 0;
}
} else {
$stmt = $this->conn->prepare("SELECT id, api_key FROM users WHERE ext_id = :ext_id AND email = :email");
$stmt->execute(array(':ext_id'=>$ext_id, ':email'=>$email));
$user = $stmt->fetchObject();
if($user != null){
$response['success'] = 2;
$response['key'] = $user->api_key;
$response['id'] = $user->id;
} else {
$response['success'] = 0;
}
}
return $response;
}
Basically what I need from the AngularJS side is a directive which renders the login buttons, handles the facebook and g+ authentication and returns in the callback the required info (name, email, user_id, gender, age) which I can then use to make an API call via Restangular and log the user in. I have a system to log the person in when entering username/password but I have no idea how to get the user info in a callback from the social media logins. Any help would be most appreciated.
asked 24 secs ago
G+ and Facebook login with AngularJS and PHP
Aucun commentaire:
Enregistrer un commentaire