public async Task <IActionResult> AddPhoneNumber(AddPhoneNumberViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            // Generate the token and send it
            var user = await GetCurrentUserAsync();

            if (user == null)
            {
                return(View("Error"));
            }
            var code = await _userManager.GenerateChangePhoneNumberTokenAsync(user, model.PhoneNumber);

            await _smsSender.SendSmsAsync(model.PhoneNumber, "Your security code is: " + code);

            return(RedirectToAction(nameof(VerifyPhoneNumber), new { PhoneNumber = model.PhoneNumber }));
        }
示例#2
0
        public void SendSms(List <Guid> requestIds, int itineraryId)
        {
            var requests = context.Requests.Where(x => requestIds.Contains(x.RequestId) && x.Status == RequestStatus.PendingConfirmation).ToList();

            if (requests.Count > 0)
            {
                var itinerary = context.Itineraries.Include(i => i.Event).Single(x => x.Id == itineraryId);

                //don't send out messages if today is not the date of the Itinerary
                if (TodayIsTheDayOfThe(itinerary.Date, itinerary.Event.TimeZoneId))
                {
                    smsSender.SendSmsAsync(requests.Select(x => x.Phone).ToList(), "sorry you couldn't make it, we will reschedule.");
                }

                mediator.Send(new SetRequestsToUnassignedCommand {
                    RequestIds = requests.Select(x => x.RequestId).ToList()
                });
            }
        }
示例#3
0
        public async Task <IActionResult> AddPhoneNumber(AddPhoneNumberViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            // Generate the token and send it
            var user = await userManager.FindByIdAsync(HttpContext.User.GetUserId());

            var code = await userManager.GenerateChangePhoneNumberTokenAsync(user, model.Number);

            await smsSender.SendSmsAsync(
                Site,
                model.Number,
                string.Format(sr["Your security code is: {0}"], code)
                );

            return(RedirectToAction("VerifyPhoneNumber", new { PhoneNumber = model.Number }));
        }
示例#4
0
        public async Task <ActionResult> SendCode(SendCodeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var user = await signInManager.GetTwoFactorAuthenticationUserAsync();

            if (user == null)
            {
                return(View("Error"));
            }

            // Generate the token and send it
            var code = await userManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider);

            if (string.IsNullOrWhiteSpace(code))
            {
                return(View("Error"));
            }


            if (model.SelectedProvider == "Email")
            {
                string toAddress = await userManager.GetEmailAsync(user);

                await emailSender.SendSecurityCodeEmailAsync(
                    Site,
                    toAddress,
                    "Security Code",
                    code);
            }
            else if (model.SelectedProvider == "Phone")
            {
                var message   = "Your security code is: " + code;
                var userPhone = await userManager.GetPhoneNumberAsync(user);

                await smsSender.SendSmsAsync(Site, userPhone, message);
            }

            return(RedirectToAction("VerifyCode", new { Provider = model.SelectedProvider, ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe }));
        }
示例#5
0
        private async Task <ReturnSignUserResponse> MakeDecisionAsync(User user,
                                                                      bool isExternal,
                                                                      ReturnUrlRequest?returnUrl,
                                                                      CancellationToken token)
        {
            if (user.PhoneNumberConfirmed)
            {
                if (isExternal)
                {
                    await _signInManager.SignInAsync(user, false);

                    return(ReturnSignUserResponse.SignIn());
                    // return new ReturnSignUserResponse(false);
                }

                throw new ArgumentException();
            }

            if (user.PhoneNumber != null)
            {
                var t1 = _signInManager.TempSignIn(user);
                var t2 = _client.SendSmsAsync(user, token);

                await Task.WhenAll(t1, t2);

                return(new ReturnSignUserResponse(RegistrationStep.RegisterVerifyPhone, new
                {
                    phoneNumber = user.PhoneNumber
                }));
            }

            if (user.EmailConfirmed)
            {
                await _signInManager.TempSignIn(user);

                return(new ReturnSignUserResponse(RegistrationStep.RegisterSetPhone));
            }

            await GenerateEmailAsync(user, returnUrl, token);

            return(new ReturnSignUserResponse(RegistrationStep.RegisterEmailConfirmed));
        }
示例#6
0
        public async Task <IActionResult> SendCode(SendCodeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();

            if (user == null)
            {
                return(View("Error"));
            }

            // Generate the token and send it
            var code = await _identityUserManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider);

            if (string.IsNullOrWhiteSpace(code))
            {
                return(View("Error"));
            }

            var message = "Your security code is: " + code;

            if (model.SelectedProvider == "Email")
            {
                try
                {
                    await _emailSender.SendEmailAsync(await _identityUserManager.GetEmailAsync(user), "Security Code", message);
                }
                catch (Exception except)
                {
                    _logger.LogError(0, except, "can't send email");
                }
            }
            else if (model.SelectedProvider == "Phone")
            {
                await _smsSender.SendSmsAsync(await _identityUserManager.GetPhoneNumberAsync(user), message);
            }

            return(RedirectToAction(nameof(VerifyCode), new { Provider = model.SelectedProvider, ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe }));
        }
示例#7
0
        public async Task AddPhoneNumber(string phoneNumber)
        {
            if (!Validate.PhoneNumberValidation(phoneNumber))
            {
                throw new ValidationException("Invalid inputs");
            }

            var user = await GetCurrentUserAsync();

            if (user != null)
            {
                var code = await _userManager.GenerateChangePhoneNumberTokenAsync(user, phoneNumber);

                await _smsSender.SendSmsAsync(phoneNumber, "Your Payloola OTP is: " + code);
            }
            else
            {
                throw new ValidationException("Invalid User");
            }
        }
        public async Task <IActionResult> Send(UserStatus[] status, string role, MessageMedia media, string subject, string messageBody, string smsBody)
        {
            var usersToReceiveMessage = userManager.Users.Where(user => status.Contains(user.Status)).ToHashSet();

            if (!String.IsNullOrEmpty(role))
            {
                usersToReceiveMessage.UnionWith(await userManager.GetUsersInRoleAsync(role));
            }
            if (media == MessageMedia.SMS || media == MessageMedia.EmailSMS)
            {
                var userPhonenumbers = usersToReceiveMessage.Where(user => !string.IsNullOrEmpty(user?.PhoneNumber)).Select(user => user.PhoneNumber).ToArray();
                var result           = await smsSender.SendSmsAsync(smsBody, userPhonenumbers);
            }
            if (media == MessageMedia.Email || media == MessageMedia.EmailSMS)
            {
                var mails = usersToReceiveMessage.Where(user => !string.IsNullOrEmpty(user?.Email)).Select(user => user.Email).ToArray();
                await emailSender.SendEmailAsync(string.Join(";", mails), subject, messageBody);
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> SendCode(SendCode model, string returnTo)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();

            if (user == null)
            {
                return(View("Error"));
            }

            var code = await _userManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider);

            if (string.IsNullOrEmpty(code))
            {
                return(View("Error"));
            }

            var message = $"Confirm Code: {code}";

            if (model.SelectedProvider == "Email")
            {
                await _emailSender.SendEmailAsync(user.Email, "Confirm Code", message);
            }
            else if (model.SelectedProvider == "Phone")
            {
                await _smsSender.SendSmsAsync(user.PhoneNumber, message);
            }


            return(RedirectToRoute("GetVerifyCode",
                                   new
            {
                returnTo,
                rememberMe = model.RememberMe,
                provider = model.SelectedProvider
            }));
        }
示例#10
0
        public void SendSms(List <Guid> requestIds, int itineraryId)
        {
            var requestorPhoneNumbers = context.Requests.Where(x => requestIds.Contains(x.RequestId) && x.Status == RequestStatus.PendingConfirmation).Select(x => x.Phone).ToList();

            if (requestorPhoneNumbers.Count > 0)
            {
                //TODO mgmccarthy: need to convert itinerary.Date to local time of the request's intinerary's campaign's timezoneid. Waiting on the final word for how we'll store DateTime, as well as Issue #1386
                var itinerary = context.Itineraries.Single(x => x.Id == itineraryId);

                //don't send out messages if today is less than 7 days away from the Itinerary.Date.
                //This can happen if a request is added to an itinereary less than 7 days away from the itinerary's date
                if (TodayIsEqualToOrGreaterThanSevenDaysBefore(itinerary.Date))
                {
                    smsSender.SendSmsAsync(requestorPhoneNumbers,
                                           $@"Your request has been scheduled by allReady for {itinerary.Date.Date}. Please response with ""Y"" to confirm this request or ""N"" to cancel this request.");
                }

                //schedule job for one day before Itinerary.Date
                backgroundJob.Schedule <ISendRequestConfirmationMessagesADayBeforeAnItineraryDate>(x => x.SendSms(requestIds, itinerary.Id), OneDayBefore(itinerary.Date));
            }
        }
示例#11
0
        public void SendSms(List <Guid> requestIds, int itineraryId)
        {
            var requestorPhoneNumbers = context.Requests.Where(x => requestIds.Contains(x.RequestId) && x.Status == RequestStatus.PendingConfirmation).Select(x => x.Phone).ToList();

            if (requestorPhoneNumbers.Count > 0)
            {
                var itinerary = context.Itineraries.Include(i => i.Event).Single(x => x.Id == itineraryId);

                //don't send out messages if today is not 1 day before from the DayOfThe.Date. This sceanrio can happen if:
                //1. a request is added to an itinereary less than 1 day away from the itinerary's date
                //2. if the Hangfire server is offline for the period where it would have tried to process this job. Hangfire processes jobs in the "past" by default
                if (TodayIsOneDayBeforeThe(itinerary.Date, itinerary.Event.TimeZoneId))
                {
                    smsSender.SendSmsAsync(requestorPhoneNumbers,
                                           $@"Your request has been scheduled by allReady for {itinerary.Date.Date}. Please response with ""Y"" to confirm this request or ""N"" to cancel this request.");
                }

                //schedule job for day of the Intinerary Date
                backgroundJob.Schedule <ISendRequestConfirmationMessagesTheDayOfAnItineraryDate>(x => x.SendSms(requestIds, itinerary.Id), DayOfThe(itinerary.Date, itinerary.Event.TimeZoneId));
            }
        }
示例#12
0
        public async Task <IActionResult> AddPhoneNumber(AddPhoneNumberViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            // Generate the token and send it
            var user = await GetCurrentUserAsync();

            if (user == null)
            {
                return(View("Error"));
            }

            var code = await _userManager.GenerateChangePhoneNumberTokenAsync(user, model.PhoneNumber);

            //https://github.com/aspnet/Identity/issues/1494
            await _smsSender.SendSmsAsync(JsonConvert.SerializeObject(new { code = code }), model.PhoneNumber, "9812");

            return(RedirectToAction(nameof(VerifyPhoneNumber), new { PhoneNumber = model.PhoneNumber }));
        }
示例#13
0
        public async Task <IActionResult> HotelRegister(HotelRegisterationViewModel model)
        {
            var user = _userManager.FindByIdAsync(model.AppUserId).Result;

            if (ModelState.IsValid)
            {
                var hotel = new Hotel()
                {
                    HotelName   = model.HotelName,
                    Description = model.Description,
                    AboutHotel  = model.Description,
                    NoOfFloors  = model.NoOfFloors,
                    NoOfRooms   = model.NoOfRooms,
                    HotelCity   = model.HotelCity,
                    ZipCode     = model.ZipCode,
                    Address     = model.Address,
                    AppUser     = user
                };
                var city = new City()
                {
                    CityName = model.HotelCity
                };
                _repository.Add(city);
                _repository.Add(hotel);

                if (_repository.SaveChange())
                {
                    await _emailSender.SendEmailAsync(user.Email, "Account Requestng  Mail",
                                                      $"Your Request for Adding Account is send Succesfully..it will took a few days process on it")
                    .ConfigureAwait(true);

                    await _smsSender.SendSmsAsync(user.PhoneNumber, "Your Request for Adding Account is send Succesfully." +
                                                  "it will took a few days process on it").ConfigureAwait(true);

                    return(RedirectToAction("Message", "AddingHotelMessage", new { email = user.Email }));
                }
            }

            return(View());
        }
示例#14
0
        public async Task <IActionResult> SendCode(SendCodeViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Json(new { success = false, msg = "Invalid model." }));
                }

                var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();

                if (user == null)
                {
                    return(Json(new { success = false, msg = "No user." }));
                }

                // Generate the token and send it
                var code = await _userManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider);

                if (string.IsNullOrWhiteSpace(code))
                {
                    return(Json(new { success = false, msg = "No code." }));
                }

                var message = "Your security code is: " + code;
                if (model.SelectedProvider == "Email")
                {
                    await _emailSender.SendEmailAsync(await _userManager.GetEmailAsync(user), "Security Code", message);
                }
                else if (model.SelectedProvider == "Phone")
                {
                    await _smsSender.SendSmsAsync(await _userManager.GetPhoneNumberAsync(user), message);
                }
                return(Json(new { success = true, msg = "Code sent.", pvdr = model.SelectedProvider }));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, msg = ex.ToString() }));
            }
        }
示例#15
0
        public async Task <IActionResult> SendCode(SendCode model)
        {
            if (!_accessor.ActionContext.ModelState.IsValid)
            {
                return(new OkResult());
            }

            var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();

            if (user == null)
            {
                return(new OkObjectResult("Error"));
            }

            if (model.SelectedProvider == "Authenticator")
            {
                return(new RedirectToActionResult(nameof(VerifyAuthenticatorCode), new { ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe }));
            }

            // Generate the token and send it
            var code = await _userManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider);

            if (string.IsNullOrWhiteSpace(code))
            {
                return(new OkObjectResult("Error"));
            }

            var message = "Your security code is: " + code;

            if (model.SelectedProvider == "Email")
            {
                await _emailSender.SendEmailAsync(await _userManager.GetEmailAsync(user), "Security Code", message);
            }
            else if (model.SelectedProvider == "Phone")
            {
                await _smsSender.SendSmsAsync(await _userManager.GetPhoneNumberAsync(user), message);
            }

            return(new RedirectToActionResult(nameof(VerifyCode), new { Provider = model.SelectedProvider, ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe }));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var code = await _userManager.GenerateChangePhoneNumberTokenAsync(user, Input.PhoneNumber);

            await _smsSender.SendSmsAsync(Input.PhoneNumber, "Your security code is: " + code);

            PendingVerification = true;
            InternalPhoneNumber = Input.PhoneNumber;
            StatusMessage       = "A verification code has been sent to you phone number";
            return(Page());
        }
示例#17
0
        public async Task <IActionResult> SendCode(SendCodeViewModel model)
        {
            var theme = SiteSettings.Value.Theme;

            ViewData["CssPath"] = "css/" + theme.Module + "/" + theme.Selected + "/";
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var user = await SignInManager.GetTwoFactorAuthenticationUserAsync();

            if (user == null)
            {
                return(View("Error"));
            }

            // Generate the token and send it
            var code = await UserManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider);

            if (string.IsNullOrWhiteSpace(code))
            {
                return(View("Error"));
            }

            var message = "Your security code is: " + code;

            if (model.SelectedProvider == "Email")
            {
                await EmailSender.SendEmailAsync(await UserManager.GetEmailAsync(user), "Security Code", message);
            }
            else if (model.SelectedProvider == "Phone")
            {
                await SmsSender.SendSmsAsync(await UserManager.GetPhoneNumberAsync(user), message);
            }

            return(RedirectToAction(nameof(VerifyCode), new { Provider = model.SelectedProvider, ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe }));
        }
示例#18
0
        public async Task <IActionResult> SendCode(SendCodeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();

            if (user == null)
            {
                return(View("Error"));
            }

            // Generate the token and send it
            var code = await _userManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider);

            if (string.IsNullOrWhiteSpace(code))
            {
                return(View("Error"));
            }

            var message =
                "Hi, my name is Istvan.\nThanks for setting up 2FA.\nInsert the following code: " +
                code + "\nAnd enjoy my App!";

            if (model.SelectedProvider == "Email")
            {
                await _emailSender.SendEmailAsync(await _userManager.GetEmailAsync(user), "Security Code", message);
            }
            else if (model.SelectedProvider == "Phone")
            {
                await _smsSender.SendSmsAsync(await _userManager.GetPhoneNumberAsync(user), message);
            }

            return(RedirectToAction(nameof(VerifyCode),
                                    new { Provider = model.SelectedProvider, model.ReturnUrl, model.RememberMe }));
        }
示例#19
0
        public async Task <IActionResult> AddPhoneNumber(AddPhoneNumberViewModel model)
        {
            var modelLoai = _context.loais.ToList();

            ViewBag.model = modelLoai;

            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByNameAsync(User.Identity.Name);

                if (user == null)
                {
                    return(NotFound());
                }
                var code = await _userManager.GenerateChangePhoneNumberTokenAsync(user, model.PhoneNumber);

                await _smsSender.SendSmsAsync(model.PhoneNumber, "Your security code is: " + code);

                return(RedirectToAction(nameof(VerifyPhoneNumber), new { model.PhoneNumber }));
            }

            return(View(model));
        }
        public async Task <IActionResult> AddPhoneNumbers(AddPhoneNumberViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Json(new { success = false, msg = "Invalid model." }));
                }
                // Generate the token and send it
                var user = await GetCurrentUserAsync();

                var code = await _userManager.GenerateChangePhoneNumberTokenAsync(user, model.PhoneNumber);

                await _smsSender.SendSmsAsync(model.PhoneNumber, "Your security code is: " + code);

                // return RedirectToAction("VerifyPhoneNumber", "VerifyPhoneNumber", new { PhoneNumber = model.PhoneNumber });
                return(Json(new { success = true, msg = "Phone number added." }));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, msg = ex.ToString() }));
            }
        }
        private async Task SendSmsAndWebNotifications(ServiceRequest serviceRequest)
        {
            // Send SMS Notification
            var phoneNumber = (await _userManager.FindByEmailAsync(serviceRequest.PartitionKey)).PhoneNumber;

            if (!string.IsNullOrWhiteSpace(phoneNumber))
            {
                await _smsSender.SendSmsAsync(string.Format("+91{0}", phoneNumber),
                                              string.Format("Service Request Status updated to {0}", serviceRequest.Status));
            }

            // Get Customer name
            var customerName = (await _userManager.FindByEmailAsync(serviceRequest.PartitionKey)).UserName;

            // Send web notifications
            _signalRConnectionManager.GetHubContext <ServiceMessagesHub>()
            .Clients
            .User(customerName)
            .publishNotification(new
            {
                status = serviceRequest.Status
            });
        }
示例#22
0
        public async Task <IActionResult> OnPostAsync(bool rememberMe, string returnUrl = null)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            returnUrl = returnUrl ?? Url.Content("~/");

            var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();

            if (user == null)
            {
                throw new InvalidOperationException($"Unable to load two-factor authentication user.");
            }

            // Generate the token and send it
            var code = await _userManager.GenerateTwoFactorTokenAsync(user, Input.Provider);

            if (string.IsNullOrWhiteSpace(code))
            {
                throw new InvalidOperationException($"Unable to generate login code for two factor authentication via {Input.Provider}");
            }

            var message = "Hi, Your security code to login into WRLDC dashboard portal is " + code;

            if (Input.Provider == "Email")
            {
                await _emailSender.SendEmailAsync(await _userManager.GetEmailAsync(user), "Security Code to login into WRLDC dashboard portal", message);
            }
            else if (Input.Provider == "Phone")
            {
                await _smsSender.SendSmsAsync(await _userManager.GetPhoneNumberAsync(user), message);
            }

            return(RedirectToPage("./VerifyCode", new { Provider = Input.Provider, ReturnUrl = returnUrl, RememberMe = rememberMe }));
        }
        public async Task <IActionResult> SendCode([FromBody] SendCodeDto model)
        {
            var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();

            if (user == null)
            {
                return(NotFound());
            }

            // Generate the token and send it
            var code = await _userManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider);

            if (string.IsNullOrWhiteSpace(code))
            {
                return(NotFound());
            }

            var message  = "Your security code is: " + code;
            var response = string.Empty;

            switch (model.SelectedProvider)
            {
            case "Email":
                await _emailSender.SendEmailAsync(await _userManager.GetEmailAsync(user), "Security Code", message);

                response = "An email has been sent to confirm your account";
                break;

            case "Phone":
                await _smsSender.SendSmsAsync(await _userManager.GetPhoneNumberAsync(user), message);

                response = "An sms has been sent to confirm your account";
                break;
            }

            return(Ok(response));
        }
示例#24
0
        public async Task <IActionResult> SendCode([FromBody] SendCodeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetModelErrors()));
            }

            var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();

            if (user == null)
            {
                return(BadRequest("Error"));
            }

            // Generate the token and send it
            var code = await _userManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider);

            if (string.IsNullOrWhiteSpace(code))
            {
                return(BadRequest("Error"));
            }

            var message = "Your security code is: " + code;

            if (model.SelectedProvider == "Email")
            {
                await _emailSender.SendEmailAsync(MailType.SecurityCode, new EmailModel { }, null);

                //await _emailSender.SendEmailAsync(Email, await _userManager.GetEmailAsync(user), "Security Code", message);
            }
            else if (model.SelectedProvider == "Phone")
            {
                await _smsSender.SendSmsAsync(await _userManager.GetPhoneNumberAsync(user), message);
            }

            return(RedirectToAction(nameof(VerifyCode), new { Provider = model.SelectedProvider, ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe }));
        }
示例#25
0
        public async Task <IActionResult> SendCode(SendCodeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            // Require that the user has already logged in via username/password or external login
            var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();

            if (user == null)
            {
                return(View("Error"));
            }

            // Generate the token and send it
            var code = await _userManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider);

            if (string.IsNullOrWhiteSpace(code))
            {
                return(View("Error"));
            }

            var message = T["Your security code is: {0}", code];

            if (model.SelectedProvider == "Email")
            {
                var e = await _userManager.GetEmailAsync(user);

                await _emailSender.SendEmailAsync(e, T["Security Code"], message);
            }
            else if (model.SelectedProvider == "Phone")
            {
                await _smsSender.SendSmsAsync(await _userManager.GetPhoneNumberAsync(user), message);
            }

            return(RedirectToAction(nameof(VerifyCode), new { Provider = model.SelectedProvider, ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe }));
        }
        public async Task <IActionResult> Index(string id)
        {
            var user = await _userManager.FindByIdAsync(id).ConfigureAwait(true);

            if (user != null)
            {
                user.RequestAccept = true;
            }
            var result = _userManager.UpdateAsync(user).Result;

            if (result.Succeeded)
            {
                await _emailSender.SendEmailAsync(user.Email, "Account Acceptance Mail",
                                                  $"Your Accunt Has been Accepted Successfuly...Now you can use Your Buisness Account")
                .ConfigureAwait(true);

                await _msSender.SendSmsAsync(user.PhoneNumber, "Your Accunt Has been Accepted Successfuly.." +
                                             ".Now you can use Your Buisness Account").ConfigureAwait(true);

                return(RedirectToAction("Accept", "RequestAccept"));
            }

            return(View());
        }
示例#27
0
        /// <summary>
        /// 两步注册
        /// 第一步,发送短信或者邮箱
        /// </summary>
        /// <param name="tokenProvider">TokenOptions.DefaultEmailProvider|| TokenOptions.DefaultPhoneProvider</param>
        /// <param name="tokenID">手机号码或者是邮箱</param>
        /// <returns></returns>
        public async Task <bool> TwoFactorSendCode(string tokenProvider, string tokenID)
        {
            var user = CreateUserByTokenProvider(tokenProvider, tokenID);
            //手机+密码+验证码   || 邮箱+密码+验证码
            var code = await _userManager.GenerateTwoFactorTokenAsync(user, tokenProvider);

            if (string.IsNullOrWhiteSpace(code))
            {
                return(false);
            }

            var message = "Your security code is: " + code;

            if (tokenProvider == TokenOptions.DefaultEmailProvider)
            {
                await _emailSender.SendEmailAsync(await _userManager.GetEmailAsync(user), "Security Code", message);
            }
            else if (tokenProvider == TokenOptions.DefaultPhoneProvider)
            {
                await _smsSender.SendSmsAsync(await _userManager.GetPhoneNumberAsync(user), message);
            }

            return(true);
        }
示例#28
0
        public async Task <IActionResult> SendCodeAsync(SendCodeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();

            if (user == null)
            {
                return(View("Error"));
            }

            // Generate the token and send it
            var code = await _userManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider);

            if (string.IsNullOrWhiteSpace(code))
            {
                return(View("Error"));
            }
            var orgId = await GetOrganizationFromUrl();

            var message = "Your security code is: " + code;

            if (model.SelectedProvider == "Email")
            {
                await _emailService.SendEmailAsync(orgId, await _userManager.GetEmailAsync(user), "Security Code", message);
            }
            else if (model.SelectedProvider == "Phone")
            {
                await _smsSender.SendSmsAsync(await _userManager.GetPhoneNumberAsync(user), message);
            }

            return(RedirectToAction(nameof(VerifyCodeAsync), new { Provider = model.SelectedProvider, ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe }));
        }
示例#29
0
        public async Task <IActionResult> OnPostSendVerificationPhone()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            var userId = await _userManager.GetUserIdAsync(user);

            var phoneNumber = await _userManager.GetPhoneNumberAsync(user);

            var code = await _userManager.GenerateChangePhoneNumberTokenAsync(user, phoneNumber);

            try
            {
                await _smsSender.SendSmsAsync(
                    phoneNumber,
                    $"Confirm your phone number. #{Environment.NewLine} Verification code: #{code}");
            }
            catch (Exception ex)
            {
                // logger.Push(ex.Message)
                throw;
            }
            StatusMessage     = "Verification code sent. Please check your sms.";
            isPhoneVerifyCode = true;

            return(Page());
        }
示例#30
0
 public static Task SendSmsAsync([NotNull] this ISmsSender smsSender, [NotNull] string phoneNumber, [NotNull] string text)
 {
     Check.NotNull(smsSender, nameof(smsSender));
     return(smsSender.SendSmsAsync(new SmsMessage(phoneNumber, text)));
 }