Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to validate a user that is not approved asp.net MVC 3
    primarykey
    data
    text
    <p>I have a problem with validating a user before he gets approved. Here is the code:</p> <blockquote> <p>public void Login(LoginViewModel model) {</p> <pre><code> if (Membership.ValidateUser(model.UserName, model.Password)) { if (Membership.GetUser(model.UserName).IsApproved) { FormsAuthentication.SetAuthCookie(model.UserName, model.KeepMeLoggedIn); } else { throw new Exception("Your email is not verified yet. Please check your email!"); } } else { throw new Exception("Username or Password doesn't match"); } } </code></pre> </blockquote> <p>The problem is that even when the username and password are good, but the user is not approved yet, it throws the second exception.</p> <p>I was trying to override the ValidateUser, but I can't call it.</p> <blockquote> <pre><code>public class MyValidation : SqlMembershipProvider { public override bool ValidateUser(string username, string password) { MembershipUser user = GetUser(username, false); if (!user.IsApproved) { return true; } return base.ValidateUser(username, password); } } </code></pre> </blockquote> <p>Any suggestions?</p> <p>edited: Controller Code</p> <pre><code>[AcceptVerbs(HttpVerbs.Post)] public ActionResult Login(LoginViewModel model) { AccountService service = new AccountService(); if (ModelState.IsValid) { try { service.Login(model); return RedirectToAction("Index", "Home"); } catch (Exception e) { TempData["errorMessage"] = e.Message; return RedirectToAction("Index", "Home"); } } return RedirectToAction("Index", "Home"); } </code></pre> <p>I mention that Login is a partial view </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload