diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/SCNApp.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/SCNApp.java
index a7726fe..a655762 100644
--- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/SCNApp.java
+++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/SCNApp.java
@@ -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 ?)
diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java
index a38569a..ff29a44 100644
--- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java
+++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java
@@ -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
{
diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/ServerCommunication.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/ServerCommunication.java
index bb581e4..3d51ccf 100644
--- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/ServerCommunication.java
+++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/ServerCommunication.java
@@ -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();
diff --git a/web/index_more.php b/web/index_more.php
index 95a8fc3..2bc7e02 100644
--- a/web/index_more.php
+++ b/web/index_more.php
@@ -100,6 +100,10 @@
403 (Forbidden) |
The user has exceeded its daily quota - wait 24 hours or upgrade your account |
+
+ 412 (Precondition Failed) |
+ There is no device connected with this account - open the app and press the refresh button in the account tab |
+
500 (Internal Server Error) |
There was an internal error while sending your data - try again later |
diff --git a/web/info.php b/web/info.php
index 471e7cb..0a2c64e 100644
--- a/web/info.php
+++ b/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;
\ No newline at end of file
diff --git a/web/send.php b/web/send.php
index f698a51..f5be965 100644
--- a/web/send.php
+++ b/web/send.php
@@ -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)
diff --git a/web/update.php b/web/update.php
index f643d21..edd6205 100644
--- a/web/update.php
+++ b/web/update.php
@@ -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,