ServiceStack Custom Registration Validator Issue -


i want override default registration validator enabled when registration feature added. have added own customregistrationvalidator per servicestack documentation (basic rules now, expanded later):

public class customregistrationvalidator : registrationvalidator     {         public customregistrationvalidator()         {             ruleset(applyto.post, () =>             {                 rulefor(x => x.firstname).notempty();                 rulefor(x => x.lastname).notempty();                 rulefor(x => x.email).notempty();                 rulefor(x => x.password).notempty();             });         }     } 

i have overridden default registration validator in configure method per following snippet:

plugins.add(new authfeature(             () => new authusersession(),                   new iauthprovider[] { new basicauthprovider(),                   new credentialsauthprovider()                 }));              plugins.add(new validationfeature());             plugins.add(new registrationfeature());              registeras<customregistrationvalidator, ivalidator<register>>();             container.registervalidators(typeof(apphost).assembly); 

however, validator never appears execute, can register new users invalid details.

i using latest version of servicestack v4.0.22

is major servicestack bug or feature no longer available latest version of servicestack?

thank in advance this.

regards john

i can confirm still bug in v4.0.35. how got around it...

  1. create custom registration validation class implements abstractvalidator<register> , add own fluent validation rules (i copied rules ss source)

    public class customregistrationvalidator : abstractvalidator<register> {     public iauthrepository userauthrepo { get; set; }     public customregistrationvalidator()     {         ruleset(applyto.post, () =>         {             rulefor(x => x.username).notempty().when(x => x.email.isnullorempty());             rulefor(x => x.username)             .must(x => userauthrepo.getuserauthbyusername(x) == null)             .witherrorcode("alreadyexists")             .withmessage("username exists")             .when(x => !x.username.isnullorempty());             rulefor(x => x.email)             .must(x => x.isnullorempty() || userauthrepo.getuserauthbyusername(x) == null)             .witherrorcode("alreadyexists")             .withmessage("email exists")             .when(x => !x.email.isnullorempty());              rulefor(x => x.firstname).notempty();             rulefor(x => x.lastname).notempty();             rulefor(x => x.email).notempty();             rulefor(x => x.password).notempty();             // add own rules here...     });      ruleset(         applyto.put,         () =>         {             rulefor(x => x.username).notempty();             rulefor(x => x.email).notempty();             // add own rules here...         }); } 

    }

  2. create customregistrationfeature class implements iplugin (again copied ss source , changed ioc registration customregistrationvalidator class)

    public class customregistrationfeature : iplugin {     public string atrestpath { get; set; }      public customregistrationfeature()     {         this.atrestpath = "/register";     }      public void register(iapphost apphost)     {         apphost.registerservice<registerservice>(atrestpath);         apphost.registeras<customregistrationvalidator, ivalidator<register>>();     } } 
  3. replace registrationfeature registration in app.host new customregistrationfeature created.

    plugins.add(new customregistrationfeature()); 

i don't know why works doing same or similar thing what's there, does. allows me add in more validation rules (which why needed this).


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -