Subscribe
This commit is contained in:
parent
696ff07987
commit
1642ece7f4
@ -37,10 +37,11 @@ class UsersApi extends ApiController{
|
|||||||
|
|
||||||
public function subscribe(){
|
public function subscribe(){
|
||||||
//$this->requireAuth();
|
//$this->requireAuth();
|
||||||
|
$bearer = $_SERVER['HTTP_AUTHORIZATION'];
|
||||||
|
$authManager = new AuthManager();
|
||||||
|
$userId = $authManager->getUserId($bearer);
|
||||||
|
|
||||||
$subscriptionToken = $this->input['token'];
|
NotificationManager::addSubscriber($userId, $this->input['pushtoken']);
|
||||||
$subscriptionUserId = $this->input['user_id'];
|
|
||||||
NotificationManager::addSubscriber($subscriptionUserId, $subscriptionToken);
|
|
||||||
$this->response(['value'=>'OK']);
|
$this->response(['value'=>'OK']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,4 +61,10 @@ class AuthManager {
|
|||||||
};
|
};
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getUserId($bearer){
|
||||||
|
$token = explode(' ', $bearer)[1];
|
||||||
|
$userid = Db::loadOne('SELECT user_id FROM tokens WHERE token = ? AND expire >= CURRENT_TIMESTAMP AND blocked = 0;', array($token))['user_id'];
|
||||||
|
return $userid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user