pp.setTags(null);
pp.setTitle(null);
//end set of fields i didn't use
//Step 4 Create the new auth object so user can login
AuthenticationPojo ap = new AuthenticationPojo();
ap.setId(profileId);
ap.setProfileId(profileId);
ap.setUsername(pp.getEmail());
ap.setAccountStatus(AccountStatus.ACTIVE);
if (null == wpa.getPassword()) { // Obligatory
rp.setResponse(new ResponseObject("WP Register User",false,"Need to specify password"));
return rp;
}
try
{
if (44 != wpa.getPassword().length()) { // hash if in the clear
wpa.setPassword(PasswordEncryption.encrypt(wpa.getPassword()));
}
ap.setPassword(wpa.getPassword());
if (null == wpa.getAccountType()) { // (optional, defaults to "user"
wpa.setAccountType("user");
}
ap.setAccountType(wpa.getAccountType());
// to create an account you must be admin, so this is fine....
ap.setWPUserID(wpa.getWPUserID());
DateFormat df = new SimpleDateFormat("MMM dd, yyyy kk:mm:ss aa");
//Handle copying dates from wordpress objects
// (These are all optional, just use now if not specified)
if (null == wpu.getCreated()) {
pp.setCreated(new Date());
}
else {
pp.setCreated(df.parse(wpu.getCreated()));
}
if (null == wpu.getModified()) {
pp.setModified(new Date());
}
else {
pp.setModified(df.parse(wpu.getModified()));
}
if (null == wpa.getCreated()) {
ap.setCreated(new Date());
}
else {
ap.setCreated(df.parse(wpa.getCreated()));
}
if (null == wpa.getModified()) {
ap.setModified(new Date());
}
else {
ap.setModified(df.parse(wpa.getModified()));
}
ap.setApiKey(wpa.getApiKey());
//Step 5 Save all of these objects to the DB
DbManager.getSocial().getPerson().insert(pp.toDb());
DbManager.getSocial().getAuthentication().insert(ap.toDb());
CommunityHandler cc = new CommunityHandler();
cc.createSelfCommunity(pp); //add user to own community
//try to get system
BasicDBObject commQueryDbo = new BasicDBObject("isSystemCommunity", true);
// (annoyingly can't use community pojo for queries because it has default fields)
DBObject dbo = DbManager.getSocial().getCommunity().findOne(commQueryDbo);
if (null != dbo) {
CommunityPojo systemGroup = CommunityPojo.fromDb(dbo, CommunityPojo.class);
//Add user to system community also
cc.addCommunityMember(cookieLookup, systemGroup.getId().toString(), "Infinit.e System", pp.get_id().toString(),
pp.getEmail(), pp.getDisplayName(), "member", "active", true);
}
rp.setResponse(new ResponseObject("WP Register User",true,"User Registered Successfully"));
rp.setData(ap, new AuthenticationPojoApiMap());
// OK we're all good, finally for API key users create a persistent cookie:
if (null != ap.getApiKey()) {
// (if we're here then we're already admin so can always do this - unlike the update)
CookiePojo cp = new CookiePojo();
cp.set_id(profileId);
cp.setCookieId(cp.get_id());
cp.setApiKey(wpa.getApiKey());
cp.setStartDate(ap.getCreated());
cp.setProfileId(profileId);
DbManager.getSocial().getCookies().save(cp.toDb());
}//TOTEST
}
catch (Exception ex )