microsoftRegisterDevice() public method

Register a new/old Microsoft device within the Fork API
Deprecation: : no more support for the Microsoft-app.
public microsoftRegisterDevice ( string $channelUri ) : boolean
$channelUri string The channel uri to register.
return boolean
Beispiel #1
0
 /**
  * Add a Microsoft device to a user.
  *
  * @param string $uri   The uri of the channel opened for the device.
  * @param string $email The emailaddress for the user to link the device to.
  */
 public static function microsoftAddDevice($uri, $email)
 {
     if (BaseAPI::isAuthorized()) {
         // redefine
         $uri = (string) $uri;
         // validate
         if ($uri == '') {
             BaseAPI::output(BaseAPI::BAD_REQUEST, array('message' => 'No uri-parameter provided.'));
         }
         if ($email == '') {
             BaseAPI::output(BaseAPI::BAD_REQUEST, array('message' => 'No email-parameter provided.'));
         }
         // we should tell the ForkAPI that we registered a device
         $publicKey = Model::get('fork.settings')->get('Core', 'fork_api_public_key', '');
         $privateKey = Model::get('fork.settings')->get('Core', 'fork_api_private_key', '');
         // validate keys
         if ($publicKey == '' || $privateKey == '') {
             BaseAPI::output(BaseAPI::BAD_REQUEST, array('message' => 'Invalid key for the Fork API, configure them in the backend.'));
         }
         try {
             // load user
             $user = new User(null, $email);
             // get current uris
             $uris = (array) $user->getSetting('microsoft_channel_uri');
             // not already in array?
             if (!in_array($uri, $uris)) {
                 $uris[] = $uri;
             }
             // require the class
             require_once PATH_LIBRARY . '/external/fork_api.php';
             // create instance
             $forkAPI = new \ForkAPI($publicKey, $privateKey);
             // make the call
             $forkAPI->microsoftRegisterDevice($uris);
             // store
             if (!empty($uris)) {
                 $user->setSetting('microsoft_channel_uri', $uris);
             }
         } catch (Exception $e) {
             BaseAPI::output(BaseAPI::FORBIDDEN, array('message' => 'Can\'t authenticate you.'));
         }
     }
 }