How to complete duplication of user sessions using parsing?

I want my PFSessions to be exclusive, that is, if the user has already registered on a specific device in a certain place, if another device logs on with the same credentials, I want the previous session to be completed, a warning message, of course. It looks like the old AOL Instant Messaging format. so does anyone know how i will do it fast? will it require CoreLocation?

I found this article about the user's current location, how can I use this as part of the solution to my question?

https://www.veasoftware.com/tutorials/2014/10/18/xcode-6-tutorial-ios-8-current-location-in-swift

UPDATE

so I just read this parsing article about their feedback.

http://blog.parse.com/announcements/announcing-new-enhanced-sessions/

however, when I log in to the same account with another device, the sessions are allowed to live accordingly, which I don’t want. How to solve my dilemma?

UPDATE

I received a very detailed description of how to achieve a general method that I am trying to implement:

enter image description here

however, I am not very good at implementing cloud code, can someone very briefly depict a piece of code similar to what it is trying to pass to me?

UPDATE

So, I did some more research and talked about what I was told about how to use cloud code calls in parsing, and if I want to destroy previous currentUser sessions, I wrote the following code in my login β€œsuccess”:

PFUser.logInWithUsernameInBackground(userName, password: passWord) { (user, error: NSError?) -> Void in if user != nil || error == nil { dispatch_async(dispatch_get_main_queue()) { self.performSegueWithIdentifier("loginSuccess", sender: self) PFCloud.callFunctionInBackground("currentUser", withParameters: ["PFUser":"currentUser"]) //..... Get other currentUser session tokens and destroy them } } else { 

If it's even the right format or code, but I'm sure this is the right direction? Can anyone change or extend the code I'm trying to achieve?

+7
ios xcode swift
source share
1 answer

You should start by looking for a quick launch of the cloud code.
Then you define the following cloud code function:

 Parse.Cloud.define('destroyUserSessions', function(req, res) { //the user that sends the request var currentUser = req.user; //send from client var currentUserInstallationId = req.param.installationId; var Session = Parse.Object.extend('Session'); var userSessionQuery = new Parse.Query(Session); //all sessions of this user userSessionQuery.equalTo('user', currentUser); //except the session for this installation -> to not log the request performing user out userSessionQuery.notEqualTo('installationId', currentUserInstallationId); userSessionQuery.find({ success: function(userSessionsToBeRevoked) { Parse.Object.destroyAll(userSessionsToBeRevoked, { success: function() { //you have deleted all sessions except the one for the current installation var installationIds = userSessionsToBeRevoked.map(function(session) { return session.installationId; }); //you can use the installation Ids to send push notifications to installations that are now logged out }, error: function(err) { //TODO: Handle error } }); }, error: function(err) { //TODO: Handle error } }); }); 

NOTE. This code has not been tested and contains several assumptions, for example, that you have enabled authorized sessions, and there the user is logged in when executing the request

You would call the function as follows:

 let installationId = PFInstallation.currentInstallation().installationId PFCloud.callFunctionInBackground("destroyUserSessions", withParameters: ["installationId": installationId]) { success, error in //TODO: Handle success or errors } 

Hope this helps you get started.

0
source share

All Articles