private async Task <SendMessageResult> SendSmsMessage(long inputUserId, string inputPhoneNumber, string inputCountryPhoneCode) { var code = await UserManager.GenerateChangePhoneNumberTokenAsync(inputUserId, inputPhoneNumber); var result = await _twoFactorMessageService.SendSmsMessage(new IdentityMessage() { Body = "Your confirmation code is " + code, Destination = inputCountryPhoneCode + inputPhoneNumber, }); return(result); }
public async Task <JsonResult> Login(LoginViewModel loginModel, string returnUrl = "", string returnUrlHash = "") { CheckModelState(); var loginResult = await GetLoginResultAsync( loginModel.UsernameOrEmailAddress, loginModel.Password, loginModel.TenancyName ); if (loginResult.Result == AbpLoginResultType.UserEmailIsNotConfirmed) { var url = Url.Action("EmailNotConfirmed", new { userName = loginModel.UsernameOrEmailAddress }); return(Json(new AjaxResponse { TargetUrl = url })); } CheckAndConfirmTwoFactorProviders(loginResult.User); if (await IsNecessaryToSendSms(loginResult.User)) { const string smsProvider = "Sms"; var code = await _userManager.GenerateTwoFactorTokenAsync(loginResult.User.Id, smsProvider); var messageResult = await _twoFactorMessageService.SendSmsMessage(new IdentityMessage() { Body = code, Destination = loginResult.User.CountryPhoneCode + loginResult.User.PhoneNumber, Subject = LocalizationManager.GetString(LocalizationSourceName, "YourTwoFactorCode") }); if (messageResult.SendStatus == SendStatus.Fail) { throw new UserFriendlyException(L("SendMessageFailed")); } SetPhoneNumber(loginResult.User.PhoneNumber); var url = Url.Action("PhoneNumberVerification", new { returnUrl, userId = loginResult.User.Id, provider = smsProvider, }); return(Json(new AjaxResponse { TargetUrl = url })); } if (IsTwoFactorEnabled(loginResult.User) && IsEmailRequiredForLogin && IsEmailProviderEnabled) { SetEmail(loginResult.User.EmailAddress); const string emailProvider = "Email"; //Send email verification code var emailCode = await _userManager.GenerateTwoFactorTokenAsync(loginResult.User.Id, emailProvider); await _twoFactorMessageService.SendEmailMessage(new IdentityMessage() { Body = emailCode, Destination = loginResult.User.EmailAddress, Subject = LocalizationManager.GetString(LocalizationSourceName, "YourTwoFactorCode") }); var url = Url.Action("EmailVerification", new { returnUrl, userId = loginResult.User.Id, provider = emailProvider, }); return(Json(new AjaxResponse { TargetUrl = url })); } await SignInAsync(loginResult.User, loginResult.Identity, loginModel.RememberMe); if (string.IsNullOrWhiteSpace(returnUrl)) { returnUrl = Request.ApplicationPath; } if (!string.IsNullOrWhiteSpace(returnUrlHash)) { returnUrl = returnUrl + returnUrlHash; } return(Json(new AjaxResponse { TargetUrl = returnUrl })); }