TP框架中的一些登录代码分享

<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller{
public function login(){

if(IS_POST){
$data = I('post.');
$verify = new \Think\Verify();
if(!$verify ->check($data['code']) ){
$this->error('验证码错误');
}
$model = D('Manager');
$manager =$model->where(array('username'=>$data['username']))->find();
if($manager && encrypt_password($data['password'])== $manager['password'] ){
session('manager_info',$manager);
$this->success('登陆成功',U('Admin/Index/index'));
}else{
$this ->error('登录失败');
}

}else{
$this ->display();
}
}


public function logout(){
session(null);
$this ->redirect('Admin/Login/login');
}

public function captcha(){
$config =array(
'length'=>4,
'useCurve'=>false,
'useNoise'=>false,
);

$verify =new \Think\Verify($config);
$verify ->entry();
}

}

posted @ 2017-08-16 00:04  千载白云  阅读(323)  评论(0编辑  收藏  举报