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