Intercepting the save member throws a nullReferenceException
For our web application the functionality description demands the end-user to login with an e-mail address instead of an username. Unfortunately, MembershipHelper doesn't provide a method to login with an e-mail address/password (Why not?), only username/password.
Here the username is retrieved via the user Id via the e-mail address. This looks like needing 2 extra calls to the database which we don't like and also makes the code less pretty and is.
Another solution that we found is using an intercept acting solution. As this solution introduces a sperate piece of code and no extra database calls, we decided to choose this solution as it is in the code below:
public class SaveMemberInterceptor : IComponent
{
public void Initialize()
{
MemberService.Saving += SetUserNameEqualToEmailAddress;
}
public void Terminate()
{
//Nothing to terminate
}
private void SetUserNameEqualToEmailAddress(IMemberService sender, SaveEventArgs<IMember> saveEventArguments)
{
foreach (var entity in saveEventArguments.SavedEntities)
{
entity.Username = entity.Email;
}
}
}
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class SubscribeToMediaSavedEventComposer : ComponentComposer<SaveMemberInterceptor>
{
}
Unfortunately, this code throws runtime exceptions:
Received an error from the server An error occured Object reference
not set to an instance of an object.
Exception Details System.NullReferenceException: Object reference not
set to an instance of an object.
Stacktrace
at Umbraco.Web.Editors.MemberController.UpdateName(MemberSave memberSave)
in D:\a\1\s\src\Umbraco.Web\Editors\MemberController.cs:line 614 at
Umbraco.Web.Editors.MemberController.RefetchMemberData(MemberSave
contentItem, LookupType lookup) in
D:\a\1\s\src\Umbraco.Web\Editors\MemberController.cs:line 586 at
Umbraco.Web.Editors.MemberController.CreateWithMembershipProvider(MemberSave
contentItem, MembershipCreateStatus& status) in
D:\a\1\s\src\Umbraco.Web\Editors\MemberController.cs:line 716 at
Umbraco.Web.Editors.MemberController.PostSave(MemberSave contentItem)
in D:\a\1\s\src\Umbraco.Web\Editors\MemberController.cs:line 318 at
lambdamethod(Closure , Object , Object[] ) at
System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>cDisplayClass62.
We might be using Umbraco 7 code in Umbraco 8 project but one thing we noticed: the documentation for Umbraco 8 for this subject is very poor (or we are using the wrong terms while searching, also possible of course).
What are we doing wrong and what needs to be done to fix the issue?
Did you find a solution for this at all? I have a similar issue. I have been following an article about encryption (https://skrift.io/issues/encryption-injection-in-v8/) but get the same error when trying to encrypt the username using the saving event.
Unfortunately we haven't found a solution for this problem yet. Currently we solved it by teaching the customer not to enter a normal username in the username field but fill in an e-mail address instead. Not the best solution, but currently it seems to be the only one there is.
Intercepting the save member throws a nullReferenceException
For our web application the functionality description demands the end-user to login with an e-mail address instead of an username. Unfortunately, MembershipHelper doesn't provide a method to login with an e-mail address/password (Why not?), only username/password.
In the search adventure of figuring out how to login with e-mail/password, I found this topic: https://our.umbraco.com/forum/using-umbraco-and-getting-started/86635-retrieve-a-members-login-by-their-email-address
Here the username is retrieved via the user Id via the e-mail address. This looks like needing 2 extra calls to the database which we don't like and also makes the code less pretty and is.
Another solution that we found is using an intercept acting solution. As this solution introduces a sperate piece of code and no extra database calls, we decided to choose this solution as it is in the code below:
Unfortunately, this code throws runtime exceptions:
We might be using Umbraco 7 code in Umbraco 8 project but one thing we noticed: the documentation for Umbraco 8 for this subject is very poor (or we are using the wrong terms while searching, also possible of course).
What are we doing wrong and what needs to be done to fix the issue?
Hi,
Did you find a solution for this at all? I have a similar issue. I have been following an article about encryption (https://skrift.io/issues/encryption-injection-in-v8/) but get the same error when trying to encrypt the username using the saving event.
Thanks
Unfortunately we haven't found a solution for this problem yet. Currently we solved it by teaching the customer not to enter a normal username in the username field but fill in an e-mail address instead. Not the best solution, but currently it seems to be the only one there is.
is working on a reply...