示例#1
0
        public async Task <IActionResult> ActiveAccount(string verifyType, string returnUrl = null)
        {
            var user = await _userManager.GetUserAsync(User);

            ISendActiveAccountCounted data = await _countSendActiveAccountRequestClient.Request(
                new
            {
                UserId     = user.Id,
                VerifyType = verifyType
            });

            ViewData["returnUrl"] = returnUrl;
            return(View(new VerifyViewModel()
            {
                VerifyType = verifyType, CountSendNotification = data.Count
            }));
        }
示例#2
0
        public async Task <long> SendCode(string verifyType)
        {
            var user = await _userManager.GetUserAsync(User);

            var code = string.Empty;
            ISendActiveAccountCounted data = await _countSendActiveAccountRequestClient.Request(
                new
            {
                UserId     = user.Id,
                VerifyType = verifyType
            });

            if (data.Count >= 5)
            {
                return(data.Count);
            }
            else
            {
                switch (verifyType)
                {
                case "Email":
                    code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    await _publishEndpoint.Publish <ISendMail>(
                        new
                    {
                        TypeNotification = TypeNotification.VerifyAccount,
                        Culture          = System.Globalization.CultureInfo.CurrentCulture.Name,
                        ObjectId         = user.Id,
                        ObjectType       = "users",
                        Data             = new DataSendMail()
                        {
                            Receiver = user.Email,
                            Body     = code
                        }
                    });

                    break;

                case "SMS":
                    code = await _userManager.GenerateChangePhoneNumberTokenAsync(user, user.PhoneNumber);

                    await _publishEndpoint.Publish <ISendSMS>(
                        new
                    {
                        TypeNotification = TypeNotification.VerifyAccount,
                        Culture          = System.Globalization.CultureInfo.CurrentCulture.Name,
                        ObjectId         = user.Id,
                        ObjectType       = "users",
                        Data             = new DataSendSMS()
                        {
                            Phone   = user.PhoneNumber,
                            Message = code
                        }
                    });

                    break;

                default:
                    break;
                }
                return(data.Count + 1);
            }
        }