Skip to content

Commit

Permalink
api token bug
Browse files Browse the repository at this point in the history
  • Loading branch information
star7th committed Feb 19, 2022
1 parent 5d3ec69 commit 86d58a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
6 changes: 3 additions & 3 deletions server/Application/Api/Controller/ItemController.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,10 @@ public function resetKey(){
return ;
}

$ret = D("ItemToken")->where("item_id = '$item_id' ")->delete();
$item_token = D("ItemToken")->resetToken($item_id);

if ($ret) {
$this->getKey();
if ($item_token) {
$this->sendResult($item_token);
}else{
$this->sendError(10101);
}
Expand Down
19 changes: 17 additions & 2 deletions server/Application/Api/Model/ItemTokenModel.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
class ItemTokenModel extends BaseModel {

public function createToken($item_id){
$api_key = md5(md5($item_id.microtime().rand()."showdoc")."srffsrfgr".rand()).rand();
$api_token = md5(md5($item_id.microtime().rand()."showdoc")."rgrhbtgd34".rand()).rand();
$api_key = get_rand_str().rand();
$api_token = get_rand_str().rand();
$data['item_id'] = $item_id ;
$data['api_key'] = $api_key ;
$data['api_token'] = $api_token ;
Expand Down Expand Up @@ -53,5 +53,20 @@ public function check($api_key , $api_token, $no = ''){
}
}

public function resetToken($item_id){
$item_id = intval($item_id) ;
$item_token = $this->where("item_id='$item_id'")->find();
if (!$item_token) {
$this->createToken($item_id);
sleep(1);
$item_token = $this->where("item_id='$item_id'")->find();
}
$item_token['api_token'] = get_rand_str().rand();
$this->where("item_id='$item_id'")->save(array(
"api_token"=> $item_token['api_token']
));
return $item_token ;
}


}

0 comments on commit 86d58a2

Please sign in to comment.