当前位置: 首页>>代码示例>>PHP>>正文


PHP waContact::setPhoto方法代码示例

本文整理汇总了PHP中waContact::setPhoto方法的典型用法代码示例。如果您正苦于以下问题:PHP waContact::setPhoto方法的具体用法?PHP waContact::setPhoto怎么用?PHP waContact::setPhoto使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在waContact的用法示例。


在下文中一共展示了waContact::setPhoto方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: afterAuth

 /**
  * @param array $data
  * @return waContact
  */
 protected function afterAuth($data)
 {
     $app_id = $this->getStorage()->get('auth_app');
     $contact_id = 0;
     // find contact by auth adapter id, i.e. facebook_id
     $contact_data_model = new waContactDataModel();
     $row = $contact_data_model->getByField(array('field' => $data['source'] . '_id', 'value' => $data['source_id'], 'sort' => 0));
     if ($row) {
         $contact_id = $row['contact_id'];
     }
     // try find user by email
     if (!$contact_id && isset($data['email'])) {
         $sql = "SELECT c.id FROM wa_contact_emails e\n            JOIN wa_contact c ON e.contact_id = c.id\n            WHERE e.email = s:email AND e.sort = 0 AND c.password != ''";
         $contact_model = new waContactModel();
         $contact_id = $contact_model->query($sql, array('email' => $data['email']))->fetchField('id');
         // save source_id
         if ($contact_id) {
             $contact_data_model->insert(array('contact_id' => $contact_id, 'field' => $data['source'] . '_id', 'value' => $data['source_id'], 'sort' => 0));
         }
     }
     // create new contact
     if (!$contact_id) {
         $contact = new waContact();
         $data[$data['source'] . '_id'] = $data['source_id'];
         $data['create_method'] = $data['source'];
         $data['create_app_id'] = $app_id;
         // set random password (length = default hash length - 1, to disable ability auth using login and password)
         $contact->setPassword(substr(waContact::getPasswordHash(uniqid(time(), true)), 0, -1), true);
         unset($data['source']);
         unset($data['source_id']);
         if (isset($data['photo_url'])) {
             $photo_url = $data['photo_url'];
             unset($data['photo_url']);
         } else {
             $photo_url = false;
         }
         $contact->save($data);
         $contact_id = $contact->getId();
         if ($contact_id && $photo_url) {
             $photo_url_parts = explode('/', $photo_url);
             // copy photo to tmp dir
             $path = wa()->getTempPath('auth_photo/' . $contact_id . '.' . end($photo_url_parts), $app_id);
             $photo = file_get_contents($photo_url);
             file_put_contents($path, $photo);
             $contact->setPhoto($path);
         }
     } else {
         $contact = new waContact($contact_id);
     }
     // auth user
     if ($contact_id) {
         wa()->getAuth()->auth(array('id' => $contact_id));
         return $contact;
     }
     return false;
 }
开发者ID:nowaym,项目名称:webasyst-framework,代码行数:60,代码来源:waOAuthController.class.php

示例2: oauth

 public function oauth($provider, $config, $token, $code = null)
 {
     /**
      * @var waOAuth2Adapter $auth
      */
     $auth = wa()->getAuth($provider, $config);
     if (!$token && $code) {
         $token = $auth->getAccessToken($code);
     }
     $data = $auth->getUserData($token);
     if (wa()->getUser()->getId()) {
         wa()->getUser()->save(array($data['source'] . '_id' => $data['source_id']));
         return wa()->getUser();
     }
     $app_id = wa()->getApp();
     $contact_id = 0;
     // find contact by auth adapter id, i.e. facebook_id
     $contact_data_model = new waContactDataModel();
     $row = $contact_data_model->getByField(array('field' => $data['source'] . '_id', 'value' => $data['source_id'], 'sort' => 0));
     if ($row) {
         $contact_id = $row['contact_id'];
     }
     // try find user by email
     if (!$contact_id && isset($data['email'])) {
         $sql = "SELECT c.id FROM wa_contact_emails e\n            JOIN wa_contact c ON e.contact_id = c.id\n            WHERE e.email = s:email AND e.sort = 0 AND c.password != ''";
         $contact_model = new waContactModel();
         $contact_id = $contact_model->query($sql, array('email' => $data['email']))->fetchField('id');
         // save source_id
         if ($contact_id) {
             $contact_data_model->insert(array('contact_id' => $contact_id, 'field' => $data['source'] . '_id', 'value' => $data['source_id'], 'sort' => 0));
         }
     }
     // create new contact
     if (!$contact_id) {
         $contact = new waContact();
         $data[$data['source'] . '_id'] = $data['source_id'];
         $data['create_method'] = $data['source'];
         $data['create_app_id'] = $app_id;
         // set random password (length = default hash length - 1, to disable ability auth using login and password)
         $contact->setPassword(substr(waContact::getPasswordHash(uniqid(time(), true)), 0, -1), true);
         unset($data['source']);
         unset($data['source_id']);
         if (isset($data['photo_url'])) {
             $photo_url = $data['photo_url'];
             unset($data['photo_url']);
         } else {
             $photo_url = false;
         }
         $contact->save($data);
         $contact_id = $contact->getId();
         if ($contact_id && $photo_url) {
             $photo_url_parts = explode('/', $photo_url);
             // copy photo to tmp dir
             $path = wa()->getTempPath('auth_photo/' . $contact_id . '.' . md5(end($photo_url_parts)), $app_id);
             if (function_exists('curl_init')) {
                 $ch = curl_init($photo_url);
                 curl_setopt($ch, CURLOPT_HEADER, 0);
                 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 25);
                 $photo = curl_exec($ch);
                 curl_close($ch);
             } else {
                 $photo = file_get_contents($photo_url);
             }
             if ($photo) {
                 file_put_contents($path, $photo);
                 $contact->setPhoto($path);
             }
         }
     } else {
         $contact = new waContact($contact_id);
     }
     // auth user
     if ($contact_id) {
         wa()->getAuth()->auth(array('id' => $contact_id));
         return $contact;
     }
     return false;
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:80,代码来源:waViewHelper.class.php

示例3: afterAuth

 /**
  * @param array $data
  * @return waContact
  */
 protected function afterAuth($data)
 {
     $app_id = $this->getStorage()->get('auth_app');
     $contact_id = 0;
     // find contact by auth adapter id, i.e. facebook_id
     $contact_data_model = new waContactDataModel();
     $row = $contact_data_model->getByField(array('field' => $data['source'] . '_id', 'value' => $data['source_id'], 'sort' => 0));
     if ($row) {
         $contact_id = $row['contact_id'];
     }
     // try find user by email
     if (!$contact_id && isset($data['email'])) {
         $contact_model = new waContactModel();
         $sql = "SELECT c.id FROM wa_contact_emails e\n            JOIN wa_contact c ON e.contact_id = c.id\n            WHERE e.email LIKE '" . $contact_model->escape($data['email'], 'like') . "' AND e.sort = 0 AND c.password != ''";
         $contact_id = $contact_model->query($sql)->fetchField('id');
         // save source_id
         if ($contact_id) {
             $contact_data_model->insert(array('contact_id' => $contact_id, 'field' => $data['source'] . '_id', 'value' => $data['source_id'], 'sort' => 0));
         }
     }
     // create new contact
     if (!$contact_id) {
         $contact = new waContact();
         $data[$data['source'] . '_id'] = $data['source_id'];
         $data['create_method'] = $data['source'];
         $data['create_app_id'] = $app_id;
         // set random password (length = default hash length - 1, to disable ability auth using login and password)
         $contact->setPassword(substr(waContact::getPasswordHash(uniqid(time(), true)), 0, -1), true);
         unset($data['source']);
         unset($data['source_id']);
         if (isset($data['photo_url'])) {
             $photo_url = $data['photo_url'];
             unset($data['photo_url']);
         } else {
             $photo_url = false;
         }
         $contact->save($data);
         $contact_id = $contact->getId();
         if ($contact_id && $photo_url) {
             $photo_url_parts = explode('/', $photo_url);
             // copy photo to tmp dir
             $path = wa()->getTempPath('auth_photo/' . $contact_id . '.' . md5(end($photo_url_parts)), $app_id);
             $s = parse_url($photo_url, PHP_URL_SCHEME);
             $w = stream_get_wrappers();
             if (in_array($s, $w) && ini_get('allow_url_fopen')) {
                 $photo = file_get_contents($photo_url);
             } elseif (function_exists('curl_init')) {
                 $ch = curl_init($photo_url);
                 curl_setopt($ch, CURLOPT_HEADER, 0);
                 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
                 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 25);
                 $photo = curl_exec($ch);
                 curl_close($ch);
             } else {
                 $photo = null;
             }
             if ($photo) {
                 file_put_contents($path, $photo);
                 $contact->setPhoto($path);
             }
         }
     } else {
         $contact = new waContact($contact_id);
     }
     // auth user
     if ($contact_id) {
         wa()->getAuth()->auth(array('id' => $contact_id));
         return $contact;
     }
     return false;
 }
开发者ID:Favorskij,项目名称:webasyst-framework,代码行数:78,代码来源:waOAuthController.class.php

示例4: createContact

 /**
  * @param array $data
  * @return waContact
  * @throws waException
  */
 protected function createContact($data)
 {
     $app_id = $this->getStorage()->get('auth_app');
     $contact = new waContact();
     $data[$data['source'] . '_id'] = $data['source_id'];
     $data['create_method'] = $data['source'];
     $data['create_app_id'] = $app_id;
     // set random password (length = default hash length - 1, to disable ability auth using login and password)
     $contact->setPassword(substr(waContact::getPasswordHash(uniqid(time(), true)), 0, -1), true);
     unset($data['source']);
     unset($data['source_id']);
     if (isset($data['photo_url'])) {
         $photo_url = $data['photo_url'];
         unset($data['photo_url']);
     } else {
         $photo_url = false;
     }
     $contact->save($data);
     $contact_id = $contact->getId();
     if ($contact_id && $photo_url) {
         $photo_url_parts = explode('/', $photo_url);
         // copy photo to tmp dir
         $path = wa()->getTempPath('auth_photo/' . $contact_id . '.' . md5(end($photo_url_parts)), $app_id);
         $s = parse_url($photo_url, PHP_URL_SCHEME);
         $w = stream_get_wrappers();
         if (in_array($s, $w) && ini_get('allow_url_fopen')) {
             $photo = file_get_contents($photo_url);
         } elseif (function_exists('curl_init')) {
             $ch = curl_init($photo_url);
             curl_setopt($ch, CURLOPT_HEADER, 0);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 25);
             $photo = curl_exec($ch);
             curl_close($ch);
         } else {
             $photo = null;
         }
         if ($photo) {
             file_put_contents($path, $photo);
             $contact->setPhoto($path);
         }
     }
     /**
      * @event signup
      * @param waContact $contact
      */
     wa()->event('signup', $contact);
     return $contact;
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:57,代码来源:waOAuthController.class.php


注:本文中的waContact::setPhoto方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。