Skip to content

Commit

Permalink
Initial New User Email Not Sending At Time of Creation (dnnsoftware#2492
Browse files Browse the repository at this point in the history
)

This is alternative way to fix above issue proposed in dnnsoftware/Dnn.AdminExperience#174

As per @sleupold , we need to move email notifications from UI to core part.
Once this will be approved and merged, we can remove email notifications from UI and replace it with updated controller method to let notifications to be send to their recipients.

fixes dnnsoftware#2424
  • Loading branch information
mikebigun authored and zyhfish committed Mar 29, 2019
1 parent c6d86e0 commit 2786657
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 4 deletions.
1 change: 1 addition & 0 deletions DNN Platform/Library/DotNetNuke.Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
<Compile Include="Entities\Users\IFriendshipEventHandlers.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Entities\Users\UserRegistrationEmailNotifier.cs" />
<Compile Include="Obsolete\PortalSettings.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Collections\CollectionExtensions.cs" />
Expand Down
16 changes: 15 additions & 1 deletion DNN Platform/Library/Entities/Users/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,20 @@ public static void CopyUserToPortal(UserInfo user, PortalInfo destinationPortal,
/// <returns>The Created status ot the User</returns>
/// -----------------------------------------------------------------------------
public static UserCreateStatus CreateUser(ref UserInfo user)
{
return CreateUser(ref user, false);
}

/// -----------------------------------------------------------------------------
/// <summary>
/// Creates a new User in the Data Store
/// </summary>
/// <remarks></remarks>
/// <param name="user">The userInfo object to persist to the Database</param>
/// <param name="sendEmailNotification">The sendEmailNotification flag defines whether registration email will be sent to user</param>
/// <returns>The Created status ot the User</returns>
/// -----------------------------------------------------------------------------
public static UserCreateStatus CreateUser(ref UserInfo user, bool sendEmailNotification)
{
int portalId = user.PortalID;
user.PortalID = GetEffectivePortalId(portalId);
Expand All @@ -976,7 +990,7 @@ public static UserCreateStatus CreateUser(ref UserInfo user)
AutoAssignUsersToRoles(user, portalId);
}

EventManager.Instance.OnUserCreated(new UserEventArgs { User = user });
EventManager.Instance.OnUserCreated(new UserEventArgs { User = user, SendNotification = sendEmailNotification });
}

//Reset PortalId
Expand Down
13 changes: 10 additions & 3 deletions DNN Platform/Library/Entities/Users/UserEventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

using System.ComponentModel.Composition;
using System.Globalization;

using DotNetNuke.Entities.Portals;
using DotNetNuke.Services.Mail;
using DotNetNuke.Services.Social.Notifications;

Expand All @@ -38,6 +36,12 @@ public void UserAuthenticated(object sender, UserEventArgs args)

public void UserCreated(object sender, UserEventArgs args)
{
UserRegistrationEmailNotifier.NotifyAdministrator(args.User);

if (args.SendNotification)
{
UserRegistrationEmailNotifier.NotifyUser(args.User);
}
}

public void UserRemoved(object sender, UserEventArgs args)
Expand All @@ -51,7 +55,10 @@ public void UserDeleted(object sender, UserEventArgs args)

public void UserApproved(object sender, UserEventArgs args)
{
if (args.SendNotification) Mail.SendMail(args.User, MessageType.UserRegistrationPublic, PortalSettings.Current);
if (args.SendNotification)
{
UserRegistrationEmailNotifier.NotifyUser(args.User, MessageType.UserRegistrationPublic);
}
DeleteAllNewUnauthorizedUserRegistrationNotifications(args.User.UserID);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Services.Mail;
using static DotNetNuke.Common.Globals;

namespace DotNetNuke.Entities.Users
{
public class UserRegistrationEmailNotifier
{
public UserRegistrationEmailNotifier()
{
}

public static void NotifyAdministrator(UserInfo user)
{
// avoid self-notification (i.e. on site installation/super user creation)
var currentUser = UserController.Instance.GetCurrentUserInfo();
if (currentUser != null && (currentUser.UserID == Null.NullInteger || currentUser.UserID == user.UserID))
{
return;
}

//send notification to portal administrator of new user registration
//check the receive notification setting first, but if register type is Private, we will always send the notification email.
//because the user need administrators to do the approve action so that he can continue use the website.
if (PortalSettings.Current.EnableRegisterNotification || PortalSettings.Current.UserRegistration == (int)Globals.PortalRegistrationType.PrivateRegistration)
{
NotifyUser(user, MessageType.UserRegistrationAdmin);
}
}

public static void NotifyUser(UserInfo user)
{
switch (PortalSettings.Current.UserRegistration)
{
case (int)PortalRegistrationType.PrivateRegistration:
NotifyUser(user, MessageType.UserRegistrationPrivate);
break;
case (int)PortalRegistrationType.PublicRegistration:
NotifyUser(user, MessageType.UserRegistrationPublic);
break;
case (int)PortalRegistrationType.VerifiedRegistration:
NotifyUser(user, MessageType.UserRegistrationVerified);
break;
case (int)PortalRegistrationType.NoRegistration:
NotifyUser(user, MessageType.UserRegistrationPublic);
break;
}
}

public static void NotifyUser(UserInfo user, MessageType type)
{
Mail.SendMail(user, type, PortalSettings.Current);
}
}
}

0 comments on commit 2786657

Please sign in to comment.