Skip to content

Commit

Permalink
Merge branch 'main' into hishamco/issue-15805
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco authored Jan 25, 2025
2 parents 8c0fee5 + deccae0 commit 03c7a7d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 28 deletions.
10 changes: 3 additions & 7 deletions src/OrchardCore.Modules/OrchardCore.Sms/Activities/SmsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,9 @@ public override IEnumerable<Outcome> GetPossibleOutcomes(WorkflowExecutionContex

public override async Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
{
var message = new SmsMessage
{
To = await _expressionEvaluator.EvaluateAsync(PhoneNumber, workflowContext, null),
Body = await _expressionEvaluator.EvaluateAsync(Body, workflowContext, null),
};

var result = await _smsService.SendAsync(message);
var result = await _smsService.SendAsync(
await _expressionEvaluator.EvaluateAsync(PhoneNumber, workflowContext, null),
await _expressionEvaluator.EvaluateAsync(Body, workflowContext, null));

workflowContext.LastResult = result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,7 @@ public async Task<IActionResult> IndexPost(RequestCodeSmsAuthenticatorViewModel
var code = await UserManager.GenerateChangePhoneNumberTokenAsync(user, phoneNumber);
var smsSettings = await SiteService.GetSettingsAsync<SmsAuthenticatorLoginSettings>();

var message = new SmsMessage()
{
To = phoneNumber,
Body = await GetBodyAsync(smsSettings, user, code),
};

var result = await _smsService.SendAsync(message);
var result = await _smsService.SendAsync(phoneNumber, await GetBodyAsync(smsSettings, user, code));

if (!result.Succeeded)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,9 @@ private static async Task<IResult> HandleAsync<T>(
var settings = await siteService.GetSettingsAsync<SmsAuthenticatorLoginSettings>();
var code = await userManager.GenerateTwoFactorTokenAsync(user, identityOptions.Value.Tokens.ChangePhoneNumberTokenProvider);

var message = new SmsMessage()
{
To = await userManager.GetPhoneNumberAsync(user),
Body = await GetBodyAsync(settings, user, code, liquidTemplateManager, htmlEncoder),
};

var result = await smsService.SendAsync(message);
var result = await smsService.SendAsync(
await userManager.GetPhoneNumberAsync(user),
await GetBodyAsync(settings, user, code, liquidTemplateManager, htmlEncoder));

return TypedResults.Ok(new
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace OrchardCore.Sms;

/// <summary>
/// Provides an extension methods for <see cref="ISmsService"/>.
/// </summary>
public static class SmsServiceExtensions
{
/// <summary>
/// Sends the specified message to an SMS server for delivery.
/// </summary>
/// <param name="smsService">The <see cref="ISmsService"/>.</param>
/// <param name="to">The phone number to send the message to.</param>
/// <param name="body">The body of the message to send.</param>
/// <returns></returns>
public static Task<SmsResult> SendAsync(this ISmsService smsService, string to, string body)
{
var message = new SmsMessage
{
To = to,
Body = body
};

return smsService.SendAsync(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@ public async Task<bool> TrySendAsync(object notify, INotificationMessage message
return false;
}

var smsMessage = new SmsMessage()
{
To = user.PhoneNumber,
Body = message.TextBody,
};

var result = await _smsService.SendAsync(smsMessage);
var result = await _smsService.SendAsync(user.PhoneNumber, message.TextBody);

return result.Succeeded;
}
Expand Down

0 comments on commit 03c7a7d

Please sign in to comment.