Beispiel #1
0
 /**
  * (non-PHPdoc)
  * @see \libsrv\FormProcessor::_cleanPreProcess()
  */
 protected function _cleanPreProcess(array $params)
 {
     if ($this->isInsert()) {
         if (!isset($params['m_rank_ids'])) {
             $params['m_rank_ids'] = array();
         }
         if (!is_array($params['m_rank_ids'])) {
             $params['m_rank_ids'] = (array) $params['m_rank_ids'];
         }
     } else {
         if (isset($params['m_rank_ids']) && !is_array($params['m_rank_ids'])) {
             $params['m_rank_ids'] = (array) $params['m_rank_ids'];
         }
         if (isset($params['poll_key'])) {
             $row = $this->_object->findByPk($this->id);
             if (!$row || !is_array($row) || !isset($row['poll_key'])) {
                 Log::warning(sprintf('FpPolls is unable to find the result by id "%d"', $this->id), ErrorNo::ERROR_DB_SELECT, __METHOD__);
                 return false;
             }
             $pollKey = trim($params['poll_key']);
             if ($pollKey === $row['poll_key']) {
                 unset($params['poll_key']);
             }
         }
     }
     $rules = array('poll_name' => 'trim', 'poll_key' => 'trim', 'allow_unregistered' => 'trim', 'join_type' => 'trim', 'interval' => 'intval', 'is_published' => 'trim', 'dt_publish_up' => 'trim', 'dt_publish_down' => 'trim', 'is_visible' => 'trim', 'is_multiple' => 'trim', 'max_choices' => 'intval', 'description' => 'trim', 'ext_info' => 'trim', 'dt_created' => 'trim');
     $ret = $this->clean($rules, $params);
     return $ret;
 }
Beispiel #2
0
 /**
  * (non-PHPdoc)
  * @see \libsrv\FormProcessor::_cleanPreProcess()
  */
 protected function _cleanPreProcess(array $params)
 {
     if ($this->isUpdate()) {
         $row = $this->_object->findByPk($this->id);
         if (!$row || !is_array($row) || !isset($row['category_id']) || !isset($row['category_pid']) || !isset($row['category_name'])) {
             Log::warning(sprintf('FpCategories is unable to find the result by id "%d"', $this->id), ErrorNo::ERROR_DB_SELECT, __METHOD__);
             return false;
         }
         if (isset($params['category_name'])) {
             $newCategoryName = trim($params['category_name']);
             $oldCategoryName = $row['category_name'];
             if (isset($params['category_pid'])) {
                 $newCategoryPid = (int) $params['category_pid'];
                 $oldCategoryPid = (int) $row['category_pid'];
                 if ($newCategoryPid === $oldCategoryPid && $newCategoryName === $oldCategoryName) {
                     unset($params['category_pid'], $params['category_name']);
                 }
             } else {
                 if ($newCategoryName === $oldCategoryName) {
                     unset($params['category_name']);
                 }
             }
         }
     }
     $rules = array('category_name' => 'trim', 'category_pid' => 'intval', 'alias' => 'trim', 'meta_title' => 'trim', 'meta_keywords' => 'trim', 'meta_description' => 'trim', 'tpl_home' => 'trim', 'tpl_list' => 'trim', 'tpl_view' => 'trim', 'sort' => 'intval');
     $ret = $this->clean($rules, $params);
     return $ret;
 }
Beispiel #3
0
 /**
  * 刷新用户的所有分组
  * @param integer $userId
  * @param array $groupIds
  * @return array
  */
 public function modify($userId, array $groupIds)
 {
     if (($userId = (int) $userId) <= 0) {
         Log::warning(sprintf('Usergroups user_id "%d" must be greater than 0', $userId), 0, __METHOD__);
         return false;
     }
     $news = array();
     foreach ($groupIds as $value) {
         if (($value = (int) $value) > 0) {
             if (!in_array($value, $news)) {
                 $news[] = $value;
             }
         }
     }
     $olds = $this->findGroupIdsByUserId($userId);
     $groupIdCreates = array_diff($news, $olds);
     $groupIdRemoves = array_diff($olds, $news);
     $rowCountCreate = $this->getDb()->batchCreate($userId, $groupIdCreates);
     $rowCountRemove = $this->getDb()->batchRemove($userId, $groupIdRemoves);
     $totalCreate = count($groupIdCreates);
     $totalRemove = count($groupIdRemoves);
     $errorCreate = $totalCreate - $rowCountCreate;
     $errorRemove = $totalRemove - $rowCountRemove;
     if ($errorCreate > 0 || $errorRemove > 0) {
         Log::warning(sprintf('Usergroups user_id "%d", group_ids "%s", Create {total "%d", success "%d", error "%d"}, Remove {total "%d", success "%d", error "%d"}', $userId, serialize($groupIds), $totalCreate, $rowCountCreate, $errorCreate, $totalRemove, $rowCountRemove, $errorRemove), 0, __METHOD__);
         return false;
     }
     return true;
 }
Beispiel #4
0
 /**
  * 新增或编辑前执行
  * @param string $context
  * @param array $row
  * @param mixed $params
  * @return void
  */
 public function onBeforeSave($context, array &$row, $params = null)
 {
     $isCreate = $context === 'advert\\services\\Adverts::create' ? true : false;
     $isModify = $context === 'advert\\services\\Adverts::modifyByPk' ? true : false;
     if (!$isCreate && !$isModify) {
         return;
     }
     $enum = DataAdverts::getShowTypeEnum();
     $showType = isset($row['show_type']) ? trim($row['show_type']) : '';
     if (!isset($enum[$showType])) {
         return;
     }
     if ($showType === DataAdverts::SHOW_TYPE_CODE) {
         return;
     }
     if (isset($row['show_code'])) {
         unset($row['show_code']);
     }
     $columns = array('advert_url', 'title', 'advert_src', 'advert_src2', 'attr_alt', 'attr_width', 'attr_height', 'attr_fontsize', 'attr_target');
     $hasColumn = false;
     foreach ($row as $columnName => $value) {
         if (in_array($columnName, $columns)) {
             $hasColumn = true;
             break;
         }
     }
     if (!$hasColumn) {
         return;
     }
     if ($isModify) {
         if (($advertId = (int) $params) <= 0) {
             return;
         }
         $advert = Service::getInstance('Adverts', 'advert')->findByPk($advertId);
         if (!$advert || !is_array($advert) || !isset($advert['advert_id']) || !isset($advert['advert_url'])) {
             Log::warning(sprintf('PlgShowcode is unable to find the result by id "%d"', $advertId), ErrorNo::ERROR_DB_SELECT, __METHOD__);
             return;
         }
         foreach ($columns as $columnName) {
             if (!isset($row[$columnName])) {
                 $row[$columnName] = $advert[$columnName];
             }
         }
     }
     $typeKey = isset($row['type_key']) ? strtolower(trim($row['type_key'])) : '';
     if (in_array($typeKey, $this->_specialTypes)) {
         $object = Singleton::getInstance('advert\\plugins\\showcode\\Special' . ucfirst($typeKey));
     } else {
         $object = $this;
     }
     $object->setShowCode($showType, $row, $this);
 }
Beispiel #5
0
 /**
  * 发送邮件
  * @param string $toMail
  * @param string $subject
  * @param string $body
  * @return boolean
  */
 public static function sendMail($toMail, $subject, $body)
 {
     $smtp = null;
     if ($smtp === null) {
         $smtp = new Smtp(Options::getSmtpHost(), Options::getSmtpUsername(), Options::getSmtpPassword());
     }
     try {
         return $smtp->sendMail($toMail, $subject, $body);
     } catch (ErrorException $e) {
         Log::warning(sprintf('Tools sendMail Failed, SmtpHost: "%s", Message: "%s"', $smtp->getHost(), $e->getMessage()), $e->getCode(), __METHOD__);
     }
     return false;
 }
Beispiel #6
0
 /**
  * (non-PHPdoc)
  * @see \libsrv\FormProcessor::_cleanPreProcess()
  */
 protected function _cleanPreProcess(array $params)
 {
     if ($this->isUpdate()) {
         if (isset($params['topic_key'])) {
             $row = $this->_object->findByPk($this->id);
             if (!$row || !is_array($row) || !isset($row['topic_key'])) {
                 Log::warning(sprintf('FpTopic is unable to find the result by id "%d"', $this->id), ErrorNo::ERROR_DB_SELECT, __METHOD__);
                 return false;
             }
             $topicKey = trim($params['topic_key']);
             if ($topicKey === $row['topic_key']) {
                 unset($params['topic_key']);
             }
         }
     }
     $rules = array('topic_name' => 'trim', 'topic_key' => 'trim', 'cover' => 'trim', 'meta_title' => 'trim', 'meta_keywords' => 'trim', 'is_published' => 'trim', 'sort' => 'intval', 'use_header' => 'trim', 'use_footer' => 'trim', 'dt_created' => 'trim');
     $ret = $this->clean($rules, $params);
     return $ret;
 }
Beispiel #7
0
 /**
  * (non-PHPdoc)
  * @see \libsrv\FormProcessor::_cleanPreProcess()
  */
 protected function _cleanPreProcess(array $params)
 {
     if ($this->isUpdate()) {
         if (isset($params['type_key'])) {
             $row = $this->_object->findByPk($this->id);
             if (!$row || !is_array($row) || !isset($row['type_key'])) {
                 Log::warning(sprintf('FpTypes is unable to find the result by id "%d"', $this->id), ErrorNo::ERROR_DB_SELECT, __METHOD__);
                 return false;
             }
             $typeKey = trim($params['type_key']);
             if ($typeKey === $row['type_key']) {
                 unset($params['type_key']);
             }
         }
     }
     $rules = array('type_key' => 'trim', 'type_name' => 'trim');
     $ret = $this->clean($rules, $params);
     return $ret;
 }
Beispiel #8
0
 /**
  * 执行表单数据验证操作
  * @param string $opType
  * @param array $params
  * @param integer|array $id
  * @return boolean
  * @throws ErrorException 如果指定的操作类型不是INSERT或UPDATE,抛出异常
  * @throws ErrorException 如果是UPDATE操作类型但是ID小于等于0,抛出异常
  */
 public function run($opType, array $params, $id = 0)
 {
     $this->clearValues();
     $this->clearErrors();
     $this->_opType = strtoupper($opType);
     if (!defined('static::OP_' . $this->_opType)) {
         throw new ErrorException(sprintf('FormProcessor op type "%s" must be INSERT or UPDATE', $this->_opType));
     }
     $this->id = Clean::positiveInteger($id);
     if ($this->isUpdate() && $this->id === false) {
         $isArr = is_array($id);
         Log::warning(sprintf('FormProcessor op type is Update, "%s" "%s" must be greater than 0', $isArr ? 'IDs' : 'ID', $isArr ? serialize($id) : $id));
         return false;
     }
     $params = $this->_cleanPreProcess($params);
     if ($params === false) {
         return false;
     }
     if ($this->_process($params)) {
         return $this->_cleanPostProcess();
     }
     return false;
 }
Beispiel #9
0
 /**
  * 通过主键,编辑“权限设置”
  * <pre>
  * $params = array (
  *   'app_name' => array (
  *     'mod_name' => array (
  *       'ctrl_name' => array (
  *         'Power-SELECT', 'Power-INSERT', 'Power-UPDATE', 'Power-DELETE'
  *       )
  *     )
  *   )
  * );
  * 示例:
  * $params = array (
  *   'administrator' => array (
  *     'system' => array (
  *       'site' => array ( '1', '2', '4', '8' ),
  *     ),
  *     'posts' => array (
  *       'categories' => array ( '1', '2', '4', '8' ),
  *       'modules' => array ( '1', '2', '4', '8' ),
  *       'posts' => array ( '1', '2', '4', '8' ),
  *     ),
  *   ),
  *   'passport' => array (
  *     'system' => array (
  *       'options' => array ( '1', '2', '4', '8' ),
  *       'pictures' => array ( '1', '2', '4', '8' ),
  *       'site' => array ( '1', '2', '4', '8' ),
  *     ),
  *     'users' => array (
  *       'account' => array ( '1', '2', '4', '8' ),
  *       'amcas' => array ( '1', '2', '4', '8' ),
  *       'groups' => array ( '1', '2', '4', '8' ),
  *       'users' => array ( '1', '2', '4', '8' ),
  *     ),
  *   ),
  *   'programmer' => array (
  *     'builder' => array (
  *       'builders' => array ( '1', '2', '4', '8' ),
  *       'fields' => array ( '1', '2', '4', '8' ),
  *       'groups' => array ( '1', '2', '4', '8' ),
  *       'tblnames' => array ( '1', '2', '4', '8' ),
  *       'types' => array ( '1', '2', '4', '8' ),
  *       'validators' => array ( '1', '2', '4', '8' ),
  *     ),
  *     'system' => array (
  *       'site' => array ( '1', '2', '4', '8' ),
  *     ),
  *   ),
  * );
  * </pre>
  * @param integer $groupId
  * @param array $params
  * @return array
  */
 public function modifyPermissionByPk($groupId, array $params)
 {
     if (($groupId = (int) $groupId) <= 0) {
         Log::warning(sprintf('Groups group_id "%d" must be greater than 0', $groupId), 0, __METHOD__);
         return false;
     }
     $amcas = Service::getInstance('Amcas', $this->_srvName)->findAllByRecur();
     $powerEnum = DataGroups::getPowerEnum();
     $data = array();
     foreach ($params as $appName => $mods) {
         if (!isset($amcas[$appName])) {
             Log::warning(sprintf('Groups is unable to find the app name "%s".', $appName), 0, __METHOD__);
             return false;
         }
         if (!is_array($mods)) {
             continue;
         }
         foreach ($mods as $modName => $ctrls) {
             if (!isset($amcas[$appName]['rows'][$modName])) {
                 Log::warning(sprintf('Groups is unable to find the mod name "%s-%s".', $appName, $modName), 0, __METHOD__);
                 return false;
             }
             if (!is_array($ctrls)) {
                 continue;
             }
             foreach ($ctrls as $ctrlName => $powers) {
                 if (!isset($amcas[$appName]['rows'][$modName]['rows'][$ctrlName])) {
                     Log::warning(sprintf('Groups is unable to find the ctrl name "%s-%s-%s".', $appName, $modName, $ctrlName), 0, __METHOD__);
                     return false;
                 }
                 if (!is_array($powers)) {
                     continue;
                 }
                 foreach ($powers as $power) {
                     $power = (int) $power;
                     if (!isset($powerEnum[$power])) {
                         Log::warning(sprintf('Groups is unable to find the power "%s-%s-%s-%d".', $appName, $modName, $ctrlName, $power), 0, __METHOD__);
                         return false;
                     }
                     $data[$appName][$modName][$ctrlName][] = $power;
                 }
             }
         }
     }
     $data = base64_encode(serialize($data));
     $rowCount = $this->getDb()->modifyPermissionByPk($groupId, $data);
     if ($rowCount > 0) {
         $authoriz = new Authoriz();
         if (!$authoriz->flush()) {
             Log::warning('Groups Authoriz flush roles cache Failed.', 0, __METHOD__);
         }
     }
     return $rowCount;
 }
Beispiel #10
0
 /**
  * 从Cookie中获取用户身份信息并设置到用户身份管理类
  * @return boolean
  */
 public function initIdentity()
 {
     $clusterName = self::CLUSTER_NAME;
     $config = Cfg::getApp($clusterName);
     $expiry = isset($config['expiry']) ? (int) $config['expiry'] : 0;
     $cookieName = isset($config['cookie_name']) ? trim($config['cookie_name']) : '';
     $cooksetPassword = isset($config['cookset_password']) ? (bool) $config['cookset_password'] : false;
     $cooksetRoleNames = isset($config['cookset_rolenames']) ? (bool) $config['cookset_rolenames'] : false;
     $cooksetAppNames = isset($config['cookset_appnames']) ? (bool) $config['cookset_appnames'] : false;
     if ($cookieName === '') {
         Log::warning(sprintf('Account cookie name must be string and not empty, cluster_name "%s"', $clusterName), 0, __METHOD__);
         return false;
     }
     $authentica = new Authentica($clusterName);
     $data = $authentica->getIdentity();
     if (!$data || !is_array($data) || !isset($data['user_id'])) {
         Log::debug(sprintf('Account cookie data must be array and not empty, cluster_name "%s", cookie_name "%s"', $clusterName, $cookieName), 0, __METHOD__);
         return false;
     }
     $userId = isset($data['user_id']) ? (int) $data['user_id'] : 0;
     $loginName = isset($data['user_name']) ? trim($data['user_name']) : '';
     $password = isset($data['password']) ? $data['password'] : '';
     $ip = isset($data['ip']) ? (int) $data['ip'] : 0;
     $expiry = isset($data['expiry']) ? (int) $data['expiry'] : 0;
     $time = isset($data['time']) ? (int) $data['time'] : 0;
     $nickname = isset($data['nickname']) ? trim($data['nickname']) : '';
     $roleNames = isset($data['role_names']) ? (array) $data['role_names'] : array();
     $extends = isset($data['extends']) ? $data['extends'] : '';
     if ($userId <= 0 || $loginName === '') {
         Log::warning(sprintf('Account cookie user_id and login_name must be not empty, cluster_name "%s", cookie_name "%s", user_id "%d", login_name "%s"', $clusterName, $cookieName, $userId, $loginName), 0, __METHOD__);
         return false;
     }
     $clientIp = ip2long(Ap::getRequest()->getClientIp());
     if ($ip !== $clientIp) {
         Log::warning(sprintf('Account cookie ip "%s" is not equal to client ip "%s", cluster_name "%s", cookie_name "%s", user_id "%d", login_name "%s"', long2ip($ip), long2ip($clientIp), $clusterName, $cookieName, $userId, $loginName), 0, __METHOD__);
         return false;
     }
     if ($cooksetPassword) {
         if ($password === '') {
             Log::warning(sprintf('Account config cookset_password and cookie password must be not empty, cluster_name "%s", cookie_name "%s", user_id "%d", login_name "%s"', $clusterName, $cookieName, $userId, $loginName), 0, __METHOD__);
             return false;
         }
         $dbpwd = $this->_users->getPasswordByUserId($userId);
         if ($password !== $dbpwd) {
             Log::warning(sprintf('Account cookie password "%s" is not equal to db password "%s", cluster_name "%s", cookie_name "%s", user_id "%d", login_name "%s"', $clusterName, $cookieName, $userId, $loginName), 0, __METHOD__);
             return false;
         }
     }
     $groupIds = $roleNames;
     $appNames = explode(',', $extends);
     $authoriz = $this->getAuthoriz($roleNames);
     Identity::setAll($userId, $loginName, $nickname, $roleNames, $appNames, 0, 0, $authoriz);
     return true;
 }
Beispiel #11
0
 /**
  * (non-PHPdoc)
  * @see \tfc\db\Statement::getColumnCount()
  */
 public function getColumnCount()
 {
     try {
         return parent::getColumnCount();
     } catch (ErrorException $e) {
         Log::warning($e->getMessage(), $e->getCode(), __METHOD__);
     }
     return 0;
 }
Beispiel #12
0
 /**
  * 清理正整数数据,如果为负数则返回false
  * @param integer|array $value
  * @return mixed
  */
 public function cleanPositiveInteger($value)
 {
     $result = Clean::positiveInteger($value);
     if ($result === false) {
         $isArr = is_array($value);
         Log::warning(sprintf('AbstractService cleanPositiveInteger ARGS Error, "%s" "%s" must be greater than 0', $isArr ? 'PKs' : 'PK', $isArr ? serialize($value) : $value));
     }
     return $result;
 }
Beispiel #13
0
 /**
  * (non-PHPdoc)
  * @see \libsrv\FormProcessor::_cleanPostProcess()
  */
 public function _cleanPostProcess()
 {
     if (isset($this->when)) {
         $enum = DataAddresses::getWhenEnum();
         if (!isset($enum[$this->when])) {
             $this->when = DataAddresses::WHEN_ANYONE;
         }
     }
     if (isset($this->is_default)) {
         $enum = DataAddresses::getIsDefaultEnum();
         if (!isset($enum[$this->is_default])) {
             $this->is_default = DataAddresses::IS_DEFAULT_N;
         }
     }
     if ($this->isUpdate()) {
         $row = $this->_object->findByPk($this->id);
         if (!$row || !is_array($row) || !isset($row['address_id']) || !isset($row['mobiphone']) || !isset($row['telephone'])) {
             Log::warning(sprintf('FpAddresses is unable to find the result by id "%d"', $this->id), ErrorNo::ERROR_DB_SELECT, __METHOD__);
             return false;
         }
         if (isset($this->mobiphone) && $this->mobiphone === '') {
             if (!isset($this->telephone) && $row['telephone'] === '') {
                 $this->addError('mobiphone', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_MOBIPHONE_TELEPHONE_NOTEMPTY'));
                 return false;
             }
         }
         if (isset($this->telephone) && $this->telephone === '') {
             if (!isset($this->mobiphone) && $row['mobiphone'] === '') {
                 $this->addError('telephone', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_MOBIPHONE_TELEPHONE_NOTEMPTY'));
                 return false;
             }
         }
         $consignee = isset($this->consignee) ? $this->consignee : $row['consignee'];
     }
     if (isset($this->mobiphone) && $this->mobiphone === '' && (isset($this->telephone) && $this->telephone === '')) {
         $this->addError('mobiphone', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_MOBIPHONE_TELEPHONE_NOTEMPTY'));
         $this->addError('telephone', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_MOBIPHONE_TELEPHONE_NOTEMPTY'));
         return false;
     }
     if ($this->isInsert()) {
         $consignee = $this->consignee;
     }
     if ($this->isUpdate()) {
         if (!isset($this->addr_country_id) && !isset($this->addr_province_id) && !isset($this->addr_city_id) && !isset($this->addr_district_id)) {
             $this->address_name = $consignee . '-' . $row['addr_city'];
             return true;
         }
     }
     if (!isset($this->addr_country_id)) {
         $this->addr_country_id = 1;
     }
     if (!isset($this->addr_province_id)) {
         $this->addr_province_id = 0;
     }
     if (!isset($this->addr_city_id)) {
         $this->addr_city_id = 0;
     }
     if (!isset($this->addr_district_id)) {
         $this->addr_district_id = 0;
     }
     $addrCountryId = $this->addr_country_id;
     $addrProvinceId = $this->addr_province_id;
     $addrCityId = $this->addr_city_id;
     $addrDistrictId = $this->addr_district_id;
     $srv = Service::getInstance('Regions', 'system');
     $this->addr_country = $this->addr_province = $this->addr_city = $this->addr_district = '';
     $row = $srv->findByPk($addrCountryId);
     if ($row && is_array($row) && isset($row['region_pid'], $row['region_name'], $row['region_type'])) {
         if ((int) $row['region_pid'] === 0 && (int) $row['region_type'] === 0) {
             $this->addr_country = $row['region_name'];
         }
     }
     if ($this->addr_country === '') {
         $this->addError('addr_country_id', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_ADDR_ID_INTEGER'));
         return false;
     }
     $row = $srv->findByPk($addrProvinceId);
     if ($row && is_array($row) && isset($row['region_pid'], $row['region_name'], $row['region_type'])) {
         if ((int) $row['region_pid'] === $addrCountryId && (int) $row['region_type'] === 1) {
             $this->addr_province = $row['region_name'];
         }
     }
     if ($this->addr_province === '') {
         $this->addError('addr_province_id', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_ADDR_ID_INTEGER'));
         return false;
     }
     $row = $srv->findByPk($addrCityId);
     if ($row && is_array($row) && isset($row['region_pid'], $row['region_name'], $row['region_type'])) {
         if ((int) $row['region_pid'] === $addrProvinceId && (int) $row['region_type'] === 2) {
             $this->addr_city = $row['region_name'];
         }
     }
     if ($this->addr_city === '') {
         $this->addError('addr_city_id', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_ADDR_ID_INTEGER'));
         return false;
     }
     $row = $srv->findByPk($addrDistrictId);
     if ($row && is_array($row) && isset($row['region_pid'], $row['region_name'], $row['region_type'])) {
         if ((int) $row['region_pid'] === $addrCityId && (int) $row['region_type'] === 3) {
             $this->addr_district = $row['region_name'];
         }
     }
     if ($this->addr_district === '') {
         $this->addError('addr_district_id', Lang::_('SRV_FILTER_MEMBER_ADDRESSES_ADDR_ID_INTEGER'));
         return false;
     }
     $this->address_name = $consignee . '-' . $this->addr_city;
     return true;
 }
Beispiel #14
0
 /**
  * CURL方式提交数据
  * @param string $pathinfo
  * @param array $params
  * @param string $method
  * @return mixed
  */
 public function talk($pathinfo, array $params = array(), $method = 'GET')
 {
     $ral = $this->getRal();
     $ral->setLogId(Log::getId());
     $maxRetry = $this->getRetry();
     for ($retry = 0; $retry < $maxRetry; $retry++) {
         try {
             $result = $ral->talk($pathinfo);
             $message = 'Ral Exec Curl Successfully!';
             $code = 0;
         } catch (ErrorException $e) {
             $message = 'Ral Exec Curl Failed! ' . $e->getMessage();
             $code = $e->getCode();
             $result = false;
         }
         $event = array('msg' => $message, 'retry' => $retry, 'pathinfo' => $pathinfo, 'params' => serialize($params), 'method' => $method, 'config' => serialize($this->getConfig()));
         if ($result !== false) {
             Log::notice($event, __METHOD__);
             return $result;
         }
         Log::warning($event, $code, __METHOD__);
     }
     return $result;
 }
Beispiel #15
0
 /**
  * (non-PHPdoc)
  * @see \libsrv\FormProcessor::_cleanPreProcess()
  */
 protected function _cleanPreProcess(array $params)
 {
     if (isset($params['trash'])) {
         unset($params['trash']);
     }
     if ($this->isInsert()) {
         if (isset($params['salt'])) {
             unset($params['salt']);
         }
         if (isset($params['relation_member_id'])) {
             unset($params['relation_member_id']);
         }
         if (isset($params['dt_last_repwd'])) {
             unset($params['dt_last_repwd']);
         }
         if (isset($params['ip_last_repwd'])) {
             unset($params['ip_last_repwd']);
         }
         if (isset($params['repwd_count'])) {
             unset($params['repwd_count']);
         }
         $params['dt_registered'] = $params['dt_last_login'] = date('Y-m-d H:i:s');
         $params['ip_registered'] = $params['ip_last_login'] = Clean::ip2long(Ap::getRequest()->getClientIp());
         $params['login_count'] = 1;
         $params['salt'] = $this->_object->getSalt();
         $params['login_name'] = $loginName = isset($params['login_name']) ? trim($params['login_name']) : '';
         $params['login_type'] = $loginType = $this->_object->getLoginType($loginName);
         if ($this->_object->isMailLogin($loginType)) {
             if (!isset($params['member_mail']) || trim($params['member_mail']) === '') {
                 $params['member_mail'] = $loginName;
             }
         } elseif ($this->_object->isPhoneLogin($loginType)) {
             if (!isset($params['member_phone']) || trim($params['member_phone']) === '') {
                 $params['member_phone'] = $loginName;
             }
         }
         if (!isset($params['member_name']) || trim($params['member_name']) === '') {
             if ($this->_object->isMailLogin($loginType)) {
                 $params['member_name'] = strstr($loginName, '@', true);
             } else {
                 $params['member_name'] = $loginName;
             }
         }
     } else {
         $row = $this->_object->findByPk($this->id);
         if (!$row || !is_array($row) || !isset($row['repwd_count'])) {
             Log::warning(sprintf('FpPortal is unable to find the result by id "%d"', $this->id), ErrorNo::ERROR_DB_SELECT, __METHOD__);
             return false;
         }
         if (isset($params['login_name'])) {
             unset($params['login_name']);
         }
         if (isset($params['login_type'])) {
             unset($params['login_type']);
         }
         if (isset($params['salt'])) {
             unset($params['salt']);
         }
         if (isset($params['dt_registered'])) {
             unset($params['dt_registered']);
         }
         if (isset($params['ip_registered'])) {
             unset($params['ip_registered']);
         }
         $password = isset($params['password']) ? trim($params['password']) : '';
         if ($password !== '') {
             if (!isset($params['repassword'])) {
                 $params['repassword'] = '';
             }
             $params['salt'] = $this->_object->getSalt();
             $params['dt_last_repwd'] = date('Y-m-d H:i:s');
             $params['ip_last_repwd'] = Clean::ip2long(Ap::getRequest()->getClientIp());
             $params['repwd_count'] = (int) $row['repwd_count'] + 1;
         } else {
             if (isset($params['password'])) {
                 unset($params['password']);
             }
             if (isset($params['repassword'])) {
                 unset($params['repassword']);
             }
             if (isset($params['dt_last_repwd'])) {
                 unset($params['dt_last_repwd']);
             }
             if (isset($params['ip_last_repwd'])) {
                 unset($params['ip_last_repwd']);
             }
             if (isset($params['repwd_count'])) {
                 unset($params['repwd_count']);
             }
         }
     }
     $rules = array('login_name' => 'trim', 'login_type' => 'trim', 'password' => 'trim', 'repassword' => 'trim', 'salt' => 'trim', 'member_name' => 'trim', 'member_mail' => 'trim', 'member_phone' => 'trim', 'relation_member_id' => 'intval', 'dt_registered' => 'trim', 'dt_last_login' => 'trim', 'dt_last_repwd' => 'trim', 'ip_registered' => 'intval', 'ip_last_login' => 'intval', 'ip_last_repwd' => 'intval', 'login_count' => 'intval', 'repwd_count' => 'intval', 'valid_mail' => 'trim', 'valid_phone' => 'trim', 'forbidden' => 'trim');
     $ret = $this->clean($rules, $params);
     return $ret;
 }
Beispiel #16
0
 /**
  * 检查并上传文件
  * @param array $files
  * @return integer
  */
 public function save(array $files)
 {
     $errNo = self::SUCCESS_NUM;
     $upload = $this->getUpload();
     try {
         $upload->save($files);
     } catch (\Exception $e) {
         $errNo = $e->getCode();
         $errMsg = $e->getMessage();
         Log::warning($errMsg, $errNo, __METHOD__);
     }
     return $errNo;
 }
Beispiel #17
0
 /**
  * 批量编辑排序
  * @param array $params
  * @return integer
  */
 public function batchModifySort(array $params = array())
 {
     $rowCount = 0;
     $columnName = 'sort';
     foreach ($params as $pk => $value) {
         if ($this->batchModifyByPk($pk, array($columnName => $value))) {
             $rowCount += 1;
         } else {
             $errors = $this->getErrors();
             if ($errors) {
                 Log::warning(sprintf('Posts update args error, id "%d", params "%s", errors "%s"', $pk, serialize($params), serialize($errors)), 0, __METHOD__);
             }
         }
     }
     return $rowCount;
 }
Beispiel #18
0
 /**
  * 第三方账号登录
  * @param string $partner
  * @param string $openid
  * @return array
  */
 public function loginByPartner($partner, $openid)
 {
     if (($partner = trim($partner)) === '') {
         $errNo = DataAccount::ERROR_PARTNER_EMPTY;
         return array('err_no' => $errNo, 'err_msg' => DataAccount::getErrMsgByErrNo($errNo), 'data' => array());
     }
     if (($openid = trim($openid)) === '') {
         $errNo = DataAccount::ERROR_OPENID_EMPTY;
         return array('err_no' => $errNo, 'err_msg' => DataAccount::getErrMsgByErrNo($errNo), 'data' => array());
     }
     if (!in_array($partner, DataAccount::$partners)) {
         $errNo = DataAccount::ERROR_PARTNER_WRONG;
         return array('err_no' => $errNo, 'err_msg' => DataAccount::getErrMsgByErrNo($errNo), 'data' => array());
     }
     $loginName = $partner . '_' . $openid;
     $row = $this->_portal->findByLoginName($loginName);
     if (!$row || !is_array($row) || !isset($row['member_id'])) {
         $salt = $this->_portal->getSalt();
         $password = $this->_portal->encrypt(String::randStr(12), $salt);
         $params = array('login_name' => $loginName, 'login_type' => DataPortal::LOGIN_TYPE_PARTNER, 'password' => $password, 'salt' => $salt, 'member_name' => mt_rand(100000000, 999999999), 'ip_registered' => Clean::ip2long(Ap::getRequest()->getClientIp()));
         if (!$this->_portal->getDb()->create($params)) {
             Log::warning(sprintf('Account db create failed, login_name "%s", login_type "%s"', $loginName, DataPortal::LOGIN_TYPE_PARTNER), 0, __METHOD__);
         }
     }
     $ret = $this->checkName($loginName);
     $ret['err_msg'] = DataAccount::getErrMsgByErrNo($ret['err_no']);
     if ($ret['err_no'] !== DataAccount::SUCCESS_LOGIN_NUM) {
         return $ret;
     }
     $ret = $this->checkLogin($ret['data'], true);
     $ret['err_msg'] = DataAccount::getErrMsgByErrNo($ret['err_no']);
     if ($ret['err_no'] !== DataAccount::SUCCESS_LOGIN_NUM) {
         return $ret;
     }
     $ret = $this->setIdentity($ret['data'], false);
     $ret['err_msg'] = DataAccount::getErrMsgByErrNo($ret['err_no']);
     return $ret;
 }
Beispiel #19
0
 /**
  * (non-PHPdoc)
  * @see \libsrv\FormProcessor::_cleanPreProcess()
  */
 protected function _cleanPreProcess(array $params)
 {
     if (isset($params['trash'])) {
         unset($params['trash']);
     }
     if (isset($params['category_name'])) {
         unset($params['category_name']);
     }
     if (isset($params['creator_name'])) {
         unset($params['creator_name']);
     }
     if (isset($params['last_modifier_name'])) {
         unset($params['last_modifier_name']);
     }
     if ($this->isInsert()) {
         if (isset($params['last_modifier_id'])) {
             unset($params['last_modifier_id']);
         }
         if (isset($params['last_modifier_name'])) {
             unset($params['last_modifier_name']);
         }
         $params['dt_created'] = $params['dt_last_modified'] = date('Y-m-d H:i:s');
         $params['ip_created'] = $params['ip_last_modified'] = Clean::ip2long(Ap::getRequest()->getClientIp());
         if (!isset($params['sort'])) {
             $params['sort'] = 10000;
         }
     } else {
         $row = $this->_object->findByPk($this->id);
         if (!$row || !is_array($row) || !isset($row['creator_id']) || !isset($row['allow_other_modify'])) {
             Log::warning(sprintf('FpPosts is unable to find the result by id "%d"', $this->id), ErrorNo::ERROR_DB_SELECT, __METHOD__);
             return false;
         }
         $creatorId = isset($row['creator_id']) ? (int) $row['creator_id'] : 0;
         $lastModifierId = isset($params['last_modifier_id']) ? (int) $params['last_modifier_id'] : 0;
         if ($creatorId !== $lastModifierId) {
             if ($row['allow_other_modify'] !== DataPosts::ALLOW_OTHER_MODIFY_Y) {
                 $this->addError('allow_other_modify', Lang::_('SRV_FILTER_POSTS_ALLOW_OTHER_MODIFY_POWER'));
             }
         }
         if (isset($params['creator_id'])) {
             unset($params['creator_id']);
         }
         if (isset($params['creator_name'])) {
             unset($params['creator_name']);
         }
         if (isset($params['dt_created'])) {
             unset($params['dt_created']);
         }
         if (isset($params['ip_created'])) {
             unset($params['ip_created']);
         }
         if (isset($params['module_id'])) {
             unset($params['module_id']);
         }
         $params['dt_last_modified'] = date('Y-m-d H:i:s');
         $params['ip_last_modified'] = Clean::ip2long(Ap::getRequest()->getClientIp());
     }
     $rules = array('title' => 'trim', 'alias' => 'trim', 'keywords' => 'trim', 'sort' => 'intval', 'category_id' => 'intval', 'module_id' => 'intval', 'password' => 'trim', 'picture' => 'trim', 'is_head' => 'trim', 'is_recommend' => 'trim', 'is_jump' => 'trim', 'jump_url' => 'trim', 'is_published' => 'trim', 'dt_publish_up' => 'trim', 'dt_publish_down' => 'trim', 'comment_status' => 'trim', 'allow_other_modify' => 'trim', 'hits' => 'intval', 'praise_count' => 'intval', 'comment_count' => 'intval', 'creator_id' => 'intval', 'last_modifier_id' => 'intval');
     $ret = $this->clean($rules, $params);
     return $ret;
 }
Beispiel #20
0
 /**
  * 调用从回收站还原数据类方法
  * @param \libsrv\AbstractService $object
  * @param string $method
  * @param integer|array $id
  * @return array
  */
 public function callRestoreMethod(AbstractService $object, $method, $id)
 {
     $rowCount = $object->{$method}($id);
     if ($rowCount === false) {
         $errNo = ErrorNo::ERROR_ARGS_RESTORE;
         $errMsg = Lang::_('ERROR_MSG_ERROR_DB_RESTORE');
         Log::warning(sprintf('%s callRestoreMethod, service "%s", method "%s", id "%s"', $errMsg, get_class($object), $method, is_array($id) ? serialize($id) : $id), $errNo, __METHOD__);
         return array('err_no' => $errNo, 'err_msg' => $errMsg, 'id' => $id);
     }
     $errNo = ErrorNo::SUCCESS_NUM;
     $errMsg = $rowCount > 0 ? Lang::_('ERROR_MSG_SUCCESS_RESTORE') : Lang::_('ERROR_MSG_ERROR_DB_AFFECTS_ZERO');
     Log::debug(sprintf('%s callRestoreMethod, service "%s", method "%s", id "%s", rowCount "%d"', $errMsg, get_class($object), $method, is_array($id) ? serialize($id) : $id, $rowCount), $errNo, __METHOD__);
     return array('err_no' => $errNo, 'err_msg' => $errMsg, 'id' => $id, 'row_count' => $rowCount);
 }
Beispiel #21
0
 /**
  * 修改密码
  * @param integer $memberId
  * @param string $password
  * @param string $repassword
  * @return integer
  */
 public function modifyPasswordByPk($memberId, $password, $repassword)
 {
     $rowCount = $this->_portal->modifyPasswordByPk($memberId, $password, $repassword);
     if ($rowCount === false || $rowCount <= 0) {
         $errNo = DataRepwd::ERROR_REPWD_FAILED;
         Log::warning(sprintf('Repwd modify password failed, member_id "%d", password "%s", repassword "%s"', $memberId, $password, $repassword), $errNo, __METHOD__);
         $errors = $this->_portal->getErrors();
         return array('err_no' => $errNo, 'err_msg' => array_shift($errors));
     }
     $errNo = DataRepwd::SUCCESS_REPWD_NUM;
     return array('err_no' => $errNo, 'err_msg' => DataRepwd::getErrMsgByErrNo($errNo));
 }