-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSmsFlow.cs
More file actions
55 lines (46 loc) · 1.45 KB
/
Copy pathSmsFlow.cs
File metadata and controls
55 lines (46 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
namespace Cleipnir.Flows.Sample.Presentation.F_SmsVerificationFlow;
public enum MostRecentAttempt
{
NotStarted,
CodeExpired,
IncorrectCode,
Success,
MaxAttemptsExceeded
}
public record CodeFromUser(string CustomerPhoneNumber, string Code, DateTime Timestamp);
public class SmsFlow : Flow<string, MostRecentAttempt>
{
public override async Task<MostRecentAttempt> Run(string customerPhoneNumber)
{
for (var i = 0; i < 5; i++)
{
var generatedCode = await Effect.Capture(
$"SendSms#{i}",
async () =>
{
var generatedCode = GenerateOneTimeCode();
await SendSms(customerPhoneNumber, generatedCode);
return generatedCode;
}
);
var codeFromUser = await Message<CodeFromUser>();
if (IsExpired(codeFromUser))
continue; // CodeExpired - try again
else if (codeFromUser.Code == generatedCode)
return MostRecentAttempt.Success;
}
return MostRecentAttempt.MaxAttemptsExceeded;
}
private string GenerateOneTimeCode()
{
throw new NotImplementedException();
}
private Task SendSms(string customerPhoneNumber, string generatedCode)
{
throw new NotImplementedException();
}
private bool IsExpired(CodeFromUser code)
{
throw new NotImplementedException();
}
}