Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.79 KB | None | 0 0
  1. /**
  2. STRUCTURE DU POST:
  3.  
  4. 'Socyalize' => [
  5.     'Provider'  => [
  6.     'token'     => '',
  7.         'provider_name' => '',
  8.         'id'            => '',
  9.         'first_name'    => '',
  10.         'name'          => '',
  11.         'birthday'      => '',
  12.         'email'         => '',
  13.         'picture'       => '',
  14.         'profile_url'   => '',
  15.         'location'      => '',
  16.     'locale'    => '',
  17.     ],
  18.     'callback'  => '',
  19.     'email'     => '',
  20.     'birthday'  => ''
  21. ]
  22. */
  23.  
  24. if($this->request->is('post')):
  25.  
  26.             // L'utilisateur s'authentifie par le biais de l'authentification par réseau social
  27.             if(isset($this->request->data['Socyalize'])):
  28.  
  29.                 // Vérification de l'authencitité de l'information
  30.                 if(isset($this->request->data['Socyalize']['Provider']['token'])):
  31.  
  32.                     $validationIdentity = file_get_contents("https://www.socyalize.com/socializes/confirm/" . $this->request->data['Socyalize']['Provider']['provider_id'] . "/" . $this->request->data['Socyalize']['Provider']['token']);
  33.  
  34.                     if(stripos($validationIdentity, "Authorization") !== false):
  35.                         // Check if user is already registered
  36.                         $user = $this->Users->find()->where([
  37.                             'provider_name' => $this->request->data['Socyalize']['Provider']['provider_name'],
  38.                             'provider_id'   => $this->request->data['Socyalize']['Provider']['provider_id'],
  39.                         ])
  40.                         ->first();
  41.  
  42.                         if(!is_null($user)):
  43.                             $this->Auth->setUser($user->toArray());
  44.                         else:
  45.                             $user = $this->Users->newEntity([
  46.                                 'username'      => $this->request->data['Socyalize']['username'],
  47.                                 'code_bancaire'  => $this->request->data['Socyalize']['pincode'],
  48.                                 'provider_name' => $this->request->data['Socyalize']['Provider']['provider_name'],
  49.                                 'provider_id'   => $this->request->data['Socyalize']['Provider']['provider_id']
  50.                             ]);
  51.  
  52.                             $this->Users->save($user);
  53.                             debug($this->request->data['Socyalize']['callback']);
  54.                             $callback = file_get_contents("https://www.socyalize.com/socializes/callback/" . $this->request->data['Socyalize']['callback'] . "/" . $this->request->data['Socyalize']['Provider']['provider_id']);
  55.                             $this->Auth->setUser($user->toArray());
  56.                         endif;
  57.  
  58.                         return $this->redirect(['action' => 'me']);
  59.                     endif;
  60.  
  61.                 endif;
  62.             endif;
  63.         endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement