Search in sources :

Example 1 with UserInvite

use of net.geoprism.account.UserInvite in project geoprism-registry by terraframe.

the class RegistryAccountUtil method initiateInTrans.

@Transaction
public static void initiateInTrans(String sInvite, String roleIds) {
    if (roleIds == null || roleIds.length() == 0 || JsonParser.parseString(roleIds).getAsJsonArray().size() == 0) {
        // TODO : Better Error
        throw new AttributeValueException("You're attempting to invite a user with zero roles?", "");
    }
    JSONObject joInvite = new JSONObject(sInvite);
    String email = joInvite.getString("email");
    UserInvite invite = new UserInvite();
    invite.setEmail(email);
    UserInviteQuery query = new UserInviteQuery(new QueryFactory());
    query.WHERE(query.getEmail().EQi(invite.getEmail()));
    OIterator<? extends UserInvite> it = query.getIterator();
    while (it.hasNext()) {
        it.next().delete();
    }
    invite.setStartTime(new Date());
    invite.setToken(generateEncryptedToken(invite.getEmail()));
    invite.setRoleIds(roleIds);
    invite.apply();
    RegistryAccountUtil.sendEmail(invite, roleIds);
}
Also used : UserInvite(net.geoprism.account.UserInvite) QueryFactory(com.runwaysdk.query.QueryFactory) JSONObject(org.json.JSONObject) UserInviteQuery(net.geoprism.account.UserInviteQuery) AttributeValueException(com.runwaysdk.dataaccess.attributes.AttributeValueException) Date(java.util.Date) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 2 with UserInvite

use of net.geoprism.account.UserInvite in project geoprism-registry by terraframe.

the class RegistryAccountUtil method inviteCompleteInTrans.

@Transaction
private static void inviteCompleteInTrans(java.lang.String token, String json) {
    UserInviteQuery query = new UserInviteQuery(new QueryFactory());
    query.WHERE(query.getToken().EQ(token));
    OIterator<? extends UserInvite> reqIt = query.getIterator();
    UserInvite invite;
    if (reqIt.hasNext()) {
        invite = reqIt.next();
        invite.appLock();
    } else {
        throw new InvalidUserInviteToken();
    }
    if ((System.currentTimeMillis() - invite.getStartTime().getTime()) > (GeoprismProperties.getInviteUserTokenExpireTime() * 3600000)) {
        throw new InvalidUserInviteToken();
    }
    JsonObject account = JsonParser.parseString(json).getAsJsonObject();
    if (invite.getRoleIds().length() > 0) {
        JsonArray array = JsonParser.parseString(invite.getRoleIds()).getAsJsonArray();
        List<String> list = new LinkedList<String>();
        for (int i = 0; i < array.size(); i++) {
            list.add(array.get(i).getAsString());
        }
        UserInfo.applyUserWithRoles(account, list.toArray(new String[list.size()]), true);
    } else {
        UserInfo.applyUserWithRoles(account, new String[] {}, true);
    }
    invite.delete();
    logger.info("User [" + account.get(GeoprismUser.USERNAME) + "] has been created via a user invite.");
}
Also used : UserInvite(net.geoprism.account.UserInvite) JsonArray(com.google.gson.JsonArray) QueryFactory(com.runwaysdk.query.QueryFactory) InvalidUserInviteToken(net.geoprism.account.InvalidUserInviteToken) UserInviteQuery(net.geoprism.account.UserInviteQuery) JsonObject(com.google.gson.JsonObject) LinkedList(java.util.LinkedList) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Aggregations

Transaction (com.runwaysdk.dataaccess.transaction.Transaction)2 QueryFactory (com.runwaysdk.query.QueryFactory)2 UserInvite (net.geoprism.account.UserInvite)2 UserInviteQuery (net.geoprism.account.UserInviteQuery)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 AttributeValueException (com.runwaysdk.dataaccess.attributes.AttributeValueException)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 InvalidUserInviteToken (net.geoprism.account.InvalidUserInviteToken)1 JSONObject (org.json.JSONObject)1