@@ -10,7 +10,7 @@ class Base{
1010 public $ ctx ;
1111 public $ token ;
1212
13- public function get_query ($ string ) {
13+ public function get_query ($ string ) { //获取url参数
1414 $ ctx = $ this ->ctx ;
1515 if (empty ($ string )) {
1616 return false ;
@@ -27,13 +27,13 @@ public function get_query($string) {
2727 return false ;
2828 }
2929
30- public function error ($ str = "失败 " ) {
30+ public function error ($ str = "失败 " ) { //自定义返回异常
3131 $ array ['Ok ' ] = false ;
3232 $ array ['Msg ' ] = $ str ;
3333 $ this ->ctx ->JSONP (200 , $ array );
3434 $ this ->ctx ->abort ();
3535 }
36- public function new_token () {
36+ public function new_token () { //新建一个token
3737 $ array = 'q.w.e.r.t.y.u.i.o.p.a.s.d.f.g.h.j.k.l.z.x.c.v.b.n.m.0.1.2.3.4.5.6.7.8.9 ' ;
3838 $ array = explode ('. ' , $ array );
3939 $ num = count ($ array );
@@ -48,27 +48,37 @@ public function new_token() {
4848 }
4949 return $ res .date ("ymdhis " );
5050 }
51- public function check_logined ($ token ) {
51+ public function check_logined ($ token ) {//判断是否登录
52+ $ token_cache = new Cache ($ token );
53+ if ($ token_cache ->exists and !$ token_cache ->expired ){
54+ if ($ token_cache ->value ){
55+ return true ;
56+ }
57+ }
58+ if (!$ this ->istoken ($ token )){
59+ return false ;
60+ }
5261 $ array = DB ::instance ()->table ('User_Pool ' )-> where ('token = ? ' , addslashes ($ token ))->first ();
5362 if (isset ($ array ->user )) {
63+ $ token_cache ->Set (true );
5464 return true ;
5565 } else {
5666 return false ;
5767 }
5868 }
59- public function get_userid ($ token ) {
69+ public function get_userid ($ token ) {//通过token获取用户id
6070 $ array = DB ::instance ()->table ('User_Pool ' )->where ('token = ? ' , $ token )->first ();
6171 return $ array ->id ;
6272 }
63- public function strsafe ($ str ) {
73+ public function strsafe ($ str ) {//使用正则判断字符串是否含有非法字符
6474 $ pattern = "#['!`~\/ \\\%^&*()+= \$\#:;<>\]\[{}]# " ;
6575 if (preg_match ($ pattern , $ str )) {
6676 return false ;
6777 } else {
6878 return true ;
6979 }
7080 }
71- public function istoken ($ str ) {
81+ public function istoken ($ str ) {//使用正则判断是否为token
7282 $ ereg = '/^[[:alnum:]]{25}$/ ' ;
7383 //$str='a!@#$%^';
7484 $ num = preg_match ($ ereg , $ str );
@@ -79,7 +89,7 @@ public function istoken($str) {
7989 return true ;
8090 }
8191 }
82- public function isdate ($ str ){
92+ public function isdate ($ str ){//使用正则判断是否为指定格式的日期
8393 $ ereg = '/^[0-9]{4}(-[0-9]{2}){2}.[0-9]{2}(:[0-9]{2}){2}$/ ' ;
8494 //$str='a!@#$%^';
8595 $ num = preg_match ($ ereg , $ str );
@@ -90,11 +100,11 @@ public function isdate($str){
90100 return true ;
91101 }
92102 }
93- /***100000 2000 3000
94- * 笔记id 笔记本id 标签id
95- *
96- * lastsysnctime = time()
97- ***/
103+
104+ /***
105+ * usn功能尚未开发
106+ ***/
107+
98108 public function isusn ($ usn ) {
99109 /***
100110 if (!isset($usn) or empty($usn)) {
@@ -208,49 +218,49 @@ public function tag_usn_update($id,$usn,$token){
208218 return $this->updateusn($new_usn,$token);
209219 ***/
210220 }
211- public function check_notebook_exist ($ title ,$ token ){
221+ public function check_notebook_exist ($ title ,$ token ){//通过笔记本名称判断笔记本是否存在
212222
213- $ userid = $ this ->get_userid ($ token );
223+ $ userid = $ this ->get_userid ($ token );//通过token过去用户id
214224 $ tb_name = 'User_ ' .$ userid .'_Notebooks ' ;
215- $ array = DB ::instance ()->table ($ tb_name )->where ('title = ? ' ,addslashes ($ title ))->first ();
216- if (isset ($ array ->title ) and isset ($ array ->uuid )){
225+ $ array = DB ::instance ()->table ($ tb_name )->where ('title = ? ' ,addslashes ($ title ))->first ();//查询用户笔记本数据表
226+ if (isset ($ array ->title ) and isset ($ array ->uuid )){//判断指定笔记本是否存在
217227 return true ;
218228 }
219229 return false ;
220230 }
221- public function check_notebookid_exist ($ id ,$ token ){
231+ public function check_notebookid_exist ($ id ,$ token ){//通过笔记本id判断笔记本是否存在
222232
223- if (!$ this ->istoken ($ id )){
233+ if (!$ this ->istoken ($ id )){//判断id是否非法
224234 return false ;
225235 }
226- $ userid = $ this ->get_userid ($ token );
236+ $ userid = $ this ->get_userid ($ token );//通过token获取用户id
227237 $ tb_name = 'User_ ' .$ userid .'_Notebooks ' ;
228- $ array = DB ::instance ()->table ($ tb_name )->where ('uuid = ? ' ,$ id )->first ();
229- if (isset ($ array ->title ) and isset ($ array ->uuid )){
238+ $ array = DB ::instance ()->table ($ tb_name )->where ('uuid = ? ' ,$ id )->first ();//查询用户笔记本数据表
239+ if (isset ($ array ->title ) and isset ($ array ->uuid )){//判断指定笔记本是否存在
230240 return true ;
231241 }
232242 return false ;
233243 }
234- public function check_noteid_exist ($ id ,$ token ){
244+ public function check_noteid_exist ($ id ,$ token ){//通过笔记id判断笔记本是否存在
235245
236- if (!$ this ->istoken ($ id )){
246+ if (!$ this ->istoken ($ id )){//判断id是否非法
237247 return false ;
238248 }
239- $ userid = $ this ->get_userid ($ token );
249+ $ userid = $ this ->get_userid ($ token );//通过token获取用户id
240250 $ tb_name = 'User_ ' .$ userid .'_Notes ' ;
241- $ array = DB ::instance ()->table ($ tb_name )->where ('uuid = ? ' ,$ id )->first ();
242- if (isset ($ array ->title ) and isset ($ array ->uuid )){
251+ $ array = DB ::instance ()->table ($ tb_name )->where ('uuid = ? ' ,$ id )->first ();//查询用户笔记数据表
252+ if (isset ($ array ->title ) and isset ($ array ->uuid )){//判断指定笔记是否存在
243253 return true ;
244254 }
245255 return false ;
246256 }
247- public function firstload (Context $ ctx ){
257+ public function firstload (Context $ ctx ){//笔记,笔记本,标签类统一初始化方法
248258 $ this ->ctx = $ ctx ;
249259
250- if (!$ this ->check_logined ($ this ->get_query ('token ' ))){
260+ if (!$ this ->check_logined ($ this ->get_query ('token ' ))){//判断是否登录
251261 $ this ->error ('token错误 ' );
252262 }
253263 $ token = $ this ->get_query ('token ' );
254- $ this ->token = $ token ;
264+ $ this ->token = $ token ;//传递局部变量
255265 }
256266}
0 commit comments