feat: add user management, refs NOISSUE
This commit is contained in:
@@ -10,7 +10,8 @@ public class ConfigurationAD
|
||||
|
||||
public string LDAPserver { get; set; } = string.Empty;
|
||||
public string LDAPQueryBase { get; set; } = string.Empty;
|
||||
public string LDAPUserQueryBase { get; set; } = string.Empty;
|
||||
|
||||
public string Crew { get; set; } = string.Empty;
|
||||
public string Managers { get; set; } = string.Empty;
|
||||
public string CrewGroup { get; set; } = string.Empty;
|
||||
public string ManagerGroup { get; set; } = string.Empty;
|
||||
}
|
4
song_of_the_day/Auth/IAuthenticationService.cs
Normal file
4
song_of_the_day/Auth/IAuthenticationService.cs
Normal file
@@ -0,0 +1,4 @@
|
||||
public interface IAuthenticationService
|
||||
{
|
||||
bool Authenticate(string userName, string password);
|
||||
}
|
15
song_of_the_day/Auth/LdapAuthenticationService.cs
Normal file
15
song_of_the_day/Auth/LdapAuthenticationService.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
public class LdapAuthenticationService : IAuthenticationService
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public LdapAuthenticationService(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public bool Authenticate(string username, string password)
|
||||
{
|
||||
var ldapInstance = LdapIntegration.Instance;
|
||||
return ldapInstance.TestLogin(username, password);
|
||||
}
|
||||
}
|
58
song_of_the_day/Auth/PhoneClaimCodeProviderService.cs
Normal file
58
song_of_the_day/Auth/PhoneClaimCodeProviderService.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
public class PhoneClaimCodeProviderService
|
||||
{
|
||||
private Dictionary<string, string> _phoneClaimCodes;
|
||||
private Dictionary<string, string> _phoneClaimNumbers;
|
||||
|
||||
public PhoneClaimCodeProviderService()
|
||||
{
|
||||
_phoneClaimCodes = new Dictionary<string, string>();
|
||||
_phoneClaimNumbers = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
private static Random random = new Random();
|
||||
|
||||
private static string RandomString(int length)
|
||||
{
|
||||
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
return new string(Enumerable.Repeat(chars, length)
|
||||
.Select(s => s[random.Next(s.Length)]).ToArray());
|
||||
}
|
||||
|
||||
public void GenerateClaimCodeForUserAndNumber(string username, string phoneNumber)
|
||||
{
|
||||
var generatedCode = string.Empty;
|
||||
if (IsCodeGeneratedForUser(username))
|
||||
{
|
||||
generatedCode = _phoneClaimCodes[username];
|
||||
}
|
||||
else
|
||||
{
|
||||
generatedCode = RandomString(6);
|
||||
_phoneClaimCodes[username] = generatedCode;
|
||||
_phoneClaimNumbers[username] = phoneNumber;
|
||||
}
|
||||
|
||||
SignalIntegration.Instance.SendMessageToUserAsync("Your phone number validation code is: " + generatedCode, phoneNumber);
|
||||
}
|
||||
|
||||
public string ValidateClaimCodeForUser(string code, string username)
|
||||
{
|
||||
var result = false;
|
||||
result = _phoneClaimCodes[username] == code;
|
||||
|
||||
if (result)
|
||||
{
|
||||
_phoneClaimCodes.Remove(username);
|
||||
var number = _phoneClaimNumbers[username];
|
||||
_phoneClaimNumbers.Remove(username);
|
||||
return number;
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public bool IsCodeGeneratedForUser(string username)
|
||||
{
|
||||
return _phoneClaimCodes.ContainsKey(username);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user