Example #1
0
 /**
  * (non-PHPdoc)
  * @see \tfc\mvc\interfaces\Action::run()
  */
 public function run()
 {
     $req = Ap::getRequest();
     $mod = Model::getInstance('Social', 'member');
     $ret = $mod->modifyByPk(Identity::getUserId(), $req->getPost());
     $this->display($ret);
 }
Example #2
0
 /**
  * 检查用户是否登录,如果没有登录,跳转到登录页面
  * @return void
  */
 protected function _isLogin()
 {
     if (!$this->_validLogin) {
         return;
     }
     if (Identity::isLogin()) {
         return;
     }
     $this->display(array('err_no' => ErrorNo::ERROR_NO_LOGIN, 'err_msg' => libapp\Lang::_('ERROR_MSG_ERROR_NO_LOGIN')));
 }
Example #3
0
 /**
  * 检查用户身份授权,如果没有授权,跳转到403页面
  * @return void
  */
 protected function _isAuth()
 {
     if (!$this->_validAuth) {
         return;
     }
     if (!$this->_validLogin) {
         return;
     }
     $authoriz = Identity::getAuthoriz();
     if ($authoriz->isAllowed(APP_NAME, Mvc::$module, Mvc::$controller, $this->_power)) {
         return;
     }
     $this->display(array('err_no' => ErrorNo::ERROR_NO_POWER, 'err_msg' => libapp\Lang::_('ERROR_MSG_ERROR_NO_POWER')));
 }
Example #4
0
 /**
  * 检查用户身份授权,如果没有授权,跳转到403页面
  * @return void
  */
 protected function _isAuth()
 {
     if (!$this->_validAuth) {
         return;
     }
     if (!$this->_validLogin) {
         return;
     }
     $authoriz = Identity::getAuthoriz();
     if ($authoriz->isAllowed(APP_NAME, Mvc::$module, Mvc::$controller, $this->_power)) {
         return;
     }
     $this->err403();
 }
Example #5
0
 /**
  * (non-PHPdoc)
  * @see \tfc\mvc\interfaces\Action::run()
  */
 public function run()
 {
     Text::_('MOD_MEMBER__');
     $mod = Model::getInstance('Social', 'member');
     $row = $mod->findByPk(Identity::getUserId());
     if (is_array($row) && isset($row['birth_ymd'])) {
         $row['birth_y'] = substr($row['birth_ymd'], 0, 4);
         $row['birth_m'] = substr($row['birth_ymd'], 5, 2);
         $row['birth_d'] = substr($row['birth_ymd'], 8, 2);
     }
     //\tfc\saf\debug_dump($row);
     $this->assign('sex_enum', DataSocial::getSexEnum());
     $this->assign('interests_enum', DataSocial::getInterestsEnum());
     $this->render($row);
 }
Example #6
0
 /**
  * (non-PHPdoc)
  * @see \tfc\mvc\Widget::run()
  */
 public function run()
 {
     $output = '';
     $html = $this->getHtml();
     $config = Cfg::getApp('navbar');
     foreach ($config as $menus) {
         $main = array_shift($menus);
         if (!is_array($main)) {
             continue;
         }
         // 主菜单
         if (!$menus) {
             $output .= $html->tag('li', $this->getAttributes($main, false), $this->a($main)) . "\n";
             continue;
         }
         // 主菜单外开始标签
         $output .= $html->openTag('li', $this->getAttributes($main, true)) . "\n";
         $output .= $this->a($main, true) . "\n";
         // 下拉子菜单外开始标签
         $output .= $html->openTag('ul', array('class' => 'dropdown-menu')) . "\n";
         // 下拉子菜单列表
         $total = count($menus);
         $curr = 0;
         foreach ($menus as $menu) {
             $output .= $html->tag('li', array(), $this->a($menu)) . "\n";
             if (++$curr < $total) {
                 $output .= $html->tag('li', array('class' => 'divider'), '') . "\n";
             }
         }
         // 下拉子菜单外结束标签
         $output .= $html->closeTag('ul') . "\n";
         // 主菜单外结束标签
         $output .= $html->closeTag('li') . "\n";
     }
     $this->assign('is_login', Identity::isLogin());
     $this->assign('user_id', Identity::getUserId());
     $this->assign('login_name', Identity::getLoginName());
     $this->assign('user_name', Identity::getNickname());
     $this->assign('app_names', Identity::getAppNames());
     $this->assign('menus', $output);
     $this->assign('logout', $this->getView()->CFG_SYSTEM_GLOBAL_LOGOUT);
     $this->display();
 }
Example #7
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;
 }
Example #8
0
 /**
  * 通过主键,编辑一条记录
  * @param integer $id
  * @param array $params
  * @return array
  */
 public function modifyByPk($id, array $params = array())
 {
     $params['last_modifier_id'] = Identity::getUserId();
     if (isset($params['content'])) {
         $params['content'] = String::stripslashes($params['content']);
     }
     return parent::modifyByPk($id, $params);
 }
Example #9
0
 /**
  * 操作会员账户
  * @param string $columnName
  * @param string $opType
  * @param integer $memberId
  * @param integer|float $value
  */
 public function opAccount($columnName, $opType, $memberId, $value)
 {
     $funcName = 'op' . ucfirst(strtolower($columnName));
     $ret = $this->getService()->{$funcName}($opType, $memberId, $value, DataMembers::SOURCE_ADMINOP, '', Identity::getUserId());
     if ($ret) {
         $errNo = ErrorNo::SUCCESS_NUM;
         $errMsg = Lang::_('ERROR_MSG_SUCCESS_UPDATE');
     } else {
         $errNo = ErrorNo::ERROR_DB_UPDATE;
         $errMsg = Lang::_('ERROR_MSG_ERROR_DB_UPDATE');
     }
     return array('err_no' => $errNo, 'err_msg' => $errMsg);
 }
Example #10
0
 /**
  * 递归获取指定类型下的所有菜单
  * @param string $typeKey
  * @param integer $menuPid
  * @return array
  */
 public static function findRows($typeKey, $menuPid = 0)
 {
     $allowUnregistered = Identity::isLogin() ? true : false;
     $rows = self::getService()->findRows($typeKey, $menuPid, $allowUnregistered);
     return $rows;
 }
Example #11
0
 /**
  * 投票
  * @param string $pollKey
  * @param string $value
  * @return array
  */
 public function addVote($pollKey, $value)
 {
     $ret = $this->_service->addVote($pollKey, $value, Identity::getUserId(), Identity::getRankId());
     return $ret;
 }
Example #12
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;
     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;
     }
     $memberId = 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 ($memberId <= 0 || $loginName === '') {
         Log::warning(sprintf('Account cookie member_id and login_name must be not empty, cluster_name "%s", cookie_name "%s", member_id "%d", login_name "%s"', $clusterName, $cookieName, $memberId, $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", member_id "%d", login_name "%s"', long2ip($ip), long2ip($clientIp), $clusterName, $cookieName, $memberId, $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", member_id "%d", login_name "%s"', $clusterName, $cookieName, $memberId, $loginName), 0, __METHOD__);
             return false;
         }
         $dbpwd = $this->_portal->getPasswordByUserId($memberId);
         if ($password !== $dbpwd) {
             Log::warning(sprintf('Account cookie password "%s" is not equal to db password "%s", cluster_name "%s", cookie_name "%s", member_id "%d", login_name "%s"', $clusterName, $cookieName, $memberId, $loginName), 0, __METHOD__);
             return false;
         }
     }
     $typeId = $rankId = 0;
     foreach ($roleNames as $name) {
         $prev = substr($name, 0, 7);
         if ($prev === 'type_id') {
             $typeId = (int) substr($name, 8);
             continue;
         }
         if ($prev === 'rank_id') {
             $rankId = (int) substr($name, 8);
             continue;
         }
     }
     $appNames = array();
     $authoriz = null;
     Identity::setAll($memberId, $loginName, $nickname, $roleNames, $appNames, $typeId, $rankId, $authoriz);
     return true;
 }
Example #13
0
 /**
  * 通过原始密码修改
  * @param string $oldPwd
  * @param string $password
  * @param string $repassword
  * @return array
  */
 public function repwdByOldPwd($oldPwd, $password, $repassword)
 {
     $ret = $this->_service->repwdByOldPwd(Identity::getLoginName(), $oldPwd, $password, $repassword);
     $ret['data'] = array('old_pwd' => $oldPwd, 'password' => $password, 'repassword' => $repassword);
     return $ret;
 }
Example #14
0
 /**
  * 将会员账户信息设置到模板变量中
  * @return void
  */
 public function assignAccount()
 {
     $viw = Mvc::getView();
     $viw->assign('is_login', Identity::isLogin());
     $viw->assign('member_id', Identity::getUserId());
     $viw->assign('login_name', Identity::getLoginName());
     $viw->assign('member_name', Identity::getNickname());
     $viw->assign('type_id', Identity::getTypeId());
     $viw->assign('rank_id', Identity::getRankId());
 }