How to prevent user log in from two devices - mysql

I am developing mobile application in ionic 2. I want to design mechanism when user log in my website i must log out from my mobile application at the same time if user logged in mobile application then website must be log out. I am using same database for mobile and website. I am using jsonwebtoken for my mobile authentication. what is the best way to implement this mechanism in my ionic 2 application.

you will need to create a session table that will store the session details and will also store the unique ID and status that will be used to identify these sessions and tell us weather it is active or not. This id will be used as a reference to validate session for different devices, once the user logs in you will query into this table and check whether any existing session is there or not. If it is there change the status to false.
In the UI you will use setinterval to request for this session at regular time it can be 10 seconds or anything based on your requirement then inside setinterval make a call to backend that will be checking this session, if this session status is false then logout.

Related

AngularJS + Ionic: Checking if new Entry in Database, if yes: Push notification

I am working on an application with ionic and angularjs. I would like, that the app checks automatically in the background, if new database entries are available. If yes, it should send a notification. My question: How can I check in the background continiously, if there is an database update?
And Question #2: If there is no entry in the database, it should throw you out of the actual page.
Background: I am working on an live-survey app for events, with which you can interact with the show on the stage. If a question is activated for the people, you should get a notification.
1 - for continuously checks you should use cron job from your server side and based on it you can send your notifications
2- if there is no entries you can send push notification with any flag in its payload and check on it in the mobile app then execute the desired behavior.

How to send back data to a server in a PWA website

I've searched and I can only find tutorials to pull info from a server to update the latest info of my PWA app using JSON. But I can't find any way and any example to fetch data back to a server to mantain for instance a Database updated and display that to all users which may use that PWA.
For example, I have a PWA that let me login (client-server communication), then it displays a list of contacts that were stored in a Database. I can delete, modify or add new users to this list from my PWA app, and after doing that, they'll update on my server Database, so if my friend Paul, wants to check the updated list from his account, he'll see the new changes.
How Can I do that? Which language would I have to use, php and Javascript (Ajax)? Which is the most fluid and optimized way to do it according to a Progressive Web App.
I guess you are trying to store user changes back to the server(webservice and then to the data base).
You have to make an AJAX call to your web service and pass the required data needed to store in DB.
Here is an example.
https://www.w3schools.com/xml/xml_http.asp
Depending on the framework you are using, you might have more options to call a web service. Like here is an example for Angular -> https://www.w3schools.com/angular/angular_http.asp

ejabberd behavior b/w user disconnected vs user unavailable

What is the ejabbered behavior for user who is un-expectedly disconnected from internet
vs
user who explicitly sent an 'unavailable' presence?
Would they both be considered offline (for both single user chat or MUC)?
I want a behavior where if a user is disconnected from internet, offline messages to be sent
If user sent a explicit unavailble presence, I dont want offline messages to be sent.
How can that be accomplished? I can write my hook. But I need to know in which situations, the hook will be called.
When the user gets offline, the default behaviour is the same, no matter which method is used (explicit session close or unvoluntary disconnect). This is per XMPP specification.
If you want to customise the behaviour, it will not be easy as there is no way to know the reason why a user if offline.
What I would do: I would use the last module and support an optional reason for disconnect and store it. When you disconnect unvoluntarily, I would modify code to store reason being something like "timeout". When you disconnect explicitely, I would store another flag. When you get an offline message, you can then check the reason from being offline coming from mod_last storage.

ios/Android targeted push notifications in AIR app

I was wondering if it is possible to have multiple custom push notifications setup in a single AIR App.
What I am trying to do is allow users to setup custom alerts based on information they would like to receive for example say user 1 would like to know when new actions or drama movies are released on DVD, user 2 would like to know when new comedies are released, user 3 would like to know when any new movie is released.
This is a simple example and there are possibly 1000's of options (postcode/zip information).
Thanks
Technically, there's nothing that wouldn't allow you to do this.
The implementation is mostly backend related though, let me just quickly draft a design for that here;
The user's device registers for push notifications at your backend service.
Your service takes the user's id stores in a DB and passes the device token to the corresponding push notification server.
Once the registration is completed, the user selects what items he'd like to get notified of (naturally your backend service has to know this information as well to store it in the DB).
As soon as a new action movie (or whatever kind of information the user registered for) is available, your service looks in the DB what users registered for that kind of movies and sends a message via push.
So a simple database and some server side scripting will get you going.

oauth for html5 enabled devices

I'm building a webapp specifically for iOS and Android devices which requires user to sign in with their Facebook or Twitter accounts. I have it setup so that initially they're redirected to the appropriate login page and upon successful completion my provided calllback url is triggered.
Because I want to implement a single sign on, I will be storing on the user's device the access token that I received so they can easily access the webapp without having to sign in again next time.
My question is this: is it better to store it as an html4 cookie from the server side? Or is it better to insert it as a hidden input in the home page and have javascript on the client grab it and store it with the new local/sessionStorage? And if the latter, which type of storage would be better for this type of data that I would like to save?