<?php
class MemberModel extends Model{
        public function checklogin(){
			if(!cookie('feimao_username')) {
				header("Location:". U('login/index') ."");
			}else{
				$username = cookie('feimao_username');
				$u_data = M('admin')->where("username='$username'")->find();
				$salt = $u_data['salt'];
				$token = md5(md5($username).md5($salt));
				$data = M('admin_token')->where("username = '$username' and token='$token'")->find();
				if(!$data) {
					header("Location:". U('login/index') ."");
				}elseif($data['addtime']+C('logint') >= time()) {
					cookie('feimao_username',null);
					M('admin_token')->where("username = '$username' and token='$token'")->delete();
					header("Location:". U('login/index') ."");
				}else{
					//echo 1;
				}
			}
        }
		public function logout(){
			$username = cookie('feimao_username');
			cookie('feimao_username',null);
			M('admin_token')->where("username = '$username'")->delete();
			header("Location:". U('login/index') ."");
		}
    }
?>