feat: add user management, refs NOISSUE

This commit is contained in:
2025-05-17 22:17:09 +02:00
parent 6b9c383697
commit efbbc915e5
17 changed files with 908 additions and 97 deletions

View File

@@ -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;
}

View File

@@ -0,0 +1,4 @@
public interface IAuthenticationService
{
bool Authenticate(string userName, string password);
}

View 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);
}
}

View 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);
}
}