Closed tdekoekkoek closed 12 years ago
Hmm. The MembershipProvider (MS design) has an event (OnValidatingPassword) which can return an exception which should be thrown. So to follow that I also throw an exception when my password strategy validation fails.
It's used both in the CreateUser and ResetPassword methods. But since there is a status code for it, I should maybe catch the exception internally and return the status code instead (in CreateUser). Would be interesting to know how the SqlMembershipProvider does.
Not sure what the best strategy is. The default implementation of the AccountController in MVC looks like this, so there is no catching an exception. I suppose adding try..catch would work just as well, though:
// Attempt to register the user
MembershipCreateStatus createStatus;
Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", ErrorCodeToString(createStatus));
}
The novell SqlProvider both throws exceptions and returns the invalid code. I changed so that CreateUser will always return the invalid code, while ResetPassword can still throw exceptions. Will commit soon.
I've updated nuget now
On Fri, Aug 17, 2012 at 2:29 PM, Trevor de Koekkoek < notifications@github.com> wrote:
Not sure what the best strategy is. The default implementation of the AccountController in MVC looks like this, so there is no catching an exception. I suppose adding try..catch would work just as well, though:
// Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); }
— Reply to this email directly or view it on GitHubhttps://github.com/jgauffin/griffin.mvccontrib/issues/20#issuecomment-7816494.
Thanks. Great project by the way! I'll have to dig into the other contrib projects and see what they offer.
-Trevor
On Fri, Aug 17, 2012 at 8:54 AM, Jonas Gauffin notifications@github.comwrote:
I've updated nuget now
On Fri, Aug 17, 2012 at 2:29 PM, Trevor de Koekkoek < notifications@github.com> wrote:
Not sure what the best strategy is. The default implementation of the AccountController in MVC looks like this, so there is no catching an exception. I suppose adding try..catch would work just as well, though:
// Attempt to register the user MembershipCreateStatus createStatus;
Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, false / createPersistentCookie /); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); }
— Reply to this email directly or view it on GitHub< https://github.com/jgauffin/griffin.mvccontrib/issues/20#issuecomment-7816494>.
— Reply to this email directly or view it on GitHubhttps://github.com/jgauffin/griffin.mvccontrib/issues/20#issuecomment-7817005.
Trevor de Koekkoek http://sincere.ly/tdekoekkoek
Wondering why ValidatePassword is a void and throws an exception instead of returning MembershipCreateStatus. So on invalid password it would return MembershipCreateStatus.InvalidPassword