only one account per fcm_token
This commit is contained in:
parent
faf5207478
commit
3f18fdd35a
@ -116,6 +116,8 @@ public class SCNApp extends Application implements LifecycleObserver
|
||||
|
||||
[X] - perhaps response codes in api (?)
|
||||
|
||||
[ ] - verify recieve
|
||||
|
||||
[ ] - test notification channels
|
||||
|
||||
[ ] - publish (+ HN post ?)
|
||||
|
@ -8,6 +8,7 @@ import android.view.View;
|
||||
|
||||
import com.android.billingclient.api.Purchase;
|
||||
import com.blackforestbytes.simplecloudnotifier.SCNApp;
|
||||
import com.blackforestbytes.simplecloudnotifier.lib.string.Str;
|
||||
import com.blackforestbytes.simplecloudnotifier.service.IABService;
|
||||
import com.google.firebase.iid.FirebaseInstanceId;
|
||||
|
||||
@ -195,10 +196,10 @@ public class SCNSettings
|
||||
if (isConnected())
|
||||
{
|
||||
ServerCommunication.info(user_id, user_key, loader);
|
||||
if (promode_server != promode_local)
|
||||
{
|
||||
updateProState(loader);
|
||||
}
|
||||
|
||||
if (promode_server != promode_local) updateProState(loader);
|
||||
|
||||
if (!Str.equals(fcm_token_local, fcm_token_server)) work(a);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -276,6 +276,7 @@ public class ServerCommunication
|
||||
SCNSettings.inst().quota_curr = json_int(json, "quota");
|
||||
SCNSettings.inst().quota_max = json_int(json, "quota_max");
|
||||
SCNSettings.inst().promode_server = json_bool(json, "is_pro");
|
||||
if (!json_bool(json, "fcm_token_set")) SCNSettings.inst().fcm_token_server = "";
|
||||
SCNSettings.inst().save();
|
||||
|
||||
SCNApp.refreshAccountTab();
|
||||
|
@ -100,6 +100,10 @@
|
||||
<td data-label="Statuscode">403 (Forbidden)</td>
|
||||
<td data-label="Explanation">The user has exceeded its daily quota - wait 24 hours or upgrade your account</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-label="Statuscode">412 (Precondition Failed)</td>
|
||||
<td data-label="Explanation">There is no device connected with this account - open the app and press the refresh button in the account tab</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-label="Statuscode">500 (Internal Server Error)</td>
|
||||
<td data-label="Explanation">There was an internal error while sending your data - try again later</td>
|
||||
|
15
web/info.php
15
web/info.php
@ -15,7 +15,7 @@ $user_key = $INPUT['user_key'];
|
||||
|
||||
$pdo = getDatabase();
|
||||
|
||||
$stmt = $pdo->prepare('SELECT user_id, user_key, quota_today, is_pro, quota_day FROM users WHERE user_id = :uid LIMIT 1');
|
||||
$stmt = $pdo->prepare('SELECT user_id, user_key, quota_today, is_pro, quota_day, fcm_token FROM users WHERE user_id = :uid LIMIT 1');
|
||||
$stmt->execute(['uid' => $user_id]);
|
||||
|
||||
$datas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
@ -33,11 +33,12 @@ if ($data['quota_day'] === null || $data['quota_day'] !== date("Y-m-d")) $quota=
|
||||
|
||||
echo json_encode(
|
||||
[
|
||||
'success' => true,
|
||||
'user_id' => $user_id,
|
||||
'quota' => $quota,
|
||||
'quota_max' => Statics::quota_max($is_pro),
|
||||
'is_pro' => $is_pro,
|
||||
'message' => 'ok'
|
||||
'success' => true,
|
||||
'user_id' => $user_id,
|
||||
'quota' => $quota,
|
||||
'quota_max' => Statics::quota_max($is_pro),
|
||||
'is_pro' => $is_pro,
|
||||
'fcm_token_set' => ($data['fcm_token'] != null),
|
||||
'message' => 'ok'
|
||||
]);
|
||||
return 0;
|
@ -54,6 +54,11 @@ try
|
||||
if ($data['quota_day'] === null || $data['quota_day'] !== date("Y-m-d")) $new_quota=1;
|
||||
if ($new_quota > Statics::quota_max($data['is_pro'])) api_return(403, json_encode(['success' => false, 'error' => 2101, 'errhighlight' => -1, 'message' => 'Daily quota reached ('.Statics::quota_max($data['is_pro']).')']));
|
||||
|
||||
if ($fcm == null || $fcm == '' || $fcm == false)
|
||||
{
|
||||
api_return(412, json_encode(['success' => false, 'error' => 1401, 'errhighlight' => -1, 'message' => 'No device linked with this account']));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
||||
if ($usrmsgid != null)
|
||||
|
@ -34,6 +34,8 @@ $new_userkey = generateRandomAuthKey();
|
||||
|
||||
if ($fcm_token === null)
|
||||
{
|
||||
// only gen new user_secret
|
||||
|
||||
$stmt = $pdo->prepare('UPDATE users SET timestamp_accessed=NOW(), user_key=:at WHERE user_id = :uid');
|
||||
$stmt->execute(['uid' => $user_id, 'at' => $new_userkey]);
|
||||
|
||||
@ -51,9 +53,14 @@ if ($fcm_token === null)
|
||||
}
|
||||
else
|
||||
{
|
||||
// update fcm and gen new user_secret
|
||||
|
||||
$stmt = $pdo->prepare('UPDATE users SET timestamp_accessed=NOW(), fcm_token=:ft, user_key=:at WHERE user_id = :uid');
|
||||
$stmt->execute(['uid' => $user_id, 'ft' => $fcm_token, 'at' => $new_userkey]);
|
||||
|
||||
$stmt = $pdo->prepare('UPDATE users SET fcm_token=NULL WHERE user_id <> :uid AND fcm_token=:ft');
|
||||
$stmt->execute(['uid' => $user_id, 'ft' => $fcm_token]);
|
||||
|
||||
echo json_encode(
|
||||
[
|
||||
'success' => true,
|
||||
|
Loading…
Reference in New Issue
Block a user