gtb: pwd change, register

This commit is contained in:
Stoyan Zlatev
2024-02-20 12:17:07 +01:00
parent a90459f5d4
commit 3110e3a051
72 changed files with 1927 additions and 981 deletions
@@ -30,6 +30,18 @@
this.softwareRepository = LaaServiceProvider.GetService<ISoftwareRepository>();
}
public bool ChangePassword(string password, string bearer)
{
var tokenData = this.employeesRepository.GetTokenData(bearer);
if (tokenData is null)
{
return false;
}
return this.employeesRepository.SetPassword(tokenData.EmployeeId, password);
}
public IPrincipal GetClaimsPrincipal(string token)
{
var claimsIdentity = anonymous;
@@ -75,8 +87,10 @@
return new ClaimsPrincipal(claimsIdentity);
}
public string Login(LDAPLoginModel model)
public bool? Login(LDAPLoginModel model, out string bearer)
{
bearer = default(string);
var softwareId = this.GetOrCreateSoftwareId(
model.Assembly,
model.MajorV,
@@ -85,39 +99,19 @@
if (softwareId <= 0)
{
return default(string);
return false;
}
var employeeNr = this.employeesRepository.FindEmployeeNr(model.EmployeeId);
//if (employeeNr <= 0)
//{
// employeeNr = this.employeesRepository.Update(
// model.EmployeeId,
// model.FirstName,
// model.LastName,
// model.Phone,
// model.Username,
// model.Email);
// if (employeeNr <= 0)
// {
// employeeNr = this.employeesRepository.Insert(
// model.EmployeeId,
// model.FirstName,
// model.LastName,
// model.Phone,
// model.Username,
// model.Email);
// }
//}
if (employeeNr <= 0)
{
return default(string);
return null;
}
return this.GetOrCreateAuthToken(softwareId, employeeNr);
bearer = this.GetOrCreateAuthToken(softwareId, employeeNr);
return true;
}
public string Login(UserLoginModel model)
@@ -180,5 +174,48 @@
return token;
}
public bool? Register(LDAPRegisterModel model, out string bearer)
{
bearer = default(string);
var softwareId = this.GetOrCreateSoftwareId(
model.Assembly,
model.MajorV,
model.MinorV,
model.BuildV);
if (softwareId <= 0)
{
return false;
}
var employeeNr = this.employeesRepository.Update(
model.EmployeeId,
model.FirstName,
model.LastName,
model.Phone,
model.Email,
model.Username,
model.DomainName,
model.Password);
if (employeeNr <= 0)
{
employeeNr = this.employeesRepository.Insert(
model.EmployeeId,
model.FirstName,
model.LastName,
model.Phone,
model.Email,
model.Username,
model.DomainName,
model.Password);
}
bearer = this.GetOrCreateAuthToken(softwareId, employeeNr);
return true;
}
}
}
@@ -6,14 +6,18 @@
public interface IAccountManager
{
bool ChangePassword(string password, string bearer);
IPrincipal GetClaimsPrincipal(string token);
string Login(LDAPLoginModel model);
bool? Login(LDAPLoginModel model, out string bearer);
string Login(UserLoginModel model);
void ResetPassword(short employeeId);
void SetPassword(short employeeId, string password);
bool? Register(LDAPRegisterModel model, out string bearer);
}
}
@@ -163,7 +163,7 @@
.SetParameter(nameof(token), token)
.ExecuteReader(x => x.GetString());
public short Insert(int employeeId, string firstName, string lastName, string phone, string username, string email)
public short Insert(int employeeId, string firstName, string lastName, string phone, string email, string username, string domainname, string password)
=> this.sqlConnection
.CreateCommand($@"
INSERT INTO [Mitarbeiter] (
@@ -175,7 +175,8 @@
, [Benutzername]
, [AnlageDatum]
, [eMail]
, [DomainUser])
, [DomainUser]
, [PasswordHash])
OUTPUT [inserted].[MitarbeiterNr]
VALUES ((SELECT MAX([MitarbeiterNr]) + 1 FROM [Mitarbeiter])
, @{nameof(employeeId)}
@@ -185,13 +186,16 @@
, @{nameof(username)}
, GETDATE()
, @{nameof(email)}
, @{nameof(username)})")
, @{nameof(domainname)}
, @{nameof(password)})")
.SetParameter(nameof(employeeId), employeeId)
.SetParameter(nameof(firstName), firstName)
.SetParameter(nameof(lastName), lastName)
.SetParameter(nameof(phone), phone)
.SetParameter(nameof(username), username)
.SetParameter(nameof(email), email)
.SetParameter(nameof(username), username)
.SetParameter(nameof(domainname), domainname)
.SetParameter(nameof(password), password)
.ExecuteScalar(x => x.GetSmallint());
public void ResetPassword(short employeeId)
@@ -211,7 +215,7 @@
.SetParameter(nameof(employeeId), employeeId)
.ExecuteNonQuery();
public void SetPassword(short employeeId, string password)
public bool SetPassword(short employeeId, string password)
=> this.sqlConnection
.CreateCommand($@"
UPDATE [Mitarbeiter]
@@ -219,16 +223,18 @@
WHERE [MitarbeiterNr] = @{nameof(employeeId)}")
.SetParameter(nameof(employeeId), employeeId)
.SetParameter(nameof(password), password)
.ExecuteNonQuery();
.ExecuteNonQuery() == 1;
public short Update(int employeeId, string firstName, string lastName, string phone, string username, string email)
public short Update(int employeeId, string firstName, string lastName, string phone, string email, string username, string domainname, string password)
=> this.sqlConnection
.CreateCommand($@"
UPDATE [Mitarbeiter]
SET [EmployeeId] = ISNULL(@{nameof(employeeId)}, [EmployeeId])
, [eMail] = ISNULL(@{nameof(email)}, [eMail])
, [Telefon] = ISNULL(@{nameof(phone)}, [Telefon])
, [DomainUser] = ISNULL(@{nameof(username)}, [DomainUser])
SET [EmployeeId] = ISNULL(@{nameof(employeeId)} , [EmployeeId])
, [eMail] = ISNULL(@{nameof(email)} , [eMail])
, [Telefon] = ISNULL(@{nameof(phone)} , [Telefon])
, [Benutzername] = ISNULL(@{nameof(username)} , [Benutzername])
, [DomainUser] = ISNULL(@{nameof(domainname)} , [DomainUser])
, [PasswordHash] = ISNULL(@{nameof(password)} , [PasswordHash])
OUTPUT [inserted].[MitarbeiterNr]
WHERE [Vorname] = @{nameof(firstName)}
AND [Name] = @{nameof(lastName)}
@@ -237,8 +243,10 @@
.SetParameter(nameof(firstName), firstName)
.SetParameter(nameof(lastName), lastName)
.SetParameter(nameof(phone), phone)
.SetParameter(nameof(username), username)
.SetParameter(nameof(email), email)
.SetParameter(nameof(username), username)
.SetParameter(nameof(domainname), domainname)
.SetParameter(nameof(password), password)
.ExecuteScalar(x => x.GetSmallint());
}
}
@@ -24,14 +24,14 @@
IEnumerable<string> GetUserRoles(string token);
short Insert(int employeeId, string firstName, string lastName, string phone, string username, string email);
short Insert(int employeeId, string firstName, string lastName, string phone, string email, string username, string domainname, string password);
void ResetPassword(short employeeId);
void ResetTokens(short employeeId);
void SetPassword(short employeeId, string password);
bool SetPassword(short employeeId, string password);
short Update(int employeeId, string firstName, string lastName, string phone, string username, string email);
short Update(int employeeId, string firstName, string lastName, string phone, string email, string username, string domainname, string password);
}
}