/580w/Lib/Action/PublicAction.class.php
PHP | 363 lines | 225 code | 20 blank | 118 comment | 34 complexity | 17c7daac7b7511d29bf4c155087dab19 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, LGPL-2.1
- <?php
- class PublicAction extends Action {
- public function _initialize() {
- import('ORG.Util.RBAC');
- if (C('USER_AUTH_ON') && !in_array(MODULE_NAME,explode(',',C('NOT_AUTH_MODULE')))) {
- if (!RBAC::AccessDecision()) {
- //???????
- if (!$_SESSION [C('USER_AUTH_KEY')]) {
- //???????
- redirect(PHP_FILE.C('USER_AUTH_GATEWAY'));
- }
- // ???? ????
- if (C ( 'RBAC_ERROR_PAGE' )) {
- // ????????
- redirect (C('RBAC_ERROR_PAGE' ));
- } else {
- if (C('GUEST_AUTH_ON' )) {
- $this->assign('jumpUrl',PHP_FILE.C('USER_AUTH_GATEWAY'));
- }
- // ??????
- $this->error ('?????');
- }
- }
- }
- import("ORG.Util.Page");//?????
- import("@.Com.ajaxpage");//??ajax???
- }
-
- public function checkLogin() {
- if(empty($_POST['account'])) {
- $this->error('?????');
- }elseif (empty($_POST['password'])){
- $this->error('?????');
- }elseif (empty($_POST['verify'])){
- $this->error('??????');
- }
- // ???????
- $verifyCodeStr = $_POST['verify'];
- $verifyCodeNum = array_flip($_SESSION['verifyCode']);
- $len = strlen(trim($_POST['verify']));
- for($i=0; $i<$len; $i++) {
- $verify .= $verifyCodeNum[$verifyCodeStr[$i]];
- }
- if($verify!='0123456789'){
- $this->error('??????');
- }
- $User = M('User');
- //??????
- $map = array();
- $map["account"] = $_POST['account'];
- $map["status"] = array('gt',0);
-
- //$authInfo = $User->find($map);
- $authInfo = RBAC::authenticate($map);
- //??????????????????
- if(false === $authInfo) {
- $this->error('??????????');
- }else {
- if($authInfo['password'] != md5($_POST['password'])) {
- $this->error('?????');
- }
- $_SESSION[C('USER_AUTH_KEY')] = $authInfo['id'];
- $_SESSION['email'] = $authInfo['email'];
- $_SESSION['loginUserName'] = $authInfo['nickname'];
- $_SESSION['lastLoginTime'] = $authInfo['last_login_time'];
- $_SESSION['login_count'] = $authInfo['login_count'];
- if($authInfo['account']=='admin') {
- $_SESSION['administrator'] = true;
- }
- //??????
- $User = M('User');
- $ip = get_client_ip();
- $time = time();
- $data = array();
- $data['id'] = $authInfo['id'];
- $data['last_login_time'] = $time;
- $data['login_count'] = array('exp','login_count+1');
- $data['last_login_ip'] = $ip;
- $User->save($data);
-
- // ??????
- RBAC::saveAccessList();
- $this->success('?????');
- }
- }
-
- public function login() {
- if(!isset($_SESSION[C('USER_AUTH_KEY')])) {
- $this->display();
- }else{
- $this->redirect('/Index/index');
- }
- }
-
- public function logout()
- {
- if(isset($_SESSION[C('USER_AUTH_KEY')])) {
- unset($_SESSION['menu'.$_SESSION[C('USER_AUTH_KEY')]]);
- unset($_SESSION[C('USER_AUTH_KEY')]);
- unset($_SESSION['administrator']);
- $this->assign("jumpUrl",__URL__.'/login/');
- $this->success('?????');
- }else {
- $this->error( '?????');
- }
- }
-
- /**
- +----------------------------------------------------------
- * ?????
- +----------------------------------------------------------
- * @access public
- +----------------------------------------------------------
- * @return void
- +----------------------------------------------------------
- * @throws FcsException
- +----------------------------------------------------------
- */
- function verify(){
- import("ORG.Util.Image");
- Image::showAdvVerify();
- }
-
- /**
- +----------------------------------------------------------
- * ???????????URL??
- * ?????????????
- * ???action??????
- +----------------------------------------------------------
- * @access public
- +----------------------------------------------------------
- * @return string
- +----------------------------------------------------------
- * @throws ThinkExecption
- +----------------------------------------------------------
- */
- function getReturnUrl()
- {
- return __URL__.'?'.C('VAR_MODULE').'='.MODULE_NAME.'&'.C('VAR_ACTION').'='.C('DEFAULT_ACTION');
- }
-
- /**
- +----------------------------------------------------------
- * ??????????
- * ??????
- +----------------------------------------------------------
- * @access protected
- +----------------------------------------------------------
- * @param string $name ??????
- +----------------------------------------------------------
- * @return HashMap
- +----------------------------------------------------------
- * @throws ThinkExecption
- +----------------------------------------------------------
- */
- protected function _search($name='')
- {
- //??????
- if(empty($name)) {
- $name = $this->name;
- }
- $model = D($name);
- $map = array();
- foreach($model->getDbFields() as $key=>$val) {
- if(isset($_REQUEST[$val]) && $_REQUEST[$val]!='') {
- $map[$val] = $_REQUEST[$val];
- }
- }
- return $map;
- }
-
- /**
- +----------------------------------------------------------
- * ??????????
- * ??????
- +----------------------------------------------------------
- * @access protected
- +----------------------------------------------------------
- * @param Model $model ????
- * @param HashMap $map ????
- * @param string $sortBy ??
- * @param boolean $asc ????
- +----------------------------------------------------------
- * @return void
- +----------------------------------------------------------
- * @throws ThinkExecption
- +----------------------------------------------------------
- */
- protected function _list($model,$map,$sortBy='',$asc=true)
- {
- //???? ??????
- if(isset($_REQUEST['order'])) {
- $order = $_REQUEST['order'];
- }else {
- $order = !empty($sortBy)? $sortBy: $model->getPk();
- }
- //????????????
- //?? sost?? 0 ???? ?0? ????
- if(isset($_REQUEST['sort'])) {
- $sort = $_REQUEST['sort']?'asc':'desc';
- }else {
- $sort = $asc?'asc':'desc';
- }
- //??????????
- $count = $model->count($map);
- if($count>0) {
- import("ORG.Util.Page");
- //??????
- if(!empty($_REQUEST['listRows'])) {
- $listRows = $_REQUEST['listRows'];
- }else {
- $listRows = '';
- }
- $p = new Page($count,$listRows);
- //??????
- $voList = $model->where($map)->order($order.' '.$sort)->limit($p->firstRow.','.$p->listRows)->findAll();
- //?????????????
- foreach($map as $key=>$val) {
- if(is_array($val)) {
- foreach ($val as $t){
- $p->parameter .= $key.'[]='.urlencode($t)."&";
- }
- }else{
- $p->parameter .= "$key=".urlencode($val)."&";
- }
- }
- //????
- $page = $p->show();
- //??????
- $sortImg = $sort ; //????
- $sortAlt = $sort == 'desc'?'????':'????'; //????
- $sort = $sort == 'desc'? 1:0; //????
- //??????
- $this->assign('list', $voList);
- $this->assign('sort', $sort);
- $this->assign('order', $order);
- $this->assign('sortImg', $sortImg);
- $this->assign('sortType', $sortAlt);
- $this->assign("page", $page);
- }
- return ;
- }
-
-
- function update() {
- $model = D($this->name);
- if(false === $vo = $model->create()) {
- $this->error($model->getError());
- }
- $result = $model->save();
- if($result) {
- //????
- $this->success('?????');
- }else {
- //????
- $this->error('?????');
- }
- }
-
- /**
- +----------------------------------------------------------
- * ??????
- +----------------------------------------------------------
- * @access public
- +----------------------------------------------------------
- * @return string
- +----------------------------------------------------------
- * @throws ThinkExecption
- +----------------------------------------------------------
- */
- public function delete()
- {
- //??????
- $model = D($this->name);
- if(!empty($model)) {
- $id = $_REQUEST['id'];
- if(isset($id)) {
- if($model->delete($id)){
- $this->success('?????');
- }else {
- $this->error('?????');
- }
- }else {
- $this->error('????');
- }
- }
- }
-
-
-
- /**
- +----------------------------------------------------------
- * ??????
- *
- +----------------------------------------------------------
- * @access public
- +----------------------------------------------------------
- * @return void
- +----------------------------------------------------------
- * @throws FcsException
- +----------------------------------------------------------
- */
-
-
- function sort()
- {
- $thismodel=$this->name;
- $list = D($thismodel);
- if(!$_REQUEST['pid']){
- $sortList = $list->order('seqNo asc')->findall();
- }else{
- $sortList = $list->where('pid='.$_REQUEST['pid'])->field('*')->order('seqNo asc')->findall();
- }
- //dump($sortList);
- $this->assign("thismodel",$thismodel);
- $this->assign("sortList",$sortList);
- $this->display('Public:sort');
- return ;
- }
-
-
- /**
- +----------------------------------------------------------
- * ????????
- *
- +----------------------------------------------------------
- * @access public
- +----------------------------------------------------------
- * @return void
- +----------------------------------------------------------
- * @throws FcsException
- +----------------------------------------------------------
- */
- function saveSort()
- {
- $seqNoList = $_POST['sortvaue'];
- if(!empty($seqNoList)) {
- //??????
- $thismodel=$this->name;
- $list = D($thismodel);
- $col = explode(',',$seqNoList);
- $i=1;
- foreach($col as $val) {
- $data['id'] =$val;
- $data['seqNo'] =$i;
- $list->data($data)->save();
- $i++;
- }
- }
- }
-
- protected function checkUser() {
- if(!isset($_SESSION[C('USER_AUTH_KEY')])) {
- $this->assign ('jumpUrl', PHP_FILE . C('USER_AUTH_GATEWAY') );
- $this->error('????');
- }
- }
- public function Switchframe(){
- //??
- $this->display();
- }
- }
- ?>