only one account per fcm_token

This commit is contained in:
Mike Schwörer 2018-11-12 15:19:10 +01:00
parent faf5207478
commit 3f18fdd35a
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
7 changed files with 32 additions and 11 deletions

View File

@ -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 ?)

View File

@ -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
{

View File

@ -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();

View File

@ -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>

View File

@ -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;

View File

@ -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)

View File

@ -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,