Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- STRUCTURE DU POST:
- 'Socyalize' => [
- 'Provider' => [
- 'token' => '',
- 'provider_name' => '',
- 'id' => '',
- 'first_name' => '',
- 'name' => '',
- 'birthday' => '',
- 'email' => '',
- 'picture' => '',
- 'profile_url' => '',
- 'location' => '',
- 'locale' => '',
- ],
- 'callback' => '',
- 'email' => '',
- 'birthday' => ''
- ]
- */
- if($this->request->is('post')):
- // L'utilisateur s'authentifie par le biais de l'authentification par réseau social
- if(isset($this->request->data['Socyalize'])):
- // Vérification de l'authencitité de l'information
- if(isset($this->request->data['Socyalize']['Provider']['token'])):
- $validationIdentity = file_get_contents("https://www.socyalize.com/socializes/confirm/" . $this->request->data['Socyalize']['Provider']['provider_id'] . "/" . $this->request->data['Socyalize']['Provider']['token']);
- if(stripos($validationIdentity, "Authorization") !== false):
- // Check if user is already registered
- $user = $this->Users->find()->where([
- 'provider_name' => $this->request->data['Socyalize']['Provider']['provider_name'],
- 'provider_id' => $this->request->data['Socyalize']['Provider']['provider_id'],
- ])
- ->first();
- if(!is_null($user)):
- $this->Auth->setUser($user->toArray());
- else:
- $user = $this->Users->newEntity([
- 'username' => $this->request->data['Socyalize']['username'],
- 'code_bancaire' => $this->request->data['Socyalize']['pincode'],
- 'provider_name' => $this->request->data['Socyalize']['Provider']['provider_name'],
- 'provider_id' => $this->request->data['Socyalize']['Provider']['provider_id']
- ]);
- $this->Users->save($user);
- debug($this->request->data['Socyalize']['callback']);
- $callback = file_get_contents("https://www.socyalize.com/socializes/callback/" . $this->request->data['Socyalize']['callback'] . "/" . $this->request->data['Socyalize']['Provider']['provider_id']);
- $this->Auth->setUser($user->toArray());
- endif;
- return $this->redirect(['action' => 'me']);
- endif;
- endif;
- endif;
- endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement