Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions DigitalLearningSolutions.Data/DataServices/LoginDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
public interface ILoginDataService
{
void UpdateLastAccessedForUsersTable(int Id);

void UpdateLastAccessedForDelegatesAccountsTable(int Id);

void UpdateLastAccessedForAdminAccountsTable(int Id);
}

public class LoginDataService : ILoginDataService
Expand All @@ -29,5 +33,31 @@ public void UpdateLastAccessedForUsersTable(int Id)
}
);
}

public void UpdateLastAccessedForDelegatesAccountsTable(int Id)
{
connection.Execute(
@"UPDATE DelegateAccounts SET
LastAccessed = GetUtcDate()
WHERE ID = @Id",
new
{
Id
}
);
}

public void UpdateLastAccessedForAdminAccountsTable(int Id)
{
connection.Execute(
@"UPDATE AdminAccounts SET
LastAccessed = GetUtcDate()
WHERE ID = @Id",
new
{
Id
}
);
}
}
}
8 changes: 7 additions & 1 deletion DigitalLearningSolutions.Web/Controllers/LoginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,17 @@ int centreIdToLogInto
IsPersistent = rememberMe,
IssuedUtc = clockUtility.UtcNow,
};
var centreAccountSet = userEntity?.GetCentreAccountSet(centreIdToLogInto);

var adminAccount = userEntity!.GetCentreAccountSet(centreIdToLogInto)?.AdminAccount;
if (centreAccountSet?.DelegateAccount?.Id != null)
{
loginService.UpdateLastAccessedForDelegatesAccountsTable(centreAccountSet.DelegateAccount.Id);
}

var adminAccount = centreAccountSet?.AdminAccount;
if (adminAccount?.Active == true)
{
loginService.UpdateLastAccessedForAdminAccountsTable(adminAccount.Id);
sessionService.StartAdminSession(adminAccount.Id);
}

Expand Down
14 changes: 14 additions & 0 deletions DigitalLearningSolutions.Web/Services/LoginService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ List<int> idsOfCentresWithUnverifiedEmails

void UpdateLastAccessedForUsersTable(int Id);

void UpdateLastAccessedForDelegatesAccountsTable(int Id);

void UpdateLastAccessedForAdminAccountsTable(int Id);

Task<string> HandleLoginResult(
LoginResult loginResult,
TicketReceivedContext context,
Expand Down Expand Up @@ -59,6 +63,16 @@ public void UpdateLastAccessedForUsersTable(int Id)
loginDataService.UpdateLastAccessedForUsersTable(Id);
}

public void UpdateLastAccessedForDelegatesAccountsTable(int Id)
{
loginDataService.UpdateLastAccessedForDelegatesAccountsTable(Id);
}

public void UpdateLastAccessedForAdminAccountsTable(int Id)
{
loginDataService.UpdateLastAccessedForAdminAccountsTable(Id);
}

public LoginResult AttemptLogin(string username, string password)
{
var userEntity = userService.GetUserByUsername(username);
Expand Down
Loading