diff --git a/src/main/java/quanta/mongo/MongoAuth.java b/src/main/java/quanta/mongo/MongoAuth.java index b3cc926f6..576bf6dca 100644 --- a/src/main/java/quanta/mongo/MongoAuth.java +++ b/src/main/java/quanta/mongo/MongoAuth.java @@ -94,7 +94,7 @@ public List getUsersSharedTo(SubNode node) { name = PrincipalName.PUBLIC.s(); } // else if (userNodeId != null) { - SubNode accountNode = svc_mongoRead.getNode(userNodeId); + AccountNode accountNode = svc_user.getAccountNode(userNodeId); if (accountNode != null) { name = accountNode.getStr(NodeProp.USER); } @@ -420,7 +420,7 @@ public boolean nodeAuth(SubNode node, String sessionUserNodeId, List getUserNodeByProp(propName, propVal, caseSensitive)); - } - - public SubNode getUserNodeByProp(String propName, String propVal, boolean caseSensitive) { - if (StringUtils.isEmpty(propVal)) - return null; - // Otherwise for ordinary users root is based off their username - Query q = new Query(); - Criteria crit; - if (caseSensitive) { - crit = svc_mongoUtil.childrenCriteria(NodePath.USERS_PATH).and(SubNode.PROPS + "." + propName).is(propVal); - } else { - crit = svc_mongoUtil.childrenCriteria(NodePath.USERS_PATH).and(SubNode.PROPS + "." + propName) - .regex("^" + Pattern.quote(propVal) + "$", "i"); - } - - crit = svc_auth.addReadSecurity(crit); - q.addCriteria(crit); - return svc_ops.findOne(q); - } - /* * Finds and returns the first node matching userName and type as direct child of 'node', or null if * not existing. Caller can pass userNode if its available, or else userName will be used to look it diff --git a/src/main/java/quanta/service/EmailService.java b/src/main/java/quanta/service/EmailService.java index 523e6d0b2..5059c6aa7 100644 --- a/src/main/java/quanta/service/EmailService.java +++ b/src/main/java/quanta/service/EmailService.java @@ -18,6 +18,7 @@ import quanta.model.client.NodeProp; import quanta.model.client.NodeType; import quanta.mongo.MongoRepository; +import quanta.mongo.model.AccountNode; import quanta.mongo.model.SubNode; import quanta.util.LimitedInputStream; import quanta.util.TL; @@ -206,9 +207,9 @@ public String convertEmailToMarkdown(LimitedInputStream is) { /** * Sends an email notification to the user associated with 'toUserNode' (a person's account root * node), telling them that 'fromUserName' has shared a node with them, and including a link to the - * shared node in the email. + * shared node in the email. (Not currently usee) */ - public void sendEmailNotification(String fromUserName, SubNode toUserNode, SubNode node) { + public void sendEmailNotification(String fromUserName, AccountNode toUserNode, SubNode node) { String email = toUserNode.getStr(NodeProp.EMAIL); String toUserName = toUserNode.getStr(NodeProp.USER); String nodeUrl = svc_snUtil.getFriendlyNodeUrl(node); diff --git a/src/main/java/quanta/service/UserManagerService.java b/src/main/java/quanta/service/UserManagerService.java index 29934aee1..2a1c6e330 100644 --- a/src/main/java/quanta/service/UserManagerService.java +++ b/src/main/java/quanta/service/UserManagerService.java @@ -13,6 +13,7 @@ import java.util.Random; import java.util.StringTokenizer; import java.util.concurrent.ConcurrentHashMap; +import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; import org.bson.types.ObjectId; import org.slf4j.Logger; @@ -423,7 +424,7 @@ public SignupResponse signup(SignupRequest req, boolean automated) { // we disallow dupliate emails via this codepath, but by design we do allow them in the DB, and // even all the 'test accounts' will normally have the same email address. - SubNode ownerNode = svc_mongoRead.getUserNodeByPropAP(NodeProp.EMAIL.s(), email, false); + AccountNode ownerNode = svc_user.getUserNodeByPropAP(NodeProp.EMAIL.s(), email, false); if (ownerNode != null) { res.setEmailError("Email already in use."); res.setCode(HttpServletResponse.SC_EXPECTATION_FAILED); @@ -540,7 +541,7 @@ public AddCreditResponse addCredit(String userId, BigDecimal amount) { public Tran addCreditByEmail(String emailAdr, BigDecimal amount, Long timestamp) { PgTranMgr.ensureTran(); - SubNode ownerNode = svc_mongoRead.getUserNodeByPropAP(NodeProp.EMAIL.s(), emailAdr, false); + AccountNode ownerNode = svc_user.getUserNodeByPropAP(NodeProp.EMAIL.s(), emailAdr, false); if (ownerNode != null) { String userName = ownerNode.getStr(NodeProp.USER); Tran tran = addCreditInternal(ownerNode.getIdStr(), amount, timestamp); @@ -1247,6 +1248,28 @@ public SendFeedbackResponse cm_sendFeedback(SendFeedbackRequest req) { }); } + public AccountNode getUserNodeByPropAP(String propName, String propVal, boolean caseSensitive) { + return svc_arun.run(() -> getUserNodeByProp(propName, propVal, caseSensitive)); + } + + public AccountNode getUserNodeByProp(String propName, String propVal, boolean caseSensitive) { + if (StringUtils.isEmpty(propVal)) + return null; + // Otherwise for ordinary users root is based off their username + Query q = new Query(); + Criteria crit; + if (caseSensitive) { + crit = svc_mongoUtil.childrenCriteria(NodePath.USERS_PATH).and(SubNode.PROPS + "." + propName).is(propVal); + } else { + crit = svc_mongoUtil.childrenCriteria(NodePath.USERS_PATH).and(SubNode.PROPS + "." + propName) + .regex("^" + Pattern.quote(propVal) + "$", "i"); + } + + crit = svc_auth.addReadSecurity(crit); + q.addCriteria(crit); + return svc_ops.findOne(q, AccountNode.class); + } + public AccountNode getAccountNode(String id) { return svc_ops.findById(new ObjectId(id), AccountNode.class); }