CRecordUserDbCreateUser
Create a new user.
This message belongs to the Session Manager API.
The Session Manager is part of the NY_Session2PlugIn plugin.
{ "id": "546b4672-5612-4069-810d-8dbdfe8ffcb0", "name": "USER_DB_CREATE_USER ", "description": "Create a new user.", "slots": [ { "key": "1", "name": "USER_ID", "direction": "REQUEST", "mandatory": "true", "type": "STRING", "description": "The user id." }, { "key": "2", "name": "REAL_NAME", "direction": "REQUEST", "mandatory": "true", "type": "STRING", "description": "The user's real name." }, { "key": "3", "name": "EMAIL", "direction": "REQUEST", "mandatory": "true", "type": "STRING", "description": "The user's email address." }, { "key": "4", "name": "PICTURE", "direction": "REQUEST", "mandatory": "true", "type": "STRING", "description": "The user's picture." }, { "key": "5", "name": "PASSWORD", "direction": "REQUEST", "mandatory": "false", "type": "STRING", "description": "The password (SH384 hash, base64 encoded)." } ] }
Usage
Sending the request
You need the microservice ID of the session manager:
public static final IIdSESSION_MICROSERVICE_ID = CIdFactory.fromObject("ccf168c1-f18b-4229-85f9-24461a19ee6a");
The own SessionToken is needed to verify the authorization for the change.
You need the permission NY_CreateUser
.
In addition, the user ID, the users real name, the email address and a password hash (SHA384, base64 encoded) are
required.
You can use a utility method of the kernel: CUtilPassword.hashPassword().
private void createUser(final byte[] aToken, @NotNull final String aUserId, @NotNull final String aRealName, @NotNull final String aEmail, final char[] aPassword) throws CException { final String passwordHash = CUtilPassword.hashPassword(aPassword); final CEnvelope env = CEnvelope.forMicroService(SESSION_MICROSERVICE_ID ); env.setSessionToken(aToken); final CRecord record =CRecordUserDbCreateUser .create();CRecordUserDbCreateUser .setUserId(record, aUserId);CRecordUserDbCreateUser .setRealName(record, aRealName);CRecordUserDbCreateUser .setEmail(record, aEmail);CRecordUserDbCreateUser .setPassword(record, passwordHash); sendRequest(env, record); }
Dealing with the response
To catch the response of the request, we need a message handler. We add it in the constructor of the message handler registry.
// constructor: addMessageHandler(CRecordUserDbCreateUser .ID, this::asyncCreateUser );
private booleanasyncCreateUser (@NotNull final CEnvelope aEnvelope, @NotNull final CRecord aRecord) { if (aEnvelope.isAnswer()) { final int resultCode = aEnvelope.getResultCode(); if (resultCode == CResultCode.SUCCESS) { // ... } return true; } return false; }