这个项目需要用thinkPHP实现,现在thinkPHP增删改查的功能如何实现都明白了,但是如何却被实现--登陆页面--的问题卡主了。
后台入口是admin.php,它连得是index.html,这个页面放的就是用户名,密码输入窗体,用途是管理员从这输入用户名密码然后进入后台管理,如果单纯用PHP敲代码,很容易,关键是thinkPHP第一次用,不熟悉怎么样实现验证用户名密码的验证啊?求高手指教,还有我知道网上有一个分了四步关于从注册,到登陆的例子,我看了那个了,不懂。拜托了,已经整了2天了,快崩溃了~~~

解决方案 »

  1.   

    越简单越好,我现在的思维还是停留在编写php代码上,用thinkPHP做,思维上还跟不上~~~求个领路人~~~
      

  2.   

    我也是在苦恼这个问题。
    我再看别人的思路。
    if(!isset($_SESSION[C('USER_AUTH_KEY')]))
    {
    $this->redirect('login','Public');
    }
    看懂了以电脑,还在思考···
    如果没验证,转向login。
      

  3.   

    记得tp的完整包里面有个RBAC的文档,拿下来看看照着做就行了,不太难的
      

  4.   

    登陆里调用$this->display("index");
    再写个接收POST数据的方法,判断用户名和密码
      

  5.   

    别用它的RBAC,不是有IndexAction么?然后里面有index方法对吧?你在这里设登录验证不就可以么?对吧?
      

  6.   

    admin/下面的PublicAction
    class PublicAction extends Action {
    // 检查用户是否登录
    protected function checkUser(){
    if(!isset($_SESSION[C('USER_AUTH_KEY')])) {
    $this->assign('jumpUrl','login');
    $this->error('没有登录');
    }
    } //左侧页面
    public function leftframe(){
    $this->checkUser();
    $User  =  M("User");
    $vo = $User->getById($_SESSION[C('USER_AUTH_KEY')]);
    $this->assign('vo',$vo);
    $this->display();
    }

    //分组模块
    public function mainframe(){
    $model = M("Group");
    $list = $model->where('status=1')->getField('id,title');
    $this->assign('nodeGroupList',$list);
    $this->display();
    }    // 管理首页 查看系统信息
        public function sysframe(){
            $info = array(
                '操作系统'=>PHP_OS,
                '运行环境'=>$_SERVER["SERVER_SOFTWARE"],
                'PHP运行方式'=>php_sapi_name(),
                'ThinkPHP版本'=>THINK_VERSION.' [ <a href="http://thinkphp.cn" target="_blank">查看最新版本</a> ]',
                '上传附件限制'=>ini_get('upload_max_filesize'),
                '执行时间限制'=>ini_get('max_execution_time').'秒',
                '服务器时间'=>date("Y年n月j日 H:i:s"),
                '北京时间'=>gmdate("Y年n月j日 H:i:s",time()+8*3600),
                '服务器域名/IP'=>$_SERVER['SERVER_NAME'].' [ '.gethostbyname($_SERVER['SERVER_NAME']).' ]',
                '剩余空间'=>round((@disk_free_space(".")/(1024*1024)),2).'M',
                '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',
                );
            $this->assign('info',$info);
            $this->display();
        } // 用户登录页面
    public function login(){
    if(!isset($_SESSION[C('USER_AUTH_KEY')])) {
    $this->display();
    }else{
    $this->redirect('Index/index');
    }
    } public function index(){
    //如果通过认证跳转到首页
    redirect(__APP__);
    } // 用户登出
        public function logout(){
            if(isset($_SESSION[C('USER_AUTH_KEY')])) {
    unset($_SESSION[C('USER_AUTH_KEY')]);
    unset($_SESSION);
    session_destroy();
                $this->assign("jumpUrl",__URL__.'/login/');
                $this->success('登出成功!');
            }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('验证码错误!');
    }
    import ( 'ORG.Util.RBAC' );
            $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('登录成功!'); }
    }
    自己慢慢琢磨。官网有它自己的案例。
    官网下载http://thinkphp.cn/Down/4
      

  7.   

    楼上哥们是怎么把这种“划时代意义”的贴子给淘换出来的?
    万分佩服!!!
    这里有个TinkPHP框架实例,也许有帮助:http://download.csdn.net/detail/dmtnewtons/4301371