简体   繁体   中英

How to store the data in local device using JSONStore in worklight?

I'm doing Login Page in worklight using JavaScript and jquery, the username and password should validate the data getting from JSONstore?

How to store the data locally using JSONStore in worklight and how does i get the data from JSONStore while validating the username and password?

In below code where my data will store and get, if the username and password has typed where it validate:

var collections = {
          people : {
            searchFields : {name: 'string'}
          },
          orders : {
            searchFields: {name: 'string'}
          }
        };
            WL.JSONStore.init(collections)
            .then(function () {
          return WL.JSONStore.init(collections);
        })
            .then(function () {
          return WL.JSONStore.init(collections);
        })

        .then(function () {
            alert('Multiple inits worked');
        })
            .fail(function (err) {
         lert('Multiple inits failed' + err.toString());
        }); 

How to solve the issue?

You really should never ever store username and password locally in the device. That does not sound very secure...

Additionally, where is the username and password coming from? How should the logic be able to validate the credentials? It needs to compare whatever is inputted with something, to know that it is correct. An implementation cannot be done without otherwise, so you need to provide the answer to this...

In the meanwhile, you can take a look at the following tutorial: Offline Authentication .

The included sample application assumes you have first authenticated with a backend system, and later allows for authenticating locally, "offline", in case an Internet connection is not available. For this it uses JSONStore to securely authenticate.

The tutorial include a thorough implementation example, be sure to follow it, and to provide the missing information in your question.

This tutorial explains how to use the JSONStore API, including the Add method: https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-1/foundation/data/jsonstore/jsonstore-javascript-api/

var collectionName = 'people';
var options = {};

var data = {name: 'yoel', age: 23};

WL.JSONStore.get(collectionName).add(data, options).then(function () {
 // handle success
}).fail(function (error) {
 // handle failure
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM