protected void LoginForm_Authenticate(object sender, AuthenticateEventArgs e) { // check user login/password if (!Membership.ValidateUser(LoginForm.UserName, LoginForm.Password)) { e.Authenticated = false; return; } // check additional user properties bool enabled = true; MembershipUser user = Membership.GetUser(LoginForm.UserName); if (user != null) { Mediachase.Commerce.Profile.Account account = Mediachase.Commerce.Profile.ProfileContext.Current.GetAccount(user.ProviderUserKey.ToString()); if (account == null) { account = Mediachase.Commerce.Profile.ProfileContext.Current.CreateAccountForUser(user); } int accountState = account.State; if (accountState == 1 || accountState == 3) { enabled = false; } e.Authenticated = enabled; } }
/// <summary> /// In this handler, some valitation is done, such as prventing a legacy user name from being used, /// and preventing a user to log into a site other than his or her own depository. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void LoginForm_Authenticate(object sender, AuthenticateEventArgs e) { System.Collections.Generic.List <string> deprecatedAccounts = new System.Collections.Generic.List <string>() { "nwtd", "mssd", "mssdnevada" }; if (deprecatedAccounts.Contains(this.LoginForm.UserName.Trim().ToLower())) { e.Authenticated = false; this.LoginForm.FailureText = "This generic username/password has been disabled.<br /> Please create your own new account."; return; } // check user login/password if (!Membership.ValidateUser(LoginForm.UserName, LoginForm.Password)) { e.Authenticated = false; this.LoginForm.FailureText = "You have entered either an invalid username or password."; return; } // check additional user properties bool enabled = true; MembershipUser user = Membership.GetUser(LoginForm.UserName); if (user != null) { Mediachase.Commerce.Profile.Account account = Mediachase.Commerce.Profile.ProfileContext.Current.GetAccount(user.ProviderUserKey.ToString()); if (account == null) { account = Mediachase.Commerce.Profile.ProfileContext.Current.CreateAccountForUser(user); } string siteDepository = Mediachase.Cms.GlobalVariable.GetVariable("Depository", CMSContext.Current.SiteId); if (siteDepository != null) { siteDepository = siteDepository.ToLower(); } NWTD.Depository userDepository = NWTD.Profile.GetCustomerDepository(account); if (userDepository != NWTD.Depository.NONE) { if ((siteDepository == "mssd" && userDepository == NWTD.Depository.NWTD) || (siteDepository == "nwtd" && userDepository == NWTD.Depository.MSSD)) { e.Authenticated = false; this.LoginForm.FailureText = "You are not a member of this depository."; return; } } int accountState = account.State; if (accountState == 1 || accountState == 3) { enabled = false; this.LoginForm.FailureText = "Your account has been deactivated."; } e.Authenticated = enabled; //NWTD.Profile.EnsureCustomerCart(account); NWTD.Profile.SetSaleInformation(account); } }