-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathOtpAppService.cs
More file actions
83 lines (71 loc) · 2.8 KB
/
Copy pathOtpAppService.cs
File metadata and controls
83 lines (71 loc) · 2.8 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System.Threading.Tasks;
using Abp.Dependency;
using Microsoft.AspNetCore.Mvc;
using Shesha.Configuration.Security.Frontend;
using Shesha.Otp.Configuration;
using Shesha.Otp.Dto;
namespace Shesha.Otp
{
public class OtpAppService : SheshaAppServiceBase, IOtpAppService, ITransientDependency
{
private readonly IUserManagementSettings _userManagementSettings;
private readonly IOtpManager _otpManager;
public OtpAppService(IOtpManager otpManager, IUserManagementSettings userManagementSettings)
{
_otpManager = otpManager;
_userManagementSettings = userManagementSettings;
}
/// <summary>
/// Send one-time-pin
/// </summary>
public async Task<ISendPinResponse> SendPinAsync(SendPinInput input)
{
return await _otpManager.SendPinAsync(input);
}
/// <summary>
/// Resend one-time-pin
/// </summary>
public async Task<ISendPinResponse> ResendPinAsync(ResendPinInput input)
{
return await _otpManager.ResendPinAsync(input);
}
/// <summary>
/// Verify one-time-pin
/// </summary>
public async Task<IVerifyPinResponse> VerifyPinAsync(VerifyPinInput input)
{
return await _otpManager.VerifyPinAsync(input);
}
/// inheritDoc
[HttpPost]
public async Task<bool> UpdateSettingsAsync(OtpSettingsDto input)
{
await _userManagementSettings.DefaultAuthentication.SetValueAsync(new DefaultAuthenticationSettings
{
PasswordLength = input.PasswordLength,
Alphabet = input.Alphabet,
DefaultLifetime = input.DefaultLifetime,
IgnoreOtpValidation = input.IgnoreOtpValidation,
DefaultEmailBodyTemplate = input.EmailBodyTemplate,
DefaultEmailSubjectTemplate = input.EmailSubject,
});
return true;
}
/// inheritDoc
[HttpGet]
public async Task<OtpSettingsDto> GetSettingsAsync()
{
var emailSettings = await _userManagementSettings.DefaultAuthentication.GetValueAsync();
var settings = new OtpSettingsDto
{
PasswordLength = emailSettings.PasswordLength,
Alphabet = emailSettings.Alphabet,
DefaultLifetime = emailSettings.DefaultLifetime,
IgnoreOtpValidation = emailSettings.IgnoreOtpValidation,
EmailSubject = emailSettings.DefaultEmailSubjectTemplate,
EmailBodyTemplate = emailSettings.DefaultEmailBodyTemplate,
};
return settings;
}
}
}