PHP_SMART_HOME_V3/app/api/UsersApi.php

48 lines
1.1 KiB
PHP
Raw Normal View History

2020-06-23 18:23:11 +00:00
<?php
class UsersApi extends ApiController{
public function default(){
//$this->requireAuth();
$response = null;
$users = UserManager::getUsers(["user_id", "username", "at_home"]);
foreach ($users as $key => $user) {
$response[] = [
"userName" => $user['username'],
2020-07-01 10:07:00 +00:00
"homeStatus" => ($user['at_home'] == 'true') ? true : false,
2020-06-23 18:23:11 +00:00
"avatarUrl" => UserManager::getAvatarUrl($user['user_id']),
];
}
$this->response($response);
}
2020-10-05 19:12:06 +00:00
public function status(){
//$this->requireAuth();
$response = null;
$obj = $this->input;
$atHome = $obj['atHome'];
$user = UserManager::getUser($obj['user']);
$userAtHome = $user['at_home'];
$userId = $user['user_id'];
if (!empty($user)) {
if($userAtHome != $atHome){
UserManager::atHome($userId, $atHome);
}
}
$this->response(['value'=>'OK']);
}
2021-01-04 16:08:56 +00:00
public function subscribe(){
//$this->requireAuth();
2021-01-05 19:27:49 +00:00
$bearer = $_SERVER['HTTP_AUTHORIZATION'];
$authManager = new AuthManager();
$userId = $authManager->getUserId($bearer);
2021-01-04 16:08:56 +00:00
2021-01-05 19:27:49 +00:00
NotificationManager::addSubscriber($userId, $this->input['pushtoken']);
2021-01-04 16:08:56 +00:00
$this->response(['value'=>'OK']);
}
2020-06-23 18:23:11 +00:00
}