When you hook into that, you will be able to cancel a member being created. This will allow you to "just" cancel the event, if the email-address does not meet your criteria.
An example for your usecase whould be something like this
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Events;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
namespace My.Website
{
public class MemberServiceEventsComposer : IUserComposer
{
public void Compose(Composition composition)
{
// Append our component to the collection of Components
// It will be the last one to be run
composition.Components().Append<MemberServiceEventsComponent>();
}
}
public class MemberServiceEventsComponent : IComponent
{
// initialize: runs once when Umbraco starts
public void Initialize()
{
MemberService.Saving += MemberService_Saving;
}
// terminate: runs once when Umbraco stops
public void Terminate()
{ }
private void MemberService_Saving(IMemberService sender, SaveEventArgs<IMember> e)
{
foreach (var member in e.SavedEntities)
{
if(!member.IsApproved && !member.Email.EndsWith("examle.com")){
e.Cancel = true;
return;
}
}
}
}
}
This utilises the IsApproved flag, so members that are already created and approved, will not be validated.
members sign up only allow certain email extension
Hi all,
So I'm using the partial snippet which comes with Umbraco, and everything works fine, users are able to sign up.
However, I only want to allow a certain time of email extension e.g [email protected]
How could I achieve this?
Here is my email code block;
Thanks
Hi Matt,
On
MemberService
there is an event calledSaving
When you hook into that, you will be able to cancel a member being created. This will allow you to "just" cancel the event, if the email-address does not meet your criteria.
In umbraco 8 you need to implement this with a composer. The documentation contains an example on how to listen for an event on ContentService - https://our.umbraco.com/Documentation/Implementation/Composing/#example---creating-a-component-to-listen-for-contentservicesaving-events
An example for your usecase whould be something like this
This utilises the
IsApproved
flag, so members that are already created and approved, will not be validated.is working on a reply...