Ejemplo n.º 1
0
        public JsonResult AddShopUser(ShopUserModel Model)
        {
            JsonModel jm = new JsonModel();

            //如果表单验证成功
            if (ModelState.IsValid)
            {
                IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

                T_ShopUser shopUser = new T_ShopUser()
                {
                    UserName = Model.UserName,
                    TrueName = Model.TrueName,
                    Phone    = Model.Phone,
                    Gender   = Model.Gender,
                    Email    = Model.Email,
                    Password = PropertyUtils.GetMD5Str(Model.Password),
                    Memo     = Model.Memo
                };
                //保存到数据库
                shopUserBll.Save(shopUser);
                //日志记录
                jm.Content = PropertyUtils.ModelToJsonString(Model);
            }
            else
            {
                //保存异常日志
                jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR;
            }
            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        private static TelegramShopMessageHandler GetLicenseDurationPageProcessor(
            MessageEventArgs e,
            ShopUserModel user)
        {
            switch (e.Message.Text)
            {
            case MenuMessage.OneWeekDuration:
                return(new PaymentMethodMessageHandler(7, 100, user.LicenseBuyProcess.LicenseKey));

            case MenuMessage.OneMonthDuration:
                return(new PaymentMethodMessageHandler(30, 300, user.LicenseBuyProcess.LicenseKey));

            case MenuMessage.ThreeMonthDuration:
                return(new PaymentMethodMessageHandler(90, 800, user.LicenseBuyProcess.LicenseKey));

            case MenuMessage.SixMonthDuration:
                return(new PaymentMethodMessageHandler(180, 1500, user.LicenseBuyProcess.LicenseKey));

            case MenuMessage.OneYearDuration:
                return(new PaymentMethodMessageHandler(365, 2800, user.LicenseBuyProcess.LicenseKey));

            case MenuMessage.Back: return(new BackMessageHandler(EDialogState.Main, AnswerMessage.MainMenu));

            default: throw new ArgumentException(AnswerMessage.IncorrectCommand);
            }
        }
Ejemplo n.º 3
0
        public ActionResult AddShopUser()
        {
            ShopUserModel Model = new ShopUserModel();

            Model.GenderList = GetGenderList();
            return(View(Model));
        }
Ejemplo n.º 4
0
        public ActionResult EditShopUser(int id)
        {
            IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

            //获取要编辑的门店用户
            T_ShopUser shopUser = shopUserBll.GetEntity(m => m.Id == id && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);

            if (shopUser != null)
            {
                //初始化返回页面的模型
                ShopUserModel model = new ShopUserModel()
                {
                    Id         = shopUser.Id,
                    UserName   = shopUser.UserName,
                    TrueName   = shopUser.TrueName,
                    Phone      = shopUser.Phone,
                    Gender     = shopUser.Gender,
                    GenderList = GetGenderList(),
                    Email      = shopUser.Email,
                    Memo       = shopUser.Memo
                };
                return(View(model));
            }
            else
            {
                return(RedirectToAction("ShopUserList"));
            }
        }
Ejemplo n.º 5
0
        private static string GetQiwiPaymentMessage(ShopUserModel user)
        {
            var comment = GetUniqueComment();

            ShopUserRepository.UpdatePurchaseUniqueComment(user, comment);

            return(AnswerMessage.QiwiPaymentMethod
                   .Replace("{price}", user.LicenseBuyProcess.Price.ToString(CultureInfo.InvariantCulture))
                   .Replace("{comment}", comment));
        }
Ejemplo n.º 6
0
        private static string GetAllUsersLicenseMessage(ShopUserModel user)
        {
            var message = new StringBuilder(AnswerMessage.YouHaveNextLicenses);

            foreach (var key in user.LicenseKeys)
            {
                message.Append(Environment.NewLine).Append("`").Append(key).Append("`");
            }

            return(message.ToString());
        }
Ejemplo n.º 7
0
        public static bool StillBlocked(ShopUserModel user)
        {
            var minutes      = (DateTime.Now - user.LastMessageDate).TotalMinutes;
            var stillBlocked = minutes < 60;

            if (stillBlocked == false)
            {
                ShopUserRepository.UpdateSpamLevelWarning(user, 0);
            }

            return(stillBlocked);
        }
        public IActionResult Post([FromBody] Login login)
        {
            shopresult = _ShopOwnerDataProvider.LoginShopOwner(login);
            if (shopresult == null)
            {
                return(new BadRequestResult());
            }


            String ShopToken = BuildShopUserToken(shopresult);

            return(new OkObjectResult(new { token = ShopToken }));
        }
Ejemplo n.º 9
0
        private string GetPaymentMethodMessage(ShopUserModel user)
        {
            if (this.renewLicenseKey != null)
            {
                return(AnswerMessage.RenewPaymentMethodMenu
                       .Replace("{days}", this.daysCount.ToString())
                       .Replace("{license}", this.renewLicenseKey)
                       .Replace("{price}", this.price.ToString(CultureInfo.InvariantCulture)));
            }

            return(AnswerMessage.NewLicensePaymentMethodMenu
                   .Replace("{days}", this.daysCount.ToString())
                   .Replace("{price}", this.price.ToString(CultureInfo.InvariantCulture)));
        }
Ejemplo n.º 10
0
        private static TelegramShopMessageHandler GetLicenseKeyRemovePageProcessor(
            MessageEventArgs e,
            ShopUserModel user)
        {
            if (e.Message.Text == MenuMessage.Back)
            {
                return(new BackMessageHandler(EDialogState.Main, AnswerMessage.MainMenu));
            }

            if (user.LicenseKeys.Contains(e.Message.Text))
            {
                ShopUserRepository.RemoveLicenseKey(user, e.Message.Text);
                return(new LicenseRenewSubscriptionMessageHandler());
            }

            throw new ArgumentException(AnswerMessage.LicenseKeyNotBelongsToYou);
        }
Ejemplo n.º 11
0
        public static TelegramShopMessageHandler GetMenuProcessor(ShopUserModel user, MessageEventArgs e)
        {
            TelegramShopMessageHandler messageProcessor;

            switch (user.CurrentDialogState)
            {
            case EDialogState.Main:
                messageProcessor = GetMainPageProcessor(e, user);
                break;

            case EDialogState.ManageLicense:
                messageProcessor = GetManageLicensePageProcessor(e);
                break;

            case EDialogState.LicenseRenewSubscription:
                messageProcessor = GetLicenseRenewSubscriptionPageProcessor(e, user);
                break;

            case EDialogState.LicenseDuration:
                messageProcessor = GetLicenseDurationPageProcessor(e, user);
                break;

            case EDialogState.LicenseKeyAdd:
                messageProcessor = GetLicenseKeyAddPageProcessor(e, user);
                break;

            case EDialogState.LicenseKeyRemove:
                messageProcessor = GetLicenseKeyRemovePageProcessor(e, user);
                break;

            case EDialogState.PaymentMethod:
                messageProcessor = GetPaymentMethodPageProcessor(e);
                break;

            case EDialogState.QiwiPaymentVerification:
                messageProcessor = GetQiwiPaymentPageProcessor(e);
                break;

            default: throw new ArgumentException(AnswerMessage.IncorrectCommand);
            }

            return(messageProcessor);
        }
Ejemplo n.º 12
0
        private static TelegramShopMessageHandler GetLicenseRenewSubscriptionPageProcessor(
            MessageEventArgs e,
            ShopUserModel user)
        {
            if (user.LicenseKeys.Contains(e.Message.Text))
            {
                return(new LicensePurchaseDurationMessageHandler(e.Message.Text));
            }

            switch (e.Message.Text)
            {
            case MenuMessage.LicenseAddNewKey: return(new LicenseKeyAddMessageHandler());

            case MenuMessage.LicenseRemoveKey: return(new LicenseKeyRemoveMessageHandler());

            case MenuMessage.Back: return(new BackMessageHandler(EDialogState.Main, AnswerMessage.MainMenu));

            default: throw new ArgumentException(AnswerMessage.IncorrectCommand);
            }
        }
Ejemplo n.º 13
0
        public JsonResult EditShopUser(ShopUserModel model)
        {
            JsonModel jm = new JsonModel();

            //如果表单验证成功
            if (ModelState.IsValid)
            {
                IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

                T_ShopUser shopUser = shopUserBll.GetEntity(m => m.Id == model.Id && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);
                if (shopUser != null)
                {
                    shopUser.UserName = model.UserName;
                    shopUser.TrueName = model.TrueName;
                    shopUser.Email    = model.Email;
                    shopUser.Gender   = model.Gender;
                    shopUser.Phone    = model.Phone;
                    shopUser.Memo     = model.Memo;
                    //保存到数据库
                    if (shopUserBll.Update(shopUser))
                    {
                        //日志记录
                        jm.Content = PropertyUtils.ModelToJsonString(model);
                    }
                    else
                    {
                        jm.Msg = "编辑失败";
                    }
                }
                else
                {
                    jm.Msg = "该门店用户不存在";
                }
            }
            else
            {
                jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR;
            }
            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 14
0
        public static async Task <bool> IsSpamming(
            TelegramShopClient telegramShop,
            MessageEventArgs e,
            ShopUserModel user)
        {
            // if user is blocked
            if (user.SpamWarning >= 100 && StillBlocked(user))
            {
                return(true);
            }

            // if user is not spamming
            if (ShopUserRepository.IsUserSpamming(user) == false)
            {
                ShopUserRepository.UpdateUserLastMessageDate(user);
                return(false);
            }

            ShopUserRepository.UpdateUserLastMessageDate(user);
            ShopUserRepository.UpdateSpamLevelWarning(user);

            // if we should ban user
            if (user.SpamWarning >= 10)
            {
                ShopUserRepository.UpdateSpamLevelWarning(user, 100);

                await telegramShop.SendMessage(e.Message.Chat.Id, AnswerMessage.SpamYouAreBlockedMessage, null);

                return(true);
            }

            await telegramShop.SendMessage(
                e.Message.Chat.Id,
                AnswerMessage.SpamWarningMessage.Replace("{times}", (10 - user.SpamWarning).ToString()),
                TelegramShopMessageHandler.GetKeyboard(user.CurrentDialogState));

            return(true);
        }
        private string BuildShopUserToken(ShopUserModel shopuser)
        {
            try
            {
                var claims = new[]
                {
                    new Claim(JwtRegisteredClaimNames.Sub, shopuser.Name),
                    new Claim(JwtRegisteredClaimNames.Email, shopuser.Email),
                    new Claim(JwtRegisteredClaimNames.NameId, shopuser.UId),
                    new Claim(JwtRegisteredClaimNames.Aud, shopuser.Location),
                    new Claim(JwtRegisteredClaimNames.Acr, shopuser.Url),
                    new Claim(JwtRegisteredClaimNames.Actort, shopuser.ShopName),
                    new Claim(JwtRegisteredClaimNames.Azp, shopuser.ShopId.ToString()),
                    new Claim(JwtRegisteredClaimNames.Amr, shopuser.Description),
                    new Claim(JwtRegisteredClaimNames.AtHash, shopuser.Lat),
                    new Claim(JwtRegisteredClaimNames.CHash, shopuser.Lng),
                    new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
                };
                var key   = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"]));
                var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);

                var token = new JwtSecurityToken(_config["Jwt:Issuer"],
                                                 _config["Jwt:Issuer"],
                                                 claims,
                                                 expires: DateTime.Now.AddMinutes(30),
                                                 signingCredentials: creds);

                //token = new JwtSecurityToken();
                return(new JwtSecurityTokenHandler().WriteToken(token));
                //return new JwtSecurityTokenHandler().WriteToken(token);
            }
            catch (Exception e)
            {
                return(e.ToString());
            }
        }
Ejemplo n.º 16
0
        private static TelegramShopMessageHandler GetMainPageProcessor(MessageEventArgs e, ShopUserModel user)
        {
            switch (e.Message.Text)
            {
            case MenuMessage.Contacts: return(new TextInfoMessageHandler(AnswerMessage.Contacts));

            case MenuMessage.ManageLicense: return(new LicenseManageMessageHandler());

            case MenuMessage.LicenseStatus:
                return(new TextInfoMessageHandler(LicenseServerHandler.GetLicenseStatus(user.LicenseKeys)));

            case MenuMessage.SteamAutoMarketInfo:
                return(new TextInfoMessageHandler(AnswerMessage.SteamAutoMarketInfo));

            default: throw new ArgumentException(AnswerMessage.IncorrectCommand);
            }
        }
Ejemplo n.º 17
0
        public ShopUserModel LoginShopOwner(Login login)
        {
            String checkUserName;

            login.Pass_word = HashAndSalt.HashSalt(login.Pass_word);

            var email    = login.Email;
            var password = login.Pass_word;

            using (IDbConnection dbConnection = Connection)
            {
                string sQuery = "SELECT FirstName FROM ShopOwner WHERE Email = @Email AND Pass_word = @Pass_word";
                dbConnection.Open();
                checkUserName = dbConnection.QueryFirstOrDefault <String>(sQuery, new { @Email = email, @Pass_word = password });



                if (String.IsNullOrEmpty(checkUserName))
                {
                    return(null);
                }
                else
                {
                    string OwnerID;
                    string sQuery1 = "SELECT ShopOwnerId from ShopOwner where Email = @email";
                    OwnerID = dbConnection.QueryFirstOrDefault <String>(sQuery1, new { @Email = email });
                    string sQuery2 = "SELECT * FROM Shop WHERE OwnerId = @OwnerID";
                    try
                    {
                        dynamic shop = dbConnection.QueryFirst(sQuery2, new { OwnerId = OwnerID });



                        ShopUserModel shopuser = null;
                        shopuser = new ShopUserModel
                        {
                            ShopId      = shop.ShopId,
                            UId         = OwnerID,
                            Name        = checkUserName,
                            Email       = email,
                            Description = shop.Des_cription,
                            Location    = shop.Lo_cation,
                            ShopName    = shop.ShopName,
                            Url         = shop.url,
                            Lat         = shop.Lat,
                            Lng         = shop.Lng,
                        };

                        return(shopuser);
//                        String Token = BuildShopUserToken(shopuser);
//                        return new OkObjectResult(new { token = Token });
                    }
                    catch (Exception e)
                    {
                        return(null);
                    }

                    /* var method = typeof(TokenCreator).GetMethod("createToken");
                     * var action = (Action<TokenCreator>)Delegate.CreateDelegate(typeof(Action<TokenCreator>), method);
                     * action(user);*/
                } //TokenCreator tokencreator = new TokenCreatorC();

                //return tokencreator.createToken(user);
            }
        }
        public override async Task Process(TelegramShopClient telegramShop, MessageEventArgs e, ShopUserModel userModel)
        {
            ShopUserRepository.UpdateUserDialogState(userModel, EDialogState.ManageLicense);

            await telegramShop.SendMessage(e.Message.Chat.Id, AnswerMessage.LicenseManageMenuTitle, GetKeyboard(userModel.CurrentDialogState));
        }
Ejemplo n.º 19
0
        public override async Task Process(TelegramShopClient telegramShop, MessageEventArgs e, ShopUserModel userModel)
        {
            ShopUserRepository.UpdateUserDialogState(userModel, EDialogState.QiwiPaymentVerification);

            if (cachedPayments != null && IsCachedOld() == false)
            {
                await telegramShop.SendMessage(
                    e.Message.Chat.Id,
                    GetQiwiTimeToNewRequestLeftMessage(),
                    GetKeyboard(userModel.CurrentDialogState));

                return;
            }

            var payments = telegramShop.Qiwi.GetIncomingTransactions().Result;

            lastRequestDate = DateTime.Now;
            cachedPayments  = payments;

            var isPaymentPresent = IsPaymentPresent(
                userModel.LicenseBuyProcess.Comment,
                userModel.LicenseBuyProcess.Price,
                payments);

            if (isPaymentPresent)
            {
                await telegramShop.BoldLog($"@{userModel.Telegram} bought license for {userModel.LicenseBuyProcess.Days} days for {userModel.LicenseBuyProcess.Price} RUB");

                ShopUserRepository.UpdateUserDialogState(userModel, EDialogState.Main);

                if (userModel.LicenseBuyProcess.LicenseKey == null)
                {
                    var newLicenseKey = GetNewLicenseKey(userModel.Telegram);
                    LicenseServerHandler.GetNewLicense(userModel.LicenseBuyProcess.Days);

                    ShopUserRepository.AddLicenseKey(userModel, newLicenseKey);

                    await telegramShop.SendMessage(
                        e.Message.Chat.Id,
                        GetQiwiNewLicenseKeyAddedMessage(newLicenseKey, userModel.LicenseBuyProcess.Days),
                        GetKeyboard(userModel.CurrentDialogState));
                }
                else
                {
                    LicenseServerHandler.AddDaysForExistLicense(
                        userModel.LicenseBuyProcess.LicenseKey,
                        userModel.LicenseBuyProcess.Days);

                    await telegramShop.SendMessage(
                        e.Message.Chat.Id,
                        GetQiwiLicenseKeyDaysAddedMessage(
                            userModel.LicenseBuyProcess.LicenseKey,
                            userModel.LicenseBuyProcess.Days),
                        GetKeyboard(userModel.CurrentDialogState));
                }

                ShopUserRepository.UpdatePurchaseUniqueComment(userModel, null);
                ShopUserRepository.UpdateUserBuyLicenseKey(userModel, null);
                ShopUserRepository.UpdateUserLicenseDuration(userModel, 0, 0);
            }
            else
            {
                await telegramShop.SendMessage(
                    e.Message.Chat.Id,
                    GetQiwiTimeToNewRequestLeftMessage(),
                    GetKeyboard(userModel.CurrentDialogState));
            }
        }
Ejemplo n.º 20
0
        private static TelegramShopMessageHandler GetLicenseKeyAddPageProcessor(MessageEventArgs e, ShopUserModel user)
        {
            if (e.Message.Text == MenuMessage.Back)
            {
                return(new BackMessageHandler(EDialogState.Main, AnswerMessage.MainMenu));
            }

            if (LicenseServerHandler.IsLicenseExist(e.Message.Text))
            {
                ShopUserRepository.AddLicenseKey(user, e.Message.Text);
                return(new LicenseRenewSubscriptionMessageHandler());
            }

            throw new ArgumentException(AnswerMessage.LicenseKeyNotExist);
        }
        public override async Task Process(TelegramShopClient telegramShop, MessageEventArgs e, ShopUserModel userModel)
        {
            ShopUserRepository.UpdateUserDialogState(userModel, EDialogState.LicenseDuration);
            ShopUserRepository.UpdateUserBuyLicenseKey(userModel, this.licenseKey);

            await telegramShop.SendMessage(e.Message.Chat.Id, AnswerMessage.LicenseDurationMenu, GetKeyboard(userModel.CurrentDialogState));
        }
Ejemplo n.º 22
0
 public override async Task Process(TelegramShopClient telegramShop, MessageEventArgs e, ShopUserModel user)
 {
     await telegramShop.SendMessage(e.Message.Chat.Id, this.text, GetKeyboard(user.CurrentDialogState));
 }
Ejemplo n.º 23
0
        public override async Task Process(TelegramShopClient telegramShop, MessageEventArgs e, ShopUserModel userModel)
        {
            ShopUserRepository.UpdateUserDialogState(userModel, this.dialogState);

            await telegramShop.SendMessage(e.Message.Chat.Id, this.message, GetKeyboard(userModel.CurrentDialogState));
        }
Ejemplo n.º 24
0
        public override async Task Process(TelegramShopClient telegramShop, MessageEventArgs e, ShopUserModel userModel)
        {
            ShopUserRepository.UpdateUserDialogState(userModel, EDialogState.QiwiPaymentVerification);

            await telegramShop.SendMessage(e.Message.Chat.Id, GetQiwiPaymentMessage(userModel), GetKeyboard(userModel.CurrentDialogState));
        }
Ejemplo n.º 25
0
        public override async Task Process(TelegramShopClient telegramShop, MessageEventArgs e, ShopUserModel userModel)
        {
            ShopUserRepository.UpdateUserDialogState(userModel, EDialogState.PaymentMethod);
            ShopUserRepository.UpdateUserLicenseDuration(userModel, this.daysCount, this.price);

            await telegramShop.SendMessage(e.Message.Chat.Id, this.GetPaymentMethodMessage(userModel), GetKeyboard(userModel.CurrentDialogState));
        }
 public virtual Task Process(TelegramShopClient telegramShop, MessageEventArgs e, ShopUserModel userModel)
 {
     return(Task.FromResult(default(object)));
 }
Ejemplo n.º 27
0
        public override async Task Process(TelegramShopClient telegramShop, MessageEventArgs e, ShopUserModel userModel)
        {
            ShopUserRepository.UpdateUserDialogState(userModel, EDialogState.LicenseRenewSubscription);
            var keyboard = GetKeyboard(userModel.CurrentDialogState);

            await telegramShop.SendMessage(e.Message.Chat.Id, GetAllUsersLicenseMessage(userModel), keyboard);

            await telegramShop.SendMessage(e.Message.Chat.Id, AnswerMessage.SendMeLicenseKeyToStartRenew, keyboard);
        }