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


PHP waContact::save方法代码示例

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


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

示例1: execute

 public function execute()
 {
     $form = shopHelper::getCustomerForm();
     if ($form->post()) {
         $customer_validation_disabled = wa()->getSetting('disable_backend_customer_form_validation');
         if ($customer_validation_disabled || $form->isValid()) {
             $c = new waContact();
             if ($customer_validation_disabled) {
                 $errors = array();
                 $c->save($form->post());
             } else {
                 $errors = $c->save($form->post(), true);
             }
             if (!$errors) {
                 $scm = new shopCustomerModel();
                 $scm->createFromContact($c->getId());
                 echo '<script>$.customers.reloadSidebar(); window.location.hash = "#/id/' . $c->getId() . '"</script>';
                 exit;
             }
             // Show errors that waContact returned, e.g. email must be unique.
             foreach ($errors as $fld => $list) {
                 foreach ($list as $err) {
                     $form->errors($fld, $err);
                 }
             }
         }
     }
     $this->view->assign('form', $form);
     $this->view->assign('customer_validation_disabled', wa()->getSetting('disable_backend_customer_form_validation'));
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:30,代码来源:shopCustomersAdd.action.php

示例2: execute

 public function execute()
 {
     // Задаём лайаут для фронтенда
     $this->setLayout(new guestbook2FrontendLayout());
     // Получаем hash из GET параметров
     $hash = waRequest::get('hash');
     // Проверяем хэш
     if (!$hash || strlen($hash) < 33) {
         $this->redirect(wa()->getRouteUrl('/frontend'));
     }
     // Получаем contact_id из хэша
     $contact_id = substr($hash, 16, -16);
     $hash = substr($hash, 0, 16) . substr($hash, -16);
     $contact = new waContact($contact_id);
     // Проверяем валидность хэша
     if ($contact->getSettings($this->getAppId(), 'confirm_hash') === $hash) {
         // Удаляем хэш
         $contact->delSettings($this->getAppId(), 'confirm_hash');
         // Выставляем статус confirmed для email-адреса контакта
         $contact['email'] = array('value' => $contact->get('email', 'default'), 'status' => 'confirmed');
         // Сохраняем контакт
         $contact->save();
     } else {
         // Если хэш неправильный, то просто редирект на главную страницу
         $this->redirect(wa()->getRouteUrl('/frontend'));
     }
 }
开发者ID:nowaym,项目名称:webasyst-framework,代码行数:27,代码来源:guestbook2FrontendConfirm.action.php

示例3: getContactInfo

 /** Using $this->id get waContact and save it in $this->contact;
  * Load vars into $this->view specific to waContact. */
 protected function getContactInfo()
 {
     $system = wa();
     if ($this->id == $system->getUser()->getId()) {
         $this->contact = $system->getUser();
         $this->view->assign('own_profile', true);
     } else {
         $this->contact = new waContact($this->id);
         $this->view->assign('own_profile', false);
     }
     $exists = $this->contact->exists();
     if ($exists) {
         $this->view->assign('contact', $this->contact);
         // who created this contact and when
         $this->view->assign('contact_create_time', waDateTime::format('datetime', $this->contact['create_datetime'], $system->getUser()->getTimezone()));
         if ($this->contact['create_contact_id']) {
             try {
                 $author = new waContact($this->contact['create_contact_id']);
                 if ($author['name']) {
                     $this->view->assign('author', $author);
                 }
             } catch (Exception $e) {
                 // Contact not found. Ignore silently.
             }
         }
         $this->view->assign('top', $this->contact->getTopFields());
         // Main contact editor data
         $fieldValues = $this->contact->load('js', true);
         $m = new waContactModel();
         if (isset($fieldValues['company_contact_id'])) {
             if (!$m->getById($fieldValues['company_contact_id'])) {
                 $fieldValues['company_contact_id'] = 0;
                 $this->contact->save(array('company_contact_id' => 0));
             }
         }
         $contactFields = waContactFields::getInfo($this->contact['is_company'] ? 'company' : 'person', true);
         // Only show fields that are allowed in own profile
         if (!empty($this->params['limited_own_profile'])) {
             $allowed = array();
             foreach (waContactFields::getAll('person') as $f) {
                 if ($f->getParameter('allow_self_edit')) {
                     $allowed[$f->getId()] = true;
                 }
             }
             $fieldValues = array_intersect_key($fieldValues, $allowed);
             $contactFields = array_intersect_key($contactFields, $allowed);
         }
         contactsHelper::normalzieContactFieldValues($fieldValues, $contactFields);
         $this->view->assign('contactFields', $contactFields);
         $this->view->assign('contactFieldsOrder', array_keys($contactFields));
         $this->view->assign('fieldValues', $fieldValues);
         // Contact categories
         $cm = new waContactCategoriesModel();
         $this->view->assign('contact_categories', array_values($cm->getContactCategories($this->id)));
     } else {
         $this->view->assign('contact', array('id' => $this->id));
     }
     return $exists;
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:61,代码来源:contactsContactsInfo.action.php

示例4: 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

示例5: execute

 public function execute()
 {
     $this->contact = wa()->getUser();
     $data = json_decode(waRequest::post('data'), true);
     if (!$data || !is_array($data)) {
         $this->response = array('errors' => array(), 'data' => array());
         return;
     }
     // Make sure only allowed fields are saved
     $allowed = array();
     foreach (waContactFields::getAll('person') as $f) {
         if ($f->getParameter('allow_self_edit')) {
             $allowed[$f->getId()] = true;
         }
     }
     $data = array_intersect_key($data, $allowed);
     $oldLocale = $this->getUser()->getLocale();
     // Validate and save contact if no errors found
     $errors = $this->contact->save($data, true);
     if ($errors) {
         $response = array();
     } else {
         // New data formatted for JS
         $response['name'] = $this->contact->get('name', 'js');
         foreach ($data as $field_id => $field_value) {
             if (!isset($errors[$field_id])) {
                 $response[$field_id] = $this->contact->get($field_id, 'js');
             }
         }
         // Top fields
         $response['top'] = array();
         foreach (array('email', 'phone', 'im') as $f) {
             if ($v = $this->contact->get($f, 'top,html')) {
                 $response['top'][] = array('id' => $f, 'name' => waContactFields::get($f)->getName(), 'value' => is_array($v) ? implode(', ', $v) : $v);
             }
         }
     }
     // Reload page with new language if user just changed it in own profile
     if ($oldLocale != $this->contact->getLocale()) {
         $response['reload'] = TRUE;
     }
     $this->response = array('errors' => $errors, 'data' => $response);
 }
开发者ID:Favorskij,项目名称:webasyst-framework,代码行数:43,代码来源:webasystProfileSave.controller.php

示例6: execute

 public function execute()
 {
     $id = $this->getRequest()->request('id', null, waRequest::TYPE_INT);
     $sort = $this->getRequest()->request('sort', null, waRequest::TYPE_INT);
     if ($id && $sort !== null) {
         $lat = $this->getRequest()->request('lat', '', waRequest::TYPE_STRING);
         $lng = $this->getRequest()->request('lng', '', waRequest::TYPE_STRING);
         $contact = new waContact($id);
         $address = array();
         foreach ($contact->get('address') as $i => $addr) {
             $address[$i] = array('value' => $addr['data'], 'ext' => $addr['ext']);
         }
         $address[$sort]['value']['lat'] = $lat;
         $address[$sort]['value']['lng'] = $lng;
         $contact->save(array('address' => $address));
     }
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:17,代码来源:webasystProfileSaveGeocoords.controller.php

示例7: execute

 public function execute()
 {
     $id = $this->getId();
     // Delete the old photos if they exist
     $oldDir = wa()->getDataPath(waContact::getPhotoDir($id), TRUE);
     if (file_exists($oldDir)) {
         waFiles::delete($oldDir);
     }
     // Update record in DB for this user
     $contact = new waContact($id);
     $contact['photo'] = 0;
     $contact->save();
     // Update recent history to reload thumbnail correctly (if not called from personal account)
     if (wa()->getUser()->get('is_user')) {
         $history = new contactsHistoryModel();
         $history->save('/contact/' . $id, null, null, '--');
     }
     $this->response = array('done' => 1, 'url' => $contact->getPhoto());
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:19,代码来源:contactsPhotoDelete.controller.php

示例8: execute

 public function execute()
 {
     if (!$this->getRequest()->request('json', 0)) {
         $action = new contactsContactsInfoAction();
         echo $action->display();
         return;
     }
     $m = new waContactModel();
     $contact_id = $this->getRequest()->request('id', 0, 'int');
     $contact = new waContact($contact_id);
     $values = $contact->load('js', true);
     if (isset($values['company_contact_id'])) {
         if (!$m->getById($values['company_contact_id'])) {
             $values['company_contact_id'] = 0;
             $contact->save(array('company_contact_id' => 0));
         }
     }
     $values['photo_url_96'] = $contact->getPhoto(96);
     $values['photo_url_20'] = $contact->getPhoto(20);
     $fields = waContactFields::getInfo($contact['is_company'] ? 'company' : 'person', true);
     echo json_encode(array('fields' => $fields, 'values' => $values, 'top' => $contact->getTopFields()));
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:22,代码来源:contactsContactsInfo.controller.php

示例9: execute

 public function execute()
 {
     $this->id = (int) waRequest::post('id');
     // Check access
     if (!$this->id) {
         if (!$this->getRights('create')) {
             throw new waRightsException('Access denied.');
         }
     } else {
         $cr = new contactsRightsModel();
         if ($cr->getRight(null, $this->id) != 'write') {
             throw new waRightsException('Access denied.');
         }
     }
     $this->type = waRequest::post('type');
     $this->contact = new waContact($this->id);
     if ($this->type == 'company') {
         $this->contact['is_company'] = 1;
     }
     $data = json_decode(waRequest::post('data'), true);
     if (!$this->id && !isset($data['create_method'])) {
         $data['create_method'] = 'add';
     }
     $oldLocale = $this->getUser()->getLocale();
     // get old data for logging
     if ($this->id) {
         $old_data = array();
         foreach ($data as $field_id => $field_value) {
             $old_data[$field_id] = $this->contact->get($field_id);
         }
     }
     $response = array();
     if (!($errors = $this->contact->save($data, true))) {
         if ($this->id) {
             $new_data = array();
             foreach ($data as $field_id => $field_value) {
                 if (!isset($errors[$field_id])) {
                     $response[$field_id] = $this->contact->get($field_id, 'js');
                     $new_data[$field_id] = $this->contact->get($field_id);
                 }
             }
             if (empty($errors)) {
                 $this->logContactEdit($old_data, $new_data);
             }
             $response['name'] = $this->contact->get('name', 'js');
             $response['top'] = contactsHelper::getTop($this->contact);
             $response['id'] = $this->contact->getId();
         } else {
             $response = array('id' => $this->contact->getId());
             $response['address'] = $this->contact->get('address', 'js');
             $this->logAction('contact_add', null, $this->contact->getId());
         }
         // Update recently added menu item
         $name = waContactNameField::formatName($this->contact);
         if ($name || $name === '0') {
             $history = new contactsHistoryModel();
             $history->save('/contact/' . $this->contact->getId(), $name, $this->id ? null : 'add');
             $history = $history->get();
             // to update history in user's browser
         }
     }
     // Reload page with new language if user just changed it in own profile
     if ($this->contact->getId() == $this->getUser()->getId() && $oldLocale != $this->contact->getLocale()) {
         $response['reload'] = true;
     }
     $this->response = array('errors' => $errors, 'data' => $response);
     if (isset($history)) {
         $this->response['history'] = $history;
     }
 }
开发者ID:Favorskij,项目名称:webasyst-framework,代码行数:70,代码来源:contactsContactsSave.controller.php

示例10: merge


//.........这里部分代码省略.........
             foreach (array('birth_day', 'birth_month', 'birth_year') as $f) {
                 if (empty($master_data[$f]) && !empty($info[$f])) {
                     $master[$f] = $master_data[$f] = $info[$f];
                 }
             }
         }
     }
     // Remove duplicates
     foreach (array_keys($check_duplicates) as $f) {
         $values = $master[$f];
         if (!is_array($values) || count($values) <= 1) {
             continue;
         }
         $unique_values = array();
         // md5 => true
         foreach ($values as $k => $v) {
             if (is_array($v)) {
                 if (isset($v['value']) && is_string($v['value'])) {
                     $v = $v['value'];
                 } else {
                     unset($v['ext'], $v['status']);
                     ksort($v);
                     $v = serialize($v);
                 }
             }
             $hash = md5(mb_strtolower($v));
             if (!empty($unique_values[$hash])) {
                 unset($values[$k]);
                 continue;
             }
             $unique_values[$hash] = true;
         }
         $master[$f] = array_values($values);
     }
     // Save master contact
     $errors = $master->save(array(), 42);
     // 42 == do not validate anything at all
     if ($errors) {
         $errormsg = array();
         foreach ($errors as $field => $err) {
             if (!is_array($err)) {
                 $err = array($err);
             }
             foreach ($err as $str) {
                 $errormsg[] = $field . ': ' . $str;
             }
         }
         $result['error'] = implode("\n<br>", $errormsg);
         return $result;
     }
     // Merge categories
     $category_ids = array();
     $ccm = new waContactCategoriesModel();
     foreach ($ccm->getContactsCategories($merge_ids) as $cid => $cats) {
         $category_ids += array_flip($cats);
     }
     $category_ids = array_keys($category_ids);
     $ccm->add($master_id, $category_ids);
     // update photo
     if ($update_photo) {
         $rand = mt_rand();
         $path = wa()->getDataPath(waContact::getPhotoDir($master['id']), true, 'contacts', false);
         // delete old image
         if (file_exists($path)) {
             waFiles::delete($path);
         }
         waFiles::create($path);
         $filename = $path . "/" . $rand . ".original.jpg";
         waFiles::create($filename);
         waImage::factory($update_photo['original'])->save($filename, 90);
         if (!empty($update_photo['crop'])) {
             $filename = $path . "/" . $rand . ".jpg";
             waFiles::create($filename);
             waImage::factory($update_photo['crop'])->save($filename, 90);
         } else {
             waFiles::copy($filename, $path . "/" . $rand . ".jpg");
         }
         $master->save(array('photo' => $rand));
     }
     $result['total_merged'] = count($contacts_data) + 1;
     $contact_ids = array_keys($contacts_data);
     // wa_log
     $log_model = new waLogModel();
     $log_model->updateByField('contact_id', $contact_ids, array('contact_id' => $master_id));
     // wa_login_log
     $login_log_model = new waLoginLogModel();
     $login_log_model->updateByField('contact_id', $contact_ids, array('contact_id' => $master_id));
     // Merge event
     $params = array('contacts' => $contact_ids, 'id' => $master_data['id']);
     wa()->event(array('contacts', 'merge'), $params);
     // Delete all merged contacts
     $contact_model = new waContactModel();
     $contact_model->delete($contact_ids, false);
     // false == do not trigger event
     $history_model = new contactsHistoryModel();
     foreach ($contact_ids as $contact_id) {
         $history_model->deleteByField(array('type' => 'add', 'hash' => '/contact/' . $contact_id));
     }
     return $result;
 }
开发者ID:cjmaximal,项目名称:webasyst-framework,代码行数:101,代码来源:contactsContactsMerge.controller.php

示例11: 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

示例12: execute

 public function execute()
 {
     // only allowed to global admin
     if (!wa()->getUser()->getRights('webasyst', 'backend')) {
         throw new waRightsException('Access denied.');
     }
     $app_id = waRequest::post('app_id');
     $name = waRequest::post('name');
     $value = (int) waRequest::post('value');
     $contact_id = waRequest::get('id');
     $has_backend_access_old = $this->hasBackendAccess($contact_id);
     if (!$name && !$value) {
         $values = waRequest::post('app');
         if (!is_array($values)) {
             throw new waException('Bad values for access rights.');
         }
     } else {
         $values = array($name => $value);
     }
     $right_model = new waContactRightsModel();
     $is_admin = $right_model->get($contact_id, 'webasyst', 'backend', false);
     if ($is_admin && $app_id != 'webasyst') {
         throw new waException('Cannot change application rights for global admin.');
     }
     // If $contact_id used to have limited access and we're changing global admin privileges,
     // then need to notify all applications to remove their custom access records.
     if (!$is_admin && $app_id == 'webasyst' && $name == 'backend') {
         foreach (wa()->getApps() as $aid => $app) {
             try {
                 if (isset($app['rights']) && $app['rights']) {
                     $app_config = SystemConfig::getAppConfig($aid);
                     $class_name = $app_config->getPrefix() . "RightConfig";
                     $file_path = $app_config->getAppPath('lib/config/' . $class_name . ".class.php");
                     $right_config = null;
                     if (!file_exists($file_path)) {
                         continue;
                     }
                     waSystem::getInstance($aid, $app_config);
                     include_once $file_path;
                     /**
                      * @var waRightConfig
                      */
                     $right_config = new $class_name();
                     $right_config->clearRights($contact_id);
                 }
             } catch (Exception $e) {
                 // silently ignore other applications errors
             }
         }
     }
     // Update $app_id access records
     $app_config = SystemConfig::getAppConfig($app_id);
     $class_name = $app_config->getPrefix() . "RightConfig";
     $file_path = $app_config->getAppPath('lib/config/' . $class_name . ".class.php");
     $right_config = null;
     if (file_exists($file_path)) {
         // Init app
         waSystem::getInstance($app_id, $app_config);
         include_once $file_path;
         /**
          * @var waRightConfig
          */
         $right_config = new $class_name();
     }
     foreach ($values as $name => $value) {
         if ($right_config && $right_config->setRights($contact_id, $name, $value)) {
             // If we've got response from custom rights config, then no need to update main rights table
             continue;
         }
         // Set default limited rights
         if ($right_config && $name == 'backend' && $value == 1) {
             /**
              * @var $right_config waRightConfig
              */
             foreach ($right_config->setDefaultRights($contact_id) as $n => $v) {
                 $right_model->save($contact_id, $app_id, $n, $v);
             }
         }
         $right_model->save($contact_id, $app_id, $name, $value);
     }
     waSystem::setActive('contacts');
     if ($contact_id) {
         // TODO: use waContact method for disabling
         $is_user = waRequest::post('is_user', null, 'int');
         if ($is_user === -1 || $is_user === 0 || $is_user === 1) {
             $contact = new waContact($contact_id);
             $contact->save(array('is_user' => $is_user));
             $this->response['access_disable_msg'] = contactsHelper::getAccessDisableMsg($contact);
         }
     }
     $has_backend_access_new = $this->hasBackendAccess($contact_id);
     if ($has_backend_access_new !== $has_backend_access_old) {
         if ($has_backend_access_new) {
             $this->logAction("grant_backend_access", null, $contact_id);
         } else {
             $this->logAction("revoke_backend_access", null, $contact_id);
         }
     }
 }
开发者ID:Favorskij,项目名称:webasyst-framework,代码行数:99,代码来源:contactsRightsSave.controller.php

示例13: signup

 /**
  * @param array $data
  * @param array $errors
  * @return bool|waContact
  */
 public function signup($data, &$errors = array())
 {
     // check exists contacts
     $auth = wa()->getAuth();
     $field_id = $auth->getOption('login');
     if ($field_id == 'login') {
         $field_name = _ws('Login');
     } else {
         $field = waContactFields::get($field_id);
         if ($field) {
             $field_name = $field->getName();
         } else {
             $field_name = ucfirst($field_id);
         }
     }
     $is_error = false;
     // check passwords
     if ($data['password'] !== $data['password_confirm']) {
         $errors['password'] = array();
         $errors['password_confirm'] = array(_ws('Passwords do not match'));
         $is_error = true;
     } elseif (!$data['password']) {
         $errors['password'] = array();
         $errors['password_confirm'][] = _ws('Password can not be empty.');
         $is_error = true;
     }
     if (!$data[$field_id]) {
         $errors[$field_id] = array(sprintf(_ws("%s is required"), $field_name));
         $is_error = true;
     }
     $contact = $auth->getByLogin($data[$field_id]);
     if ($contact) {
         $errors[$field_id] = array(sprintf(_ws('User with the same %s is already registered'), $field_name));
         $is_error = true;
     }
     // set unconfirmed status for email
     if (isset($data['email']) && $data['email']) {
         $data['email'] = array('value' => $data['email'], 'status' => 'unconfirmed');
     }
     // check captcha
     $auth_config = wa()->getAuthConfig();
     if (isset($auth_config['signup_captcha']) && $auth_config['signup_captcha']) {
         if (!wa()->getCaptcha()->isValid()) {
             $errors['captcha'] = _ws('Invalid captcha');
             $is_error = true;
         }
     }
     if ($is_error) {
         return false;
     }
     // remove password_confirm field
     unset($data['password_confirm']);
     // set advansed data
     $data['create_method'] = 'signup';
     $data['create_ip'] = waRequest::getIp();
     $data['create_user_agent'] = waRequest::getUserAgent();
     // try save contact
     $contact = new waContact();
     if (!($errors = $contact->save($data, true))) {
         // after sign up callback
         $this->afterSignup($contact);
         // auth new contact
         wa()->getAuth()->auth($contact);
         return $contact;
     }
     if (isset($errors['name'])) {
         $errors['firstname'] = array();
         $errors['middlename'] = array();
         $errors['lastname'] = $errors['name'];
     }
     return false;
 }
开发者ID:nowaym,项目名称:webasyst-framework,代码行数:77,代码来源:waSignupAction.class.php

示例14: 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

示例15: execute

 public function execute()
 {
     $this->id = (int) waRequest::post('id');
     // Check access
     if (!$this->id) {
         if (!$this->getRights('create')) {
             throw new waRightsException('Access denied.');
         }
     } else {
         $cr = new contactsRightsModel();
         if ($cr->getRight(null, $this->id) != 'write') {
             throw new waRightsException('Access denied.');
         }
     }
     $this->type = waRequest::post('type');
     $this->contact = new waContact($this->id);
     if ($this->type == 'company') {
         $this->contact['is_company'] = 1;
     }
     $data = json_decode(waRequest::post('data'), true);
     if (!$this->id && !isset($data['create_method'])) {
         $data['create_method'] = 'add';
     }
     $oldLocale = $this->getUser()->getLocale();
     $response = array();
     if (!($errors = $this->contact->save($data, true))) {
         if ($this->id) {
             foreach ($data as $field_id => $field_value) {
                 if (!isset($errors[$field_id])) {
                     $response[$field_id] = $this->contact->get($field_id, 'js');
                 }
             }
             $response['name'] = $this->contact->get('name', 'js');
             $fields = array('email', 'phone', 'im');
             $top = array();
             foreach ($fields as $f) {
                 if ($v = $this->contact->get($f, 'top,html')) {
                     $top[] = array('id' => $f, 'name' => waContactFields::get($f)->getName(), 'value' => is_array($v) ? implode(', ', $v) : $v);
                 }
             }
             $response['top'] = $top;
         } else {
             $response = array('id' => $this->contact->getId());
             $this->log('contact_add', 1);
         }
         // Update recently added menu item
         if (($name = $this->contact->get('name')) || $name === '0') {
             $name = trim($this->contact->get('title') . ' ' . $name);
             $history = new contactsHistoryModel();
             $history->save('/contact/' . $this->contact->getId(), $name, $this->id ? null : 'add');
             $history = $history->get();
             // to update history in user's browser
         }
     }
     // Reload page with new language if user just changed it in own profile
     if ($this->contact->getId() == $this->getUser()->getId() && $oldLocale != $this->contact->getLocale()) {
         $response['reload'] = TRUE;
     }
     $this->response = array('errors' => $errors, 'data' => $response);
     if (isset($history)) {
         $this->response['history'] = $history;
     }
 }
开发者ID:navi8602,项目名称:wa-shop-ppg,代码行数:63,代码来源:contactsContactsSave.controller.php


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