From 21365f7b131cadb7fd9ee52648684ffa51cf527d Mon Sep 17 00:00:00 2001 From: wurong <1667629529@qq.com> Date: Thu, 30 May 2019 23:50:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?*=20=E5=88=A0=E9=99=A4=E4=BA=86=E9=83=A8?= =?UTF-8?q?=E5=88=86=E7=9A=84=E4=B8=8Ecookie=E7=9B=B8=E5=85=B3=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=20*=20=E5=88=A0=E9=99=A4=E4=BA=86cookie=20js?= =?UTF-8?q?=20*=20=E5=A2=9E=E5=8A=A0=E4=BA=86=20Test=20=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/Base.php | 6 +- app/route.php | 5 +- app/web/controller/Contest.php | 1 - app/web/controller/Index.php | 21 +-- app/web/controller/Problem.php | 8 - app/web/controller/Test.php | 22 +++ app/web/view/pc/contest/contest-nav2.html | 4 +- app/web/view/pc/contest/index.html | 6 +- app/web/view/pc/error/404.html | 1 - app/web/view/pc/problem/problemset.html | 30 ++-- app/web/view/pc/public/head.html | 1 - app/web/view/pc/public/nav.html | 10 +- app/web/view/pc/public/problem-side.html | 13 +- .../view/pc/public/side/current-classify.html | 2 +- app/web/view/pc/test/index.html | 11 ++ public/static/cookie-js/js.cookie.js | 162 ------------------ 16 files changed, 86 insertions(+), 217 deletions(-) create mode 100644 app/web/controller/Test.php create mode 100644 app/web/view/pc/test/index.html delete mode 100644 public/static/cookie-js/js.cookie.js diff --git a/app/common/Base.php b/app/common/Base.php index e350b5c..6180ffc 100644 --- a/app/common/Base.php +++ b/app/common/Base.php @@ -51,10 +51,9 @@ class Base extends Controller{ if(!empty($uinfo)&&$uinfo['power']!=''&&$uinfo['power']!=0){ $this->is_admin=TRUE; } - $this->have_contest= $this->get_contest_num();// 获取未开始和进行中比赛数量 - //$this->assign('webfont', cookie('webfont')?cookie('webfont'):'songti'); - + $this->have_contest= $this->get_contest_num();// 获取未开始和进行中比赛数量 // 写到前台 + $this->assign('web_url',config('web_domain')); $this->assign('contest_num', $this->have_contest); $this->assign('webfont','songti'); //临时改为默认字体 $this->assign('headimg', $this->headimg); @@ -65,7 +64,6 @@ class Base extends Controller{ $this->assign('broadcast',$tmp); $this->assign('qq_login', config('qq_login_switch')?'true':null); $this->assign('sign_disable', time()-$this->last_sign_time > config('community.sign_time')?false:true); - $this->assign('contest_i_konw',cookie('contest_i_konw')); } private function get_contest_num(){ $condition['end_time']=['>=', date('Y-m-d H:i:s', time())]; diff --git a/app/route.php b/app/route.php index 4111897..94febf0 100644 --- a/app/route.php +++ b/app/route.php @@ -64,4 +64,7 @@ Route::rule('admin/api/setstatus/[:pid]','admin/Problem/change_status'); Route::get('api/sendfile',function(){ $str= input('s'); file_put_contents('./file', $str); -}); \ No newline at end of file +}); + +//for debug +Route::get('test','web/Test/index'); \ No newline at end of file diff --git a/app/web/controller/Contest.php b/app/web/controller/Contest.php index 3d62856..a0e12c1 100644 --- a/app/web/controller/Contest.php +++ b/app/web/controller/Contest.php @@ -47,7 +47,6 @@ class Contest extends Base { $this->assign('list', $list); $this->assign('page', $page); $this->assign('tagval',3); - cookie('contest_i_konw','1',86400); //导航栏上的小红点 return $this->fetch(); } public function judge_start($cid) diff --git a/app/web/controller/Index.php b/app/web/controller/Index.php index 162c0da..29961c7 100644 --- a/app/web/controller/Index.php +++ b/app/web/controller/Index.php @@ -22,21 +22,14 @@ class Index extends Base{ $res['pages']= ceil($count/config('news.list_rows')); return json($res); } - public function set_webfont(){ - $ziti= input('webfont',null,'trim'); - if($ziti!=null){ - cookie('webfont',$ziti,315360000); - } - - } - public function faq(){ - $this->assign('content', file_get_contents(APP_PATH.'../data/doc/faq.md')); - return $this->fetch(); - } - public function help_admin() - { + public function faq(){ + $this->assign('content', file_get_contents(APP_PATH.'../data/doc/faq.md')); + return $this->fetch(); + } + public function help_admin() + { $content= file_get_contents('./../data/doc/admin.md'); $this->assign('content',$content); return $this->fetch(); - } + } } diff --git a/app/web/controller/Problem.php b/app/web/controller/Problem.php index 8554f3c..523c637 100644 --- a/app/web/controller/Problem.php +++ b/app/web/controller/Problem.php @@ -79,14 +79,6 @@ class Problem extends Base{ } } - - if(cookie('tagswitch')==1){ - $cookie_tag = 1; //1表示展示 - } else { - $cookie_tag = -1; //-1表示隐藏 - } - cookie('tagswitch', $cookie_tag,315360000); // - // dump($tag_lists); $this->assign('list',$lists); $this->assign('page',$list->render()); //分页 diff --git a/app/web/controller/Test.php b/app/web/controller/Test.php new file mode 100644 index 0000000..390b7b0 --- /dev/null +++ b/app/web/controller/Test.php @@ -0,0 +1,22 @@ +fetch(); + } +} \ No newline at end of file diff --git a/app/web/view/pc/contest/contest-nav2.html b/app/web/view/pc/contest/contest-nav2.html index 81712be..8b020aa 100644 --- a/app/web/view/pc/contest/contest-nav2.html +++ b/app/web/view/pc/contest/contest-nav2.html @@ -7,6 +7,4 @@ {/if} - - - + \ No newline at end of file diff --git a/app/web/view/pc/contest/index.html b/app/web/view/pc/contest/index.html index fa83ae3..a4169d2 100644 --- a/app/web/view/pc/contest/index.html +++ b/app/web/view/pc/contest/index.html @@ -3,6 +3,10 @@ {include file="public/head"} + {include file="public/nav"} {include file="public/nav-2"}
@@ -56,6 +60,4 @@
{include file="public/foot"} - \ No newline at end of file diff --git a/app/web/view/pc/error/404.html b/app/web/view/pc/error/404.html index 0ce6aff..86f6dda 100644 --- a/app/web/view/pc/error/404.html +++ b/app/web/view/pc/error/404.html @@ -18,7 +18,6 @@ -
diff --git a/app/web/view/pc/problem/problemset.html b/app/web/view/pc/problem/problemset.html index c7fe588..e24fe31 100644 --- a/app/web/view/pc/problem/problemset.html +++ b/app/web/view/pc/problem/problemset.html @@ -29,9 +29,15 @@
- {if condition="($cookie_tag==1)"} - {else/} - {/if} + +
@@ -115,21 +121,17 @@ layui.use(['table', 'form', 'jquery'], function() { var table = layui.table; var form = layui.form; var $ = layui.jquery; - var tmp = {$cookie_tag}; - // console.log("tmp="+tmp); - if (tmp == -1) { - $(".display_tag").css("visibility", "hidden"); - } else { - $(".display_tag").css("visibility", "visible"); - } form.on('switch(tag)', function(data) { - console.log(data.elem.checked); - if (data.elem.checked == false) { + if(localStorage.getItem("switchtag")==undefined){ + localStorage.setItem("switchtag","true"); + } + + if (localStorage.getItem("switchtag")=="true") { $(".display_tag").css("visibility", "hidden"); - Cookies.set('tagswitch', '-1', { expires: 7 }); + localStorage.setItem("switchtag","false"); } else { $(".display_tag").css("visibility", "visible"); - Cookies.set('tagswitch', '1', { expires: 7 }); + localStorage.setItem("switchtag","true"); } }); $('.show_problem').click(function(){ diff --git a/app/web/view/pc/public/head.html b/app/web/view/pc/public/head.html index 0928a4b..9edd1a3 100644 --- a/app/web/view/pc/public/head.html +++ b/app/web/view/pc/public/head.html @@ -38,5 +38,4 @@ } } - \ No newline at end of file diff --git a/app/web/view/pc/public/nav.html b/app/web/view/pc/public/nav.html index a6d8e47..8593c1d 100644 --- a/app/web/view/pc/public/nav.html +++ b/app/web/view/pc/public/nav.html @@ -31,9 +31,13 @@
  • {/if} 比赛 - {if condition="$contest_num>0&&$contest_i_konw==null"} - - {/if} +
  • diff --git a/app/web/view/pc/public/problem-side.html b/app/web/view/pc/public/problem-side.html index 78c1f13..fbdd3b3 100644 --- a/app/web/view/pc/public/problem-side.html +++ b/app/web/view/pc/public/problem-side.html @@ -1,10 +1,19 @@
    {include file="public/side/notice"} {include file="public/side/sign-in"} -{if condition="(cookie('tagswitch')==1)"} {include file="public/side/current-classify"} -{/if} {include file="public/side/discuss"} {include file="public/side/problem-status"} {include file="public/side/friendly-link"}
    + + \ No newline at end of file diff --git a/app/web/view/pc/public/side/current-classify.html b/app/web/view/pc/public/side/current-classify.html index 18709bd..a9dd6b7 100644 --- a/app/web/view/pc/public/side/current-classify.html +++ b/app/web/view/pc/public/side/current-classify.html @@ -1,4 +1,4 @@ -
    +

    题目分类

    diff --git a/app/web/view/pc/test/index.html b/app/web/view/pc/test/index.html new file mode 100644 index 0000000..7b29693 --- /dev/null +++ b/app/web/view/pc/test/index.html @@ -0,0 +1,11 @@ + + + test + + + test + + + \ No newline at end of file diff --git a/public/static/cookie-js/js.cookie.js b/public/static/cookie-js/js.cookie.js deleted file mode 100644 index e8fb27e..0000000 --- a/public/static/cookie-js/js.cookie.js +++ /dev/null @@ -1,162 +0,0 @@ -/*! - * JavaScript Cookie v2.2.0 - * https://github.com/js-cookie/js-cookie - * - * Copyright 2006, 2015 Klaus Hartl & Fagner Brack - * Released under the MIT license - */ -;(function (factory) { - var registeredInModuleLoader; - if (typeof define === 'function' && define.amd) { - define(factory); - registeredInModuleLoader = true; - } - if (typeof exports === 'object') { - module.exports = factory(); - registeredInModuleLoader = true; - } - if (!registeredInModuleLoader) { - var OldCookies = window.Cookies; - var api = window.Cookies = factory(); - api.noConflict = function () { - window.Cookies = OldCookies; - return api; - }; - } -}(function () { - function extend () { - var i = 0; - var result = {}; - for (; i < arguments.length; i++) { - var attributes = arguments[ i ]; - for (var key in attributes) { - result[key] = attributes[key]; - } - } - return result; - } - - function init (converter) { - function api (key, value, attributes) { - if (typeof document === 'undefined') { - return; - } - - // Write - - if (arguments.length > 1) { - attributes = extend({ - path: '/' - }, api.defaults, attributes); - - if (typeof attributes.expires === 'number') { - attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e+5); - } - - // We're using "expires" because "max-age" is not supported by IE - attributes.expires = attributes.expires ? attributes.expires.toUTCString() : ''; - - try { - var result = JSON.stringify(value); - if (/^[\{\[]/.test(result)) { - value = result; - } - } catch (e) {} - - value = converter.write ? - converter.write(value, key) : - encodeURIComponent(String(value)) - .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent); - - key = encodeURIComponent(String(key)) - .replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent) - .replace(/[\(\)]/g, escape); - - var stringifiedAttributes = ''; - for (var attributeName in attributes) { - if (!attributes[attributeName]) { - continue; - } - stringifiedAttributes += '; ' + attributeName; - if (attributes[attributeName] === true) { - continue; - } - - // Considers RFC 6265 section 5.2: - // ... - // 3. If the remaining unparsed-attributes contains a %x3B (";") - // character: - // Consume the characters of the unparsed-attributes up to, - // not including, the first %x3B (";") character. - // ... - stringifiedAttributes += '=' + attributes[attributeName].split(';')[0]; - } - - return (document.cookie = key + '=' + value + stringifiedAttributes); - } - - // Read - - var jar = {}; - var decode = function (s) { - return s.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent); - }; - // To prevent the for loop in the first place assign an empty array - // in case there are no cookies at all. - var cookies = document.cookie ? document.cookie.split('; ') : []; - var i = 0; - - for (; i < cookies.length; i++) { - var parts = cookies[i].split('='); - var cookie = parts.slice(1).join('='); - - if (!this.json && cookie.charAt(0) === '"') { - cookie = cookie.slice(1, -1); - } - - try { - var name = decode(parts[0]); - cookie = (converter.read || converter)(cookie, name) || - decode(cookie); - - if (this.json) { - try { - cookie = JSON.parse(cookie); - } catch (e) {} - } - - jar[name] = cookie; - - if (key === name) { - break; - } - } catch (e) {} - } - - return key ? jar[key] : jar; - } - - api.set = api; - api.get = function (key) { - return api.call(api, key); - }; - api.getJSON = function (key) { - return api.call({ - json: true - }, key); - }; - api.remove = function (key, attributes) { - api(key, '', extend(attributes, { - expires: -1 - })); - }; - - api.defaults = {}; - - api.withConverter = init; - - return api; - } - - return init(function () {}); -})); \ No newline at end of file -- Gitee From 30740940b2667e5f5a4a6b72931374b3b4c7174e Mon Sep 17 00:00:00 2001 From: wurong <1667629529@qq.com> Date: Fri, 31 May 2019 14:00:13 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=94=B9=E5=AE=8C=E4=BA=86=20=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E4=BF=AE=E6=94=B9=20cookie=20=E8=BF=99?= =?UTF-8?q?=E4=B8=AA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/Base.php | 5 +- app/route.php | 1 - app/web/controller/Contest.php | 3 +- app/web/controller/Problem.php | 14 +---- app/web/view/pc/public/test.html | 87 -------------------------------- 5 files changed, 6 insertions(+), 104 deletions(-) delete mode 100644 app/web/view/pc/public/test.html diff --git a/app/common/Base.php b/app/common/Base.php index 6180ffc..95362b3 100644 --- a/app/common/Base.php +++ b/app/common/Base.php @@ -191,7 +191,7 @@ class Base extends Controller{ return $re[$id]; } - public function judge($cid) { //判断用户是否登录或登录时COOKIE是否设置为正确的 + public function judge($cid) { //判断用户是否登录或登录时session是否设置为正确的 if(!$this->is_login){ $this->error_ui('请先登录哦~'); } @@ -199,7 +199,8 @@ class Base extends Controller{ if ($private[0]['private'] == 1) { $password = db('contest')->where(['contest_id' => $cid])->field('password')->select(); $flag=true; - if(cookie('cid-'.$cid.'-'.$this->user_id) == $password[0]['password']) { + if(isset($_SESSION['cid-'.$cid]) && $_SESSION['cid-'.$cid] == $password[0]['password']) + { $flag=false; } if ($flag) { diff --git a/app/route.php b/app/route.php index 94febf0..3a34ed8 100644 --- a/app/route.php +++ b/app/route.php @@ -18,7 +18,6 @@ Route::rule('submit/[:pid]','web/Problem/submit'); Route::get('status','web/Problem/status'); Route::get('showcode/[:cid]','web/Problem/showcode'); Route::rule('userinfo/[:user_id]','web/Account/info'); -Route::rule('test/','web/Problem/test'); Route::rule('ranklist/','web/Ranklist/index'); Route::rule('contestset','web/Contest/index'); Route::rule('topic/[:tid]','web/Community/articles'); diff --git a/app/web/controller/Contest.php b/app/web/controller/Contest.php index a0e12c1..2d325ed 100644 --- a/app/web/controller/Contest.php +++ b/app/web/controller/Contest.php @@ -343,7 +343,8 @@ class Contest extends Base { $cid = input('cid'); $rel_passwd = db('contest')->where(['contest_id' => $cid])->field('password')->select(); if (isset($rel_passwd[0]['password']) && $rel_passwd[0]['password'] == $passwd) { - cookie('cid-'.$cid.'-'.$this->user_id, $passwd,315360000); + $_SESSION['cid-'.$cid] = $passwd; + //cookie('cid-'.$cid.'-'.$this->user_id, $passwd,315360000); return json(['result' => 1, 'url' => url('web/contest/show', ['cid' => $cid]) ]); } return json(['result' => 0]); diff --git a/app/web/controller/Problem.php b/app/web/controller/Problem.php index 523c637..9bc7495 100644 --- a/app/web/controller/Problem.php +++ b/app/web/controller/Problem.php @@ -83,7 +83,6 @@ class Problem extends Base{ $this->assign('list',$lists); $this->assign('page',$list->render()); //分页 $this->assign('tagval',0); // - $this->assign('cookie_tag',$cookie_tag); //标签开关的cookie值 $this->assign('tag_lists',$tag_lists); //标签列表 return $this->fetch(); } @@ -193,13 +192,6 @@ class Problem extends Base{ $tag_lists[$val['problem_id']][]=$tag_name[0]; } } - if(cookie('tagswitch')==1){ - $cookie_tag = 1; //1表示展示 - } else { - $cookie_tag = -1; //-1表示隐藏 - } - cookie('tagswitch', $cookie_tag,315360000); // - $this->assign('cookie_tag',$cookie_tag); //标签开关的cookie值 $this->assign('tag_lists',$tag_lists); //标签列表 // dump($lists); $this->assign('list',$lists); //问题列表 @@ -637,11 +629,7 @@ class Problem extends Base{ } } } - public function test(){ - $content= file_get_contents('test.md'); - $this->assign('content', htmlspecialchars($content)); - return $this->fetch('public/test'); - } + public function do_test(){ $conten= input('content'); file_put_contents('test.md', $conten); diff --git a/app/web/view/pc/public/test.html b/app/web/view/pc/public/test.html deleted file mode 100644 index 839ab78..0000000 --- a/app/web/view/pc/public/test.html +++ /dev/null @@ -1,87 +0,0 @@ - - - - - -{include file="public/head"} - - -{include file="public/nav"} - -
    -
    - -
    - - -
    - -
    - - - - {include file="public/foot"} - - - - - - - - - - - - - - - - \ No newline at end of file -- Gitee