add api for all users
This commit is contained in:
parent
92adb669d5
commit
d987c7db7b
|
@ -73,6 +73,13 @@ public:
|
|||
MethodMap<T> const static_methods = {
|
||||
{"createUser", wrap<create_user>}
|
||||
};
|
||||
|
||||
static void all_users(ContextType ctx, ObjectType object, ReturnValue &return_value);
|
||||
|
||||
PropertyMap<T> const static_properties = {
|
||||
{"all", {wrap<all_users>, nullptr}},
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
@ -109,6 +116,15 @@ void UserClass<T>::create_user(ContextType ctx, ObjectType this_object, size_t a
|
|||
return_value.set(create_object<T, UserClass<T>>(ctx, user));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void UserClass<T>::all_users(ContextType ctx, ObjectType object, ReturnValue &return_value) {
|
||||
std::vector<ValueType> user_vector;
|
||||
for (auto user : SyncManager::shared().all_users()) {
|
||||
user_vector.push_back(create_object<T, UserClass<T>>(ctx, new SharedUser(user)));
|
||||
}
|
||||
return_value.set(Object::create_array(ctx, user_vector));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class SyncClass : public ClassDefinition<T, void *> {
|
||||
using GlobalContextType = typename T::GlobalContext;
|
||||
|
|
32
test.js
32
test.js
|
@ -23,19 +23,12 @@ const prompt = require('prompt');
|
|||
const mkdirp = require('mkdirp');
|
||||
const wildcard = require('wildcard');
|
||||
|
||||
// User.loginWithProvider('http://127.0.0.1:8080/', 'debug', 'abcd', function(error, user) {
|
||||
// console.log(user);
|
||||
// });
|
||||
|
||||
Realm.Sync.User.create('http://127.0.0.1:9080/', 'ari', 'aaa', function(error, user) {
|
||||
|
||||
var notifier_dir = './notifier';
|
||||
mkdirp.sync(notifier_dir);
|
||||
|
||||
var access_token = 'ewoJImlkZW50aXR5IjogImFkbWluIiwKCSJhY2Nlc3MiOiBbInVwbG9hZCIsICJkb3dubG9hZCIsICJtYW5hZ2UiXQp9Cg==:DlFksxA+cJyEOc9bu6JwBUfDi4fJCagjAcIPPsoisjqfmOzSrk5Omuw0IkxCRU534p2+CAAj5IOH47DfObPtAA8q2DHguYDOKWYxyktS/6doPCqDHYN7k9EgUHdPTkESNkuPZbaVfXZTGzocB8m7+MaEXJde7FGPbh1sBz/+sPldnlAhnOqO5QbWzIEyoGHiOSg3V7UCh2H8kalr3tef7fkE2X65OBMgcarPvM5M6sPijOx2N5zrVrjL2wvguP9zS+g2ybFPUqV3DGv3S8cnGA+wVId/jCfGc2ujNhecunJdENH+/pL+0BTYHCFEWkY1WP1NUyti60FwRaXAtcYxeA==';
|
||||
var admin_user = new Realm.Sync.User.adminUser('http://127.0.0.1:9080/', access_token);
|
||||
|
||||
Realm.Sync.setLogLevel('error');
|
||||
// var admin_user = new Realm.Sync.User.adminUser('http://127.0.0.1:9080/', access_token);
|
||||
// Realm.Sync.setLogLevel('error');
|
||||
// Realm.Sync.setGlobalListener(notifier_dir, 'realm://127.0.0.1:9080', admin_user,
|
||||
// (name) => {
|
||||
// console.log('filter: ' + name);
|
||||
|
@ -48,7 +41,11 @@ Realm.Sync.setLogLevel('error');
|
|||
// );
|
||||
// console.log('global notifier listening...');
|
||||
|
||||
Realm.Sync.User.login('http://127.0.0.1:9080/', 'ari', 'aaa', function(error, user) {
|
||||
function createObjects(error, user) {
|
||||
console.log(user.server);
|
||||
console.log(user.token);
|
||||
console.log(user.identity);
|
||||
|
||||
var realm = new Realm({
|
||||
sync: {
|
||||
user: user,
|
||||
|
@ -77,7 +74,16 @@ Realm.Sync.User.login('http://127.0.0.1:9080/', 'ari', 'aaa', function(error, us
|
|||
}
|
||||
prompt.start();
|
||||
prompt.get(['int'], create);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
console.log(Realm.Sync.User.all);
|
||||
if (Realm.Sync.User.all.length) {
|
||||
console.log('Using persisted user');
|
||||
createObjects(undefined, Realm.Sync.User.all[0]);
|
||||
//Realm.Sync.User.login('http://127.0.0.1:9080/', 'ari', 'aaa', createObjects);
|
||||
}
|
||||
else {
|
||||
console.log('Logging in');
|
||||
Realm.Sync.User.login('http://127.0.0.1:9080/', 'ari', 'aaa', createObjects);
|
||||
//Realm.Sync.User.create('http://127.0.0.1:9080/', 'ari', 'aaa', createObjects);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue