Skip to content

Commit

Permalink
Merge pull request #51 from intelequia/fix/47
Browse files Browse the repository at this point in the history
Fix #47: LastLoginDate not being updated on aspnet_membership
  • Loading branch information
davidjrh authored Aug 14, 2024
2 parents 2404a25 + 67b0070 commit 5de9c26
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .build/ModulePackage.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<MSBuildDnnBinPath Condition="'$(MSBuildDnnBinPath)' == ''">$(MSBuildProjectDirectory)\bin</MSBuildDnnBinPath>
</PropertyGroup>

<Target Name="PackageModule" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Target Name="PackageModule" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' or '$(Configuration)|$(Platform)' == 'Release Legacy|AnyCPU' ">
<XmlRead Prefix="n"
Namespace="http://schemas.microsoft.com/developer/msbuild/2003"
XPath="dotnetnuke/packages/package[1]/@version"
Expand Down
16 changes: 15 additions & 1 deletion DotNetNuke.Authentication.Azure.B2C/Components/AzureClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
using System.Threading;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Security;
using static DotNetNuke.Services.Authentication.AuthenticationLoginBase;

#endregion
Expand Down Expand Up @@ -781,11 +782,24 @@ private static void EnsureIdentitySourceProfilePropertyDefinitionExists(int port

private void UpdateUserAndRoles(UserInfo userInfo)
{
// Reset user password with a new one to avoid password expiration errors on DNN for Azure AD users
MembershipUser aspnetUser = Membership.GetUser(userInfo.Username);
aspnetUser.ResetPassword();

// Last login date not being updated by DNN on OAuth login, so we have to do it manually
aspnetUser = Membership.GetUser(userInfo.Username);
aspnetUser.LastLoginDate = DateTime.Now;
Membership.UpdateUser(aspnetUser);

// Updates the user in DNN
userInfo.Membership.LastLoginDate = aspnetUser.LastLoginDate;
userInfo.Membership.UpdatePassword = false;
if (Settings.AutoAuthorize && !userInfo.Membership.Approved && IsCurrentUserAuthorized())
{
userInfo.Membership.Approved = true; // Delegate approval on Auth Provider
UserController.UpdateUser(userInfo.PortalID, userInfo);
}
UserController.UpdateUser(userInfo.PortalID, userInfo);

UpdateUserRoles(JwtIdToken.Claims.First(c => c.Type == "sub").Value, userInfo);
UpdateUserProfilePicture(JwtIdToken.Claims.First(c => c.Type == "sub").Value, userInfo, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release Legacy|AnyCPU'">
<OutputPath>bin\Release Legacy\</OutputPath>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>1591</NoWarn>
Expand Down Expand Up @@ -398,7 +398,7 @@
<Error Condition="!Exists('..\DotNetNuke.Authentication.Azure.B2C\packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\DotNetNuke.Authentication.Azure\packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets'))" />
</Target>
<PropertyGroup>
<PostBuildEvent>IF "$(ConfigurationName)"=="Debug" copy $(TargetDir)$(TargetName).* c:\websites\b2c.dnndev.me\bin /Y</PostBuildEvent>
<PostBuildEvent>IF "$(ConfigurationName)"=="Debug" copy $(TargetDir)$(TargetName).* c:\websites\onlineportal.dnndev.me\bin /Y</PostBuildEvent>
</PropertyGroup>
<Import Project="..\.build\ModulePackage.Targets" />
<Import Project="..\DotNetNuke.Authentication.Azure.B2C\packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets" Condition="Exists('..\DotNetNuke.Authentication.Azure.B2C\packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets')" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Configuration;
using System.IO;
using System.Linq;
using System.Web.Security;

namespace DotNetNuke.Authentication.Azure.B2C.ScheduledTasks
{
Expand Down Expand Up @@ -345,9 +346,14 @@ private UserInfo UpdateUser(UserInfo user, int portalId, string userName, string
user.Email = eMail;
user.Profile.FirstName = firstName;
user.Profile.LastName = lastName;
user.Membership.UpdatePassword = false;

AuthenticationController.AddUserAuthentication(user.UserID, AzureConfig.ServiceName, userName);
UserController.UpdateUser(portalId, user);

// Updates the password to a new one to avoid password expiration on Azure AD B2C users
MembershipUser aspnetUser = Membership.GetUser(user.Username);
aspnetUser.ResetPassword();
return user;
}

Expand Down

0 comments on commit 5de9c26

Please sign in to comment.