Basics Module
Standard module which is added to every app automatically. It contains the user class, which is a representation for a user of your app.
Configuration
|
configuration key |
description |
|
Users can see each other |
TRUE if all user of an application can see a list of other user (e.g. to send messages to them) or FALSE if not. |
|
Role necessary for creating new Users |
Role name which is needed to create a new user. Possible values are Guest, User, and AppAdmin. Guest is default. |
Usage
Every user of your app should be represented by a corresponding User object. Using this is not only a nice and easy way to store and view your user without creating a own class, but is also necessary for authorization. Most requests on the server (especially those which require the client to be the owner) need the credentials of a valid user to make authorization work. So the first initial step in your app will be the creation and authentication of your user:
// Create your userfinal User user = new User();user.setUserName("johnDoe");user.setPassword("123456");// Configure the Datastore, a static class doing all the network stuff,// before doing the first requestDatastore.configureWithCredentials(user);// Now check if the user already exists and in case he doesn't: create the useruser.loadMeAsync(new AOMEmptyCallback() { @Override public void isDone(boolean wasLoadedFromStorage, ApiomatRequestException exception) { if (exception != null) { // if the member is not found on the server just create it user.saveAsync(new AOMEmptyCallback() { @Override public void isDone(boolean wasLoadedFromStorage, ApiomatRequestException exception) { // ... } }); } }});// Create your userAOMUser *u = [[AOMUser alloc] init];[u setUserName:@"johnDoe" ];[u setPassword:@"123456" ];// Configure the Datastore,// a static class doing all the network stuff,// before doing the first request[AOMDatastore configureWithUser:u];// now you can try to load the users data from the server[u loadMeAsyncWithFinishingBlock:^(NSError *error) { // if the user exists, we should now have a valid href if([u getHref] == NULL || error) { // if not, let us create the user initally [u saveAsyncWithBlock:^(NSError *error) { }]; }}];// Create your uservar u = User()u.userName = "johnDoe"u.password = "123456"// Configure the Datastore,// a static class doing all the network stuff,// before doing the first requestDataStore.configureWithCredentials(user)// now you can try to load the users data from the serveru.loadMe { (error) in // if the user exists, we should now have a valid href if u.href == nil || error { // if not, let us create the user initally u.save { (error) in } }}// Create a new member/user of your appvar myUser = new Apiomat.User(); myUser.setUserName("johnDoe");myUser.setPassword("1,618");// configure datastore with user credentialsApiomat.Datastore.configureWithCredentials(myUser);var saveCB = { onOk : function() { console.log("saved"); //Now you can create objects of your class with this new user.. }, onError : function(error) { console.log("Some error occured: (" + error.statusCode + ")" + error.message); }};// Try to load user or create new one if not existsmyUser.loadMe({ onOk : function() { //Now you can do sth with loaded object }, onError : function(error) { // and save it myUser.save(saveCB); }});// Create a new member/user of your appconst myUser = User();myUser.userName = "johnDoe";myuser.password = "1,618";Datastore.configureAsUser(myUser);// Try to load user or create new one if not existstry { await myUser.loadMe();} catch(e) { await myUser.save();}
As you have seen, the Datastore plays an important role: All requests are done using it. But that’s only FYI, all calls are encapsulated in SDK generated methods. Usually you should operate only with your generated classes.