Browse Source

Subscribe

3.0
GamerClassN7 1 year ago
parent
commit
1642ece7f4
2 changed files with 10 additions and 3 deletions
  1. +4
    -3
      app/api/UsersApi.php
  2. +6
    -0
      app/models/managers/AuthManager.php

+ 4
- 3
app/api/UsersApi.php View File

@ -37,10 +37,11 @@ class UsersApi extends ApiController{
public function subscribe(){
//$this->requireAuth();
$bearer = $_SERVER['HTTP_AUTHORIZATION'];
$authManager = new AuthManager();
$userId = $authManager->getUserId($bearer);
$subscriptionToken = $this->input['token'];
$subscriptionUserId = $this->input['user_id'];
NotificationManager::addSubscriber($subscriptionUserId, $subscriptionToken);
NotificationManager::addSubscriber($userId, $this->input['pushtoken']);
$this->response(['value'=>'OK']);
}
}

+ 6
- 0
app/models/managers/AuthManager.php View File

@ -61,4 +61,10 @@ class AuthManager {
};
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…
Cancel
Save