2015-07-28 15:15:57 +08:00
|
|
|
<?php
|
|
|
|
|
namespace User\Controller;
|
|
|
|
|
use Think\Controller;
|
|
|
|
|
|
|
|
|
|
/**
|
2016-01-24 11:54:16 +08:00
|
|
|
* @author Zhou Yuyang <1009465756@qq.com> 12:28 2016/1/23
|
|
|
|
|
* @copyright 2105-2018 SRCMS
|
2015-07-28 15:15:57 +08:00
|
|
|
* @homepage http://www.src.pw
|
2016-01-24 11:54:16 +08:00
|
|
|
* @version 1.5
|
2015-07-28 15:15:57 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class LoginController extends Controller {
|
|
|
|
|
//登陆主页
|
|
|
|
|
public function index(){
|
2016-01-24 11:54:16 +08:00
|
|
|
$tmodel= M('setting');
|
|
|
|
|
$title = $tmodel->where('id=1')->select();
|
|
|
|
|
$this->assign('title', $title);
|
2015-07-28 15:15:57 +08:00
|
|
|
$this->display();
|
|
|
|
|
}
|
|
|
|
|
//登陆验证
|
|
|
|
|
public function login(){
|
|
|
|
|
if(!IS_POST)$this->error("非法请求");
|
|
|
|
|
$member = M('member');
|
|
|
|
|
$username =I('username');
|
|
|
|
|
$password =I('password','','md5');
|
|
|
|
|
$code = I('verify','','strtolower');
|
|
|
|
|
//验证验证码是否正确
|
|
|
|
|
if(!($this->check_verify($code))){
|
|
|
|
|
$this->error('验证码错误');
|
|
|
|
|
}
|
|
|
|
|
//验证账号密码是否正确
|
|
|
|
|
$user = $member->where(array('username'=>$username,'password'=>$password))->find();
|
|
|
|
|
|
|
|
|
|
if(!$user) {
|
|
|
|
|
$this->error('账号或密码错误 :(') ;
|
|
|
|
|
}
|
|
|
|
|
//验证账户是否被禁用
|
|
|
|
|
if($user['status'] == 0){
|
|
|
|
|
$this->error('账号被禁用,请联系超级管理员 :(') ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新登陆信息
|
|
|
|
|
$data =array(
|
|
|
|
|
'id' => $user['id'],
|
|
|
|
|
'update_at' => time(),
|
|
|
|
|
'login_ip' => get_client_ip(),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//如果数据更新成功 跳转到后台主页
|
|
|
|
|
if($member->save($data)){
|
|
|
|
|
session('userId',$user['id']);
|
|
|
|
|
session('username',$user['username']);
|
|
|
|
|
$this->success("登陆成功",U('Index/index'));
|
|
|
|
|
}
|
|
|
|
|
//定向之后台主页
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//验证码
|
|
|
|
|
public function verify(){
|
2016-01-26 14:09:59 +08:00
|
|
|
ob_clean();
|
2015-07-28 15:15:57 +08:00
|
|
|
$Verify = new \Think\Verify();
|
2016-01-24 11:54:16 +08:00
|
|
|
$Verify->codeSet = '123456789abcdefg';
|
|
|
|
|
$Verify->fontSize = 16;
|
2015-07-28 15:15:57 +08:00
|
|
|
$Verify->length = 4;
|
|
|
|
|
$Verify->entry();
|
|
|
|
|
}
|
|
|
|
|
protected function check_verify($code){
|
|
|
|
|
$verify = new \Think\Verify();
|
|
|
|
|
return $verify->check($code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//退出登录
|
|
|
|
|
public function logout(){
|
|
|
|
|
session('userId',null);
|
|
|
|
|
session('username',null);
|
|
|
|
|
redirect(U('Login/index'));
|
|
|
|
|
}
|
2016-01-26 14:09:59 +08:00
|
|
|
}
|