Beispiel #1
0
        private string getUserId(string address)
        {
            var findStr = new JObject {
                { "address", address }
            }.ToString();
            var fieldStr = new JObject {
                { "userId", 1 }
            }.ToString();
            var queryRes = mh.GetData(dao_mongodbConnStr, dao_mongodbDatabase, userInfoCol, findStr, fieldStr);

            if (queryRes.Count == 0)
            {
                return("");
            }
            //
            var item     = queryRes[0];
            var updateJo = new JObject {
                { "nonceState", StateValidityOp.Not },
                { "lastUpdateTime", TimeHelper.GetTimeStamp() }
            };
            var userId = item["userId"].ToString();

            if (userId == "")
            {
                userId = DaoInfoHelper.genUserId(address, address, address);
                updateJo.Add("userId", userId);
            }
            var updateStr = new JObject {
                { "$set", updateJo }
            }.ToString();

            mh.UpdateData(dao_mongodbConnStr, dao_mongodbDatabase, userInfoCol, updateStr, findStr);
            return(userId);
        }
Beispiel #2
0
 private string getFileUrl(string filename)
 {
     using (var sr = new StreamReader(filename))
     {
         return(DaoInfoHelper.StoreFile(oss, bucketName, filename, sr.BaseStream));
     }
 }
Beispiel #3
0
        ///
        /// v3
        ///
        public JArray getLoginNonce(string address)
        {
            address = address.ToLower();
            if (address == "")
            {
                return(getErrorRes(DaoReturnCode.C_InvalidUserInfo));
            }
            var nonceStr = "";
            var now = TimeHelper.GetTimeStamp();
            var findStr = new JObject {
                { "address", address }
            }.ToString();
            var queryRes = mh.GetData(dao_mongodbConnStr, dao_mongodbDatabase, userInfoCol, findStr);

            if (queryRes.Count == 0)
            {
                nonceStr = DaoInfoHelper.genUserId(address, address, address);
                var newdata = new JObject {
                    { "userId", "" },
                    { "username", "" },
                    { "address", address },
                    { "headIconUrl", "" },
                    { "nonceStr", nonceStr },
                    { "nonceState", StateValidityOp.Yes },
                    { "time", now },
                    { "lastUpdateTime", now },
                }.ToString();
                mh.PutData(dao_mongodbConnStr, dao_mongodbDatabase, userInfoCol, newdata);
            }
            else
            {
                var item = queryRes[0];
                if (long.Parse(item["lastUpdateTime"].ToString()) + 30 /* 30s内同一地址不能重复申请*/ > now)
                {
                    return(getErrorRes(DaoReturnCode.RepeatOperate));
                }
                nonceStr = DaoInfoHelper.genUserId(address, address, address);
                var updateStr = new JObject {
                    { "$set", new JObject {
                          { "nonceStr", nonceStr },
                          { "nonceState", StateValidityOp.Yes },
                          { "lastUpdateTime", now },
                      } }
                }.ToString();
                mh.UpdateData(dao_mongodbConnStr, dao_mongodbDatabase, userInfoCol, updateStr, findStr);
            }
            return(getRes(new JObject {
                { "nonceStr", nonceStr }
            }));
        }
Beispiel #4
0
        //
        public JArray addUpdateDiscuss(string userId, string accessToken, string projId, string updateId, string preDiscussId, string discussContent)
        {
            if (!checkLen(discussContent))
            {
                return(getErrorRes(DaoReturnCode.lenExceedingThreshold));
            }
            if (!checkSupport(projId, userId))
            {
                return(getErrorRes(DaoReturnCode.S_NoPermissionAddDiscuss));
            }

            //
            string code;

            if (!checkToken(userId, accessToken, out code))
            {
                return(getErrorRes(code));
            }
            //
            if (!checkUserId(userId, out code))
            {
                return(getErrorRes(code));
            }
            if (!checkUpdatePreDiscussId(projId, updateId, preDiscussId, out code))
            {
                return(getErrorRes(code));
            }

            string discussId  = DaoInfoHelper.genProjUpdateDiscussId(updateId, preDiscussId, discussContent, userId);
            string childrenId = getChildrenId(preDiscussId, discussId, true);
            var    now        = TimeHelper.GetTimeStamp();
            var    newdata    = new JObject {
                { "projId", projId },
                { "updateId", updateId },
                { "preDiscussId", preDiscussId },
                { "discussId", discussId },
                { "discussContent", discussContent },
                { "userId", userId },
                { "zanCount", 0 },
                { "childrenId", childrenId },
                { "time", now },
                { "lastUpdateTime", now },
            }.ToString();

            mh.PutData(dao_mongodbConnStr, dao_mongodbDatabase, projUpdateDiscussInfoCol, newdata);
            return(getRes(new JObject {
                { "discussId", discussId }
            }));
        }
Beispiel #5
0
        //a.
        //b.send.register
        //c.
        public JArray register(string username, string email, string password)
        {
            var checkRes = checkUsername(username);

            if (!checkResCode(checkRes))
            {
                return(checkRes);
            }
            checkRes = checkEmail(email);
            if (!checkResCode(checkRes))
            {
                return(checkRes);
            }

            if (!checkPasswordLen(password))
            {
                return(getErrorRes(DaoReturnCode.invalidPasswordLen));
            }
            //
            var pswd    = toPasswordHash(password);
            var time    = TimeHelper.GetTimeStamp();
            var userId  = DaoInfoHelper.genUserId(username, email, pswd);
            var newdata = new JObject {
                { "userId", userId },
                { "username", username },
                { "password", pswd },
                { "email", email },
                { "emailVerifyCode", "" },
                { "emailVerifyState", EmailState.sendBeforeState },
                { "headIconUrl", "" },
                { "brief", "" },
                { "time", time },
                { "lastUpdateTime", time },
                { "ethAddress", "" },
                { "neoAddress", "" },
            }.ToString();

            mh.PutData(dao_mongodbConnStr, dao_mongodbDatabase, userInfoCol, newdata);

            return(getRes());
        }
Beispiel #6
0
        public JArray modifyUserIcon(string userId, string accessToken, string headIconUrl)
        {
            if (!TokenHelper.checkAccessToken(tokenUrl, userId, accessToken, out string code))
            {
                return(getErrorRes(code));
            }
            string findStr = new JObject {
                { "userId", userId }
            }.ToString();
            string fieldStr = new JObject {
                { "username", 1 }, { "password", 1 }, { "headIconUrl", 1 }
            }.ToString();
            var queryRes = mh.GetData(dao_mongodbConnStr, dao_mongodbDatabase, userInfoCol, findStr, fieldStr);

            if (queryRes.Count == 0)
            {
                return(getErrorRes(DaoReturnCode.notFindUserInfo));
            }

            //
            string oldHeadIconUrl = queryRes[0]["headIconUrl"].ToString();

            if (!DaoInfoHelper.StoreFile(oss, bucketName, oldHeadIconUrl, headIconUrl, out string newHeadIconUrl))
            {
                return(getErrorRes(DaoReturnCode.headIconNotUpload));
            }
            //
            if (oldHeadIconUrl != newHeadIconUrl)
            {
                var updateStr = new JObject {
                    { "$set", new JObject {
                          { "headIconUrl", newHeadIconUrl },
                          { "lastUpdateTime", TimeHelper.GetTimeStamp() }
                      } }
                }.ToString();
                mh.UpdateData(dao_mongodbConnStr, dao_mongodbDatabase, userInfoCol, updateStr, findStr);
            }
            return(getRes());
        }
Beispiel #7
0
        public JArray getUserInfo(string userId, string accessToken)
        {
            if (!TokenHelper.checkAccessToken(tokenUrl, userId, accessToken, out string code))
            {
                return(getErrorRes(code));
            }
            string findStr = new JObject {
                { "userId", userId }
            }.ToString();
            string fieldStr = new JObject {
                { "username", 1 }, { "email", 1 }, { "emailVerifyState", 1 }, { "headIconUrl", 1 }, { "brief", 1 }, { "neoAddress", 1 }, { "ethAddress", 1 }, { "_id", 0 }
            }.ToString();
            var queryRes = mh.GetData(dao_mongodbConnStr, dao_mongodbDatabase, userInfoCol, findStr, fieldStr);

            if (queryRes.Count == 0)
            {
                return(getRes());
            }

            var item = queryRes[0];

            item["emailVerifyState"] = DaoInfoHelper.toEmailState(item["emailVerifyState"].ToString());
            return(getRes(item));
        }
Beispiel #8
0
        public JArray initBuyOrder(
            string userId,
            string accessToken,
            string projId,
            string rewardId,
            string amount,
            string rewardAmount,
            string connectorName,
            string connectorTel,
            string connectorAddress,
            string connectorEmail,
            string connectorMessage
            )
        {
            if (!TokenHelper.checkAccessToken(tokenUrl, userId, accessToken, out string code))
            {
                return(getErrorRes(code));
            }
            var findStr = new JObject {
                { "rewardId", rewardId }
            }.ToString();
            var queryRes = mh.GetData(dao_mongodbConnStr, dao_mongodbDatabase, projFinanceRewardCol, findStr);

            if (queryRes.Count == 0 ||
                queryRes[0]["activeState"].ToString() != RewardActiveState.Valid_Yes ||
                queryRes[0]["projId"].ToString() != projId
                )
            {
                // 无效回报id
                return(getErrorRes(DaoReturnCode.Invalid_RewardId));
            }
            var item = queryRes[0];

            if (!getProjTokenName(projId, out string tokenName, out string fundName))
            {
                return(getErrorRes(DaoReturnCode.S_InvalidProjId));
            }
            string projName = getProjName(projId);
            var    orderId  = DaoInfoHelper.genProjRewardOrderId(projId, rewardId, userId);
            var    now      = TimeHelper.GetTimeStamp();
            var    newdata  = new JObject {
                { "projId", projId },
                { "projName", projName },
                { "rewardId", rewardId },
                { "orderId", orderId },
                { "orderState", OrderState.WaitingPay },
                { "rewardName", item["rewardName"] },
                { "price", item["price"] },
                { "priceUnit", fundName },
                { "amount", amount },
                { "totalCost", (decimal.Parse(item["price"].ToString()) * decimal.Parse(amount)).ToString() },
                { "totalCostUnit", fundName },
                { "rewardAmount", rewardAmount },
                { "rewardAmountUnit", tokenName },
                { "senderNote", "" },
                { "connectorName", connectorName },
                { "connectorTel", connectorTel },
                { "connectorEmail", connectorEmail },
                { "connectorAddress", connectorAddress },
                { "connectorMessage", connectorMessage },
                { "distributeWay", item["distributeWay"] },
                { "txid", "" },
                { "userId", userId },
                { "originInfo", item },
                { "markTime", now },
                { "time", now },
                { "lastUpdateTime", now }
            };

            mh.PutData(dao_mongodbConnStr, dao_mongodbDatabase, projFinanceOrderCol, newdata);
            return(getRes(new JObject {
                { "orderId", orderId }, { "time", now }
            }));
        }
Beispiel #9
0
        public JArray saveReward(string userId, string accessToken, string projId, string connectorName, string connectTel, JObject info)
        {
            // TODO: 参数检查
            if (connectorName.Length > 40 || connectTel.Length > 40)
            {
                return(getErrorRes(DaoReturnCode.C_InvalidParamLen));
            }
            var infoJA = info["info"] as JArray;

            if (infoJA != null && infoJA.Count > 0)
            {
                if (connectorName.Length == 0 || connectTel.Length == 0)
                {
                    return(getErrorRes(DaoReturnCode.C_InvalidParamLen));
                }
                if (!infoJA.All(p => {
                    if (p["rewardId"] == null ||
                        p["rewardName"] == null ||
                        p["rewardDesc"] == null ||
                        p["price"] == null ||
                        p["limitFlag"] == null ||
                        p["distributeTimeFlag"] == null ||
                        p["distributeWay"] == null ||
                        p["note"] == null)
                    {
                        return(false);
                    }
                    var len = p["rewardName"].ToString().Length;
                    if (len == 0 || len > 40)
                    {
                        return(false);
                    }
                    len = p["rewardDesc"].ToString().Length;
                    if (len == 0 || len > 500)
                    {
                        return(false);
                    }
                    if (!checkIntFmt(p["price"]))
                    {
                        return(false);
                    }
                    var tp = p["limitFlag"].ToString();
                    if (tp == SelectKey.Yes)
                    {
                        if (p["limitMax"] == null || !checkIntFmt(p["limitMax"]))
                        {
                            return(false);
                        }
                    }
                    len = p["note"].ToString().Length;
                    if (len > 100)
                    {
                        return(false);
                    }
                    return(true);
                }))
                {
                    return(getErrorRes(DaoReturnCode.C_InvalidParamFmt));
                }
            }

            //
            string code;

            if (!checkToken(userId, accessToken, out code))
            {
                return(getErrorRes(code));
            }
            string findStr = new JObject {
                { "projId", projId }, { "userId", userId }, { "role", TeamRoleType.Admin }
            }.ToString();

            if (mh.GetDataCount(dao_mongodbConnStr, dao_mongodbDatabase, projTeamInfoCol, findStr) == 0)
            {
                return(getErrorRes(DaoReturnCode.T_NoPermissionStartFinance));
            }
            //
            findStr = new JObject {
                { "projId", projId }
            }.ToString();
            string fieldStr = new JObject {
                { "connectorName", 1 }, { "connectorTel", 1 }, { "fundName", 1 }, { "deployContractFlag", 1 }, { "reserveTokenSetFlag", 1 }, { "rewardSetFlag", 1 }
            }.ToString();
            var queryRes = mh.GetData(dao_mongodbConnStr, dao_mongodbDatabase, projFinanceCol, findStr, fieldStr);

            if (queryRes.Count == 0)
            {
                return(getErrorRes(DaoReturnCode.InvalidOperate));
            }
            //
            if (queryRes[0]["deployContractFlag"].ToString() != SkOp.FinishOp ||
                queryRes[0]["reserveTokenSetFlag"].ToString() != SkOp.FinishOp)
            {
                return(getErrorRes(DaoReturnCode.InvalidOperate));
            }

            if (queryRes[0]["connectorName"].ToString() != connectorName ||
                queryRes[0]["connectorTel"].ToString() != connectTel ||
                queryRes[0]["rewardSetFlag"].ToString() != SkOp.FinishOp)
            {
                string updateStr = new JObject {
                    { "$set", new JObject {
                          { "connectorName", connectorName }, { "connectorTel", connectTel }, { "rewardSetFlag", SkOp.FinishOp }
                      } }
                }.ToString();
                mh.UpdateData(dao_mongodbConnStr, dao_mongodbDatabase, projFinanceCol, updateStr, findStr);
            }
            //
            string fundName   = queryRes[0]["fundName"].ToString();
            var    rewardList = (JArray)info["info"];

            // TODO: 增删改查
            var nlist = new List <JToken>();

            findStr = new JObject {
                { "projId", projId }, { "activeState", RewardActiveState.Valid_Yes }
            }.ToString();
            queryRes = mh.GetData(dao_mongodbConnStr, dao_mongodbDatabase, projFinanceRewardCol, findStr);
            if (queryRes.Count == 0)
            {
                nlist = rewardList.ToList();
            }
            else
            {
                foreach (var item in rewardList)
                {
                    var id = item["rewardId"].ToString();
                    if (id.Trim().Length == 0)
                    {
                        nlist.Add(item);
                        continue;
                    }
                    var tItems = queryRes.Where(p => p["rewardId"].ToString() == id).ToArray();
                    if (tItems.Count() == 0)
                    {
                        continue;
                    }

                    var  tItem = tItems[0];
                    bool eq    = item["rewardName"].ToString() == tItem["rewardName"].ToString() &&
                                 item["rewardDesc"].ToString() == tItem["rewardDesc"].ToString() &&
                                 item["price"].ToString() == tItem["price"].ToString() &&
                                 item["limitFlag"].ToString() == tItem["limitFlag"].ToString() &&
                                 item["limitMax"].ToString() == tItem["limitMax"].ToString() &&
                                 item["distributeTimeFlag"].ToString() == tItem["distributeTimeFlag"].ToString() &&
                                 item["distributeTimeFixYes"].ToString() == tItem["distributeTimeFixYes"].ToString() &&
                                 item["distributeTimeFixNot"].ToString() == tItem["distributeTimeFixNot"].ToString() &&
                                 item["distributeWay"].ToString() == tItem["distributeWay"].ToString()
                    ;
                    if (eq)
                    {
                        continue;
                    }
                    findStr = new JObject {
                        { "rewardId", item["rewardId"] }
                    }.ToString();
                    var updateStr = new JObject {
                        { "$set", new JObject {
                              { "activeState", RewardActiveState.Valid_Not }
                          } }
                    }.ToString();
                    mh.UpdateData(dao_mongodbConnStr, dao_mongodbDatabase, projFinanceRewardCol, updateStr, findStr);
                    nlist.Add(item);
                }
                //
                var oIds = queryRes.Select(p => p["rewardId"].ToString()).ToArray();
                foreach (var id in oIds)
                {
                    if (rewardList.All(p => p["rewardId"].ToString() != id))
                    {
                        findStr = new JObject {
                            { "projId", projId }, { "rewardId", id }
                        }.ToString();
                        var updateStr = new JObject {
                            { "$set", new JObject {
                                  { "activeState", RewardActiveState.Valid_Not }
                              } }
                        }.ToString();
                        mh.UpdateData(dao_mongodbConnStr, dao_mongodbDatabase, projFinanceRewardCol, updateStr, findStr);
                    }
                }
            }
            //
            var res = nlist.Select(p =>
            {
                p["projId"]         = projId;
                p["rewardId"]       = DaoInfoHelper.genProjRewardId(projId, p["rewardName"].ToString());
                p["fundName"]       = fundName;
                p["activeState"]    = RewardActiveState.Valid_Yes;
                p["hasSellCount"]   = 0;
                p["hasSellCountTp"] = 0;
                return(p);
            }).ToArray();

            if (res.Count() > 0)
            {
                mh.PutData(dao_mongodbConnStr, dao_mongodbDatabase, projFinanceRewardCol, new JArray {
                    res
                });
            }
            return(getRes());
        }