Users Examples
Insert a new user. A user must have enabled = true to activate them.
DataRecord record = new DataRecord(); record.setName("user"); record.setAction(DataRecord.INSERT); record.addField("firstName", "John"); record.addField("lastName", "Smith"); record.addField("username", "jsmith@concursive.com"); record.addField("password", PasswordHash.encrypt("password")); record.addField("groupId", GROUP_ID); record.addField("departmentId", "1"); record.addField("enabled", true); api.save(record); //Add Meta Info with fields required ArrayList<String> meta = new ArrayList<String>(); meta.add("id"); api.setTransactionMeta(meta);
Users can be disabled by updating them with enabled = false:
DataRecord record = new DataRecord(); record.setName("user"); record.setAction(DataRecord.UPDATE); record.addField("id", userId); record.addField("enabled", false); api.save(record);
A user can have an expiration date which prevents them from logging in:
// Use yesterday as the expiration date Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.DATE, -1); // Update the record DataRecord record = new DataRecord(); record.setName("user"); record.setAction(DataRecord.UPDATE); record.addField("id", userId); record.addField("expiration", cal.getTime()); api.save(record);
Enable a user:
/* Re-enable the user */ DataRecord record = new DataRecord(); record.setName("user"); record.setAction(DataRecord.UPDATE); record.addField("id", userId); record.addField("enabled", true); record.addField("expiration", DataRecord.NULL); api.save(record);
Sign in to add your comment.