Shazwazza / UmbracoIdentity

ASP.NET Identity implementation for Umbraco's native member data
MIT License
111 stars 58 forks source link

Question: Validation for member properties #121

Closed Domitnator closed 4 years ago

Domitnator commented 4 years ago

First of all: Thanks for creating this package!

I have a question about the MemberProperties. We want to take advantage of the validation rules which are applied to the custom member properties. For instance, making the firstname mandatotry:

image

We then added the "ValidationMessageFor":

image

But there is no error being added for the firstrname:

image

Is there a way to make this work?

Kind Regards,

Alfred

Shazwazza commented 4 years ago

You are sort of mixing 2 different things. Those validation settings on the member type are for editing things in the back office, they do not directly translate to the model used on the front-end but I see that it could be nice to have those settings translate to the MVC validation system via the front-end models on the front-end.

That is really outside the scope of this project though. That model you are referring to comes from here https://github.com/Shazwazza/UmbracoIdentity/blob/master/src/UmbracoIdentity.Web/Views/UmbracoIdentityAccount/Register.cshtml#L18. Similarly the profile model comes from here https://github.com/Shazwazza/UmbracoIdentity/blob/master/src/UmbracoIdentity.Web/Views/UmbracoIdentityAccount/Profile.cshtml#L11. Both of these are part of the Umbraco CMS not part of this project. You can see those methods on the MembershipHelper here: https://github.com/umbraco/Umbraco-CMS/blob/v8/contrib/src/Umbraco.Web/Security/MembershipHelper.cs#L384 and https://github.com/umbraco/Umbraco-CMS/blob/v8/contrib/src/Umbraco.Web/Security/MembershipHelper.cs#L443

If you want the member type validation settings to translate into these front-end models you'll need to make a request to the CMS team to implement that. However, you could of course just do this yourself. You have the code for UmbracoIdentityAccountController.HandleRegisterMember where you could run any custom validation logic you want. You could also create your own registration model instead of using the CMS one and handle the validation logic yourself there too.