框架登出还是返回框架。

浏览:1332 发布日期:2013/01/11 分类:求助交流 关键字: 登录 框架
从框架登出结果还是返回框架而不是返回登录页面
PublicAction.class.php <?php
class PublicAction extends Action {
    // 检查用户是否登录
    protected function checkUser() {
        if(!isset($_SESSION[C('USER_AUTH_KEY')])) {
            $this->error('没有登录',__GROUP__.'/Public/login');
        }
    }

    // 顶部页面
    public function top() {
        //$this->checkUser(); //加这里只是顶部退出了?????
        C('SHOW_RUN_TIME',false);            // 运行时间显示
        C('SHOW_PAGE_TRACE',false);
        $this->display();
    }

   public function center(){
        //$this->checkUser(); //加这里中间登出了
        C('SHOW_PAGE_TRACE',false);
        C('SHOW_RUN_TIME',false);            // 运行时间显示
        $this->display();
    }

    // 尾部页面
    public function down() {
        //$this->checkUser();//加这里尾部登出了 三个都加上变三块了 忒难看。神马原因啊
        C('SHOW_RUN_TIME',false);            // 运行时间显示
        C('SHOW_PAGE_TRACE',false);
        $this->display();
    }

    
    // 用户登录页面
    public function login() {
        if(!isset($_SESSION[C('USER_AUTH_KEY')])) {
            $this->display();
        }else{
            $this->redirect('Index/index');
        }
    }

    public function index() {
        //如果通过认证跳转到首页
        redirect(__GROUP__);
    }

    // 用户登出
    public function logout() {
        if(isset($_SESSION[C('USER_AUTH_KEY')])) {
            unset($_SESSION[C('USER_AUTH_KEY')]);
            unset($_SESSION);
            session_destroy();
            $this->success('登出成功!',__URL__.'/login/');
        }else {
            $this->error('已经登出!');//跳转到这里了
        }
    }

    // 登录检测
    public function checkLogin() {
        if(empty($_POST['account'])) {
            $this->error('帐号错误!');
        }elseif (empty($_POST['password'])){
            $this->error('密码必须!');
        }elseif (empty($_POST['verify'])){
            $this->error('验证码必须!');
        }
        //生成认证条件
        $map            =   array();
        // 支持使用绑定帐号登录
        $map['account']    = $_POST['account'];
        $map["status"]    =    array('gt',0);
        if(session('verify') != md5($_POST['verify'])) {
            $this->error('验证码错误!');
        }
        $authInfo = M('User')->where($map)->find();
        //使用用户名、密码和状态的方式进行认证
        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['loginAccount']        =    $authInfo['account'];
            $_SESSION['lastLoginTime']        =    $authInfo['last_login_time'];
            $_SESSION['login_count']    =    $authInfo['login_count'];
            $_SESSION['lastloginip']    =    $authInfo['last_login_ip'];
            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);
            $this->success('登录成功!',__GROUP__.'/Index/index');

        }
    }
     //显示系统信息
    public function right() {
        $info = array(
            '操作系统'=>PHP_OS,
            '运行环境'=>$_SERVER["SERVER_SOFTWARE"],
            'PHP运行方式'=>php_sapi_name(),
            
            '上传附件限制'=>ini_get('upload_max_filesize'),
           
            '北京时间'=>gmdate("Y年n月j日 H:i:s",time()+8*3600),
            '服务器域名/IP'=>$_SERVER['SERVER_NAME'].' [ '.gethostbyname($_SERVER['SERVER_NAME']).' ]',
            
            'register_globals'=>get_cfg_var("register_globals")=="1" ? "ON" : "OFF",
            'magic_quotes_gpc'=>(1===get_magic_quotes_gpc())?'YES':'NO',
            'magic_quotes_runtime'=>(1===get_magic_quotes_runtime())?'YES':'NO',
            'host'=>gethostbyname($_SERVER['SERVER_NAME']),
            );
        $this->assign('info',$info);
        $this->display();
    }
    // 更换密码
    public function changePwd() {
        $this->checkUser();
        //对表单提交处理进行处理或者增加非表单数据
        if(md5($_POST['verify'])    != $_SESSION['verify']) {
            $this->error('验证码错误!');
        }
        $map    =    array();
        $map['password']= md5($_POST['oldpassword']);
        if(isset($_POST['account'])) {
            $map['account']     =     $_POST['account'];
        }elseif(isset($_SESSION[C('USER_AUTH_KEY')])) {
            $map['id']        =    $_SESSION[C('USER_AUTH_KEY')];
        }
        //检查用户
        $User    =   M("User");
        if(!$User->where($map)->field('id')->find()) {
            $this->error('旧密码不符或者用户名错误!');
        }else {
            $User->password    =    md5($_POST['password']);
            $User->save();
            $this->success('密码修改成功!');
         }
    }

    public function profile() {
        $this->checkUser();
        $User     =     M("User");
        $vo    =    $User->getById($_SESSION[C('USER_AUTH_KEY')]);
        $this->assign('vo',$vo);
        $this->display();
    }

    public function verify() {
        $type     =     isset($_GET['type'])?$_GET['type']:'gif';
        import("@.ORG.Util.Image");
        Image::buildImageVerify(4,1,$type);
    }

    // 修改资料
    public function change() {
        $this->checkUser();
        $User     =     D("User");
        if(!$User->create()) {
            $this->error($User->getError());
        }
        $result    =    $User->save();
        if(false !== $result) {
            $this->success('资料修改成功!');
        }else{
            $this->error('资料修改失败!');
        }
    }
}
最佳答案
评论( 相关
后面还有条评论,点击查看>>