protected void SubmitReviewButton_Click(object sender, EventArgs e) { if (Page.IsValid) { //VALIDATE CAPTCHA if (ProductReviewHelper.ImageVerificationRequired(AbleContext.Current.User)) { if (CaptchaImage.Authenticate(CaptchaInput.Text)) { HandleSubmitedReview(); ReviewsRepeater.DataBind(); } else { CustomValidator invalidInput = new CustomValidator(); invalidInput.ID = Guid.NewGuid().ToString(); invalidInput.Text = "*"; invalidInput.ErrorMessage = "You did not input the number correctly."; invalidInput.IsValid = false; invalidInput.ValidationGroup = "ProductReviewForm"; phCaptchaValidators.Controls.Add(invalidInput); RefreshCaptcha(); } CaptchaInput.Text = string.Empty; } else { HandleSubmitedReview(); ReviewsRepeater.DataBind(); } } }
protected void Submit_Click(object sender, EventArgs e) { if (EnableCaptcha) { if (CaptchaImage.Authenticate(CaptchaInput.Text)) { SubmitComment(); CaptchaInput.Text = ""; RefreshCaptcha(); } else { //CAPTCHA IS VISIBLE AND DID NOT AUTHENTICATE CustomValidator invalidInput = new CustomValidator(); invalidInput.Text = "*"; invalidInput.ErrorMessage = "You did not input the verification number correctly."; invalidInput.IsValid = false; phCaptchaValidators.Controls.Add(invalidInput); CaptchaInput.Text = ""; RefreshCaptcha(); } } else if (!EnableCaptcha) { SubmitComment(); } }
protected void SendEmailButton_Click(object sender, EventArgs e) { if (Page.IsValid) { if ((!trCaptchaImage.Visible) || CaptchaImage.Authenticate(CaptchaInput.Text)) { int productId = AbleCommerce.Code.PageHelper.GetProductId(); Product product = ProductDataSource.Load(productId); if (product != null) { int categoryId = AbleCommerce.Code.PageHelper.GetCategoryId(); Category category = CategoryDataSource.Load(categoryId); EmailTemplate template = EmailTemplateDataSource.Load(AbleContext.Current.Store.Settings.ProductTellAFriendEmailTemplateId); if (template != null) { //STRIP HTML Name.Text = StringHelper.StripHtml(Name.Text); FromEmail.Text = StringHelper.StripHtml(FromEmail.Text); FriendEmail.Text = StringHelper.StripHtml(FriendEmail.Text); // ADD PARAMETERS template.Parameters["store"] = AbleContext.Current.Store; template.Parameters["product"] = product; template.Parameters["category"] = category; template.Parameters["fromEmail"] = FromEmail.Text; template.Parameters["fromName"] = Name.Text; template.FromAddress = FromEmail.Text; template.ToAddress = FriendEmail.Text; template.Send(); FriendEmail.Text = string.Empty; SentMessage.Visible = true; CaptchaInput.Text = ""; CaptchaImage.ChallengeText = StringHelper.RandomNumber(6); } else { FailureMessage.Text = "Email template could not be loaded."; FailureMessage.Visible = true; } } else { FailureMessage.Text = "Product could not be identified."; FailureMessage.Visible = true; } } else { //CAPTCHA IS VISIBLE AND DID NOT AUTHENTICATE CustomValidator invalidInput = new CustomValidator(); invalidInput.ValidationGroup = "TellAFriend"; invalidInput.Text = "*"; invalidInput.ErrorMessage = "You did not input the verification number correctly."; invalidInput.IsValid = false; phCaptchaValidators.Controls.Add(invalidInput); CaptchaInput.Text = ""; CaptchaImage.ChallengeText = StringHelper.RandomNumber(6); } } }
protected void RegisterButton_Click(object sender, EventArgs e) { if (Page.IsValid && ValidatePassword()) { if ((!trCaptchaField.Visible) || CaptchaImage.Authenticate(CaptchaInput.Text)) { // PERFORM CUSTOM VALIDATION TO ENSURE EMAIL IS NOT ALREADY REGISTERED string userName = UserName.Text.Trim(); int userIde = UserDataSource.GetUserIdByEmail(userName); int userIdu = UserDataSource.GetUserIdByUserName(userName); if (userIde == 0 && userIdu == 0) { // NO USER REGISTERED WITH THAT USERNAME OR EMAIL MembershipCreateStatus status; User newUser = UserDataSource.CreateUser(userName, userName, Password.Text, string.Empty, string.Empty, true, 0, out status); if (status == MembershipCreateStatus.Success) { // WE HAVE TO VALIDATE CREDENTIALS SO A MODIFIED FORM POST CANNOT ACCESS THIS CODE if (Membership.ValidateUser(userName, Password.Text)) { // SET A DEFAULT BILLING ADDRESS FOR THE USER newUser.PrimaryAddress.Email = userName; newUser.PrimaryAddress.CountryCode = AbleContext.Current.Store.DefaultWarehouse.CountryCode; newUser.PrimaryAddress.Residence = true; newUser.Save(); // SET COOKIE TO REMEMBER USERNAME IF INDICATED if (RememberUserName.Checked) { HttpCookie cookie = new HttpCookie("UserName", userName); cookie.Expires = DateTime.MaxValue; Response.Cookies.Add(cookie); } else { Response.Cookies.Add(new HttpCookie("UserName", "")); } //MIGRATE USER IF NEEDED int newUserId = UserDataSource.GetUserIdByUserName(userName); if ((AbleContext.Current.UserId != newUserId) && (newUserId != 0)) { User.Migrate(AbleContext.Current.User, newUser, false, true); AbleContext.Current.UserId = newUserId; } //REDIRECT TO APPROPRIATE PAGE FormsAuthentication.SetAuthCookie(UserName.Text, false); Response.Redirect(NavigationHelper.GetReturnUrl(NavigationHelper.GetMobileStoreUrl("~/Default.aspx"))); } } else { InvalidRegistration.IsValid = false; switch (status) { case MembershipCreateStatus.DuplicateUserName: case MembershipCreateStatus.DuplicateEmail: InvalidRegistration.ErrorMessage = "The user-name you have provided is already registered. Sign in to access your account."; break; case MembershipCreateStatus.InvalidEmail: InvalidRegistration.ErrorMessage = "The email address you have provided is not valid."; break; case MembershipCreateStatus.InvalidUserName: InvalidRegistration.ErrorMessage = "The user-name you have provided is not valid."; break; case MembershipCreateStatus.InvalidPassword: InvalidRegistration.ErrorMessage = "The password you have provided is not valid."; break; default: InvalidRegistration.ErrorMessage = "Unexpected error in registration (" + status.ToString() + ")"; break; } } } else { DuplicateEmailValidator.IsValid = false; } } else { //CAPTCHA IS VISIBLE AND DID NOT AUTHENTICATE CustomValidator invalidInput = new CustomValidator(); invalidInput.ID = Guid.NewGuid().ToString(); invalidInput.Text = "*"; invalidInput.ErrorMessage = "You did not input the verification number correctly."; invalidInput.IsValid = false; phCaptchaValidators.Controls.Add(invalidInput); CaptchaInput.Text = ""; Password.Attributes.Add("value", string.Empty); RefreshCaptcha(); } } }
protected void LoginButton_Click(object sender, EventArgs e) { _LastPasswordValue = Password.Text; if (Page.IsValid) { //VALIDATE CAPTCHA if (!trCaptchaField.Visible || (CaptchaImage.Authenticate(CaptchaInput.Text))) { if (Membership.ValidateUser(UserName.Text, Password.Text)) { //MIGRATE USER IF NEEDED int newUserId = UserDataSource.GetUserId(UserName.Text); if ((AbleContext.Current.UserId != newUserId) && (newUserId != 0)) { CommerceBuilder.Users.User.Migrate(AbleContext.Current.User, UserDataSource.Load(newUserId)); AbleContext.Current.UserId = newUserId; } //HANDLE LOGIN PROCESSING if (RememberUserName.Checked) { HttpCookie cookie = new HttpCookie("UserName", UserName.Text); cookie.Expires = DateTime.MaxValue; Response.Cookies.Add(cookie); } else { Response.Cookies.Add(new HttpCookie("UserName", "")); } // CHECK PASSWORD FOR EXPIRATION User newUser = UserDataSource.Load(newUserId); MerchantPasswordPolicy policy = new MerchantPasswordPolicy(); if (policy.IsPasswordExpired(newUser)) { ShowPasswordExpired(); } else { // LOGIN SUCCESSFUL, REDIRECT FormsAuthentication.RedirectFromLoginPage(UserName.Text, false); } } else { User user = UserDataSource.LoadForUserName(UserName.Text); if (user != null) { if (!user.IsApproved) { AccountDisabled.IsValid = false; } else { MerchantPasswordPolicy policy = new MerchantPasswordPolicy(); int remainingTries = policy.MaxAttempts - user.FailedPasswordAttemptCount; if (!user.IsLockedOut && remainingTries > 0) { InvalidLogin.ErrorMessage += " You have {0} tries remaining."; InvalidLogin.ErrorMessage = String.Format(InvalidLogin.ErrorMessage, remainingTries); InvalidLogin.IsValid = false; } else { AccountLocked.ErrorMessage = String.Format(AccountLocked.ErrorMessage, policy.LockoutPeriod); AccountLocked.IsValid = false; } } } else { InvalidLogin.IsValid = false; } RefreshCaptcha(); } } else { CustomValidator invalidInput = new CustomValidator(); invalidInput.ValidationGroup = "Login"; invalidInput.Text = "*"; invalidInput.ErrorMessage = "You did not input the verification number correctly."; invalidInput.IsValid = false; phCaptchaValidators.Controls.Add(invalidInput); RefreshCaptcha(); } } }
protected void LoginButton_Click(object sender, EventArgs e) { _LastPasswordValue = Password.Text; User loginUser = UserDataSource.LoadForUserName(UserName.Text); if (loginUser != null) { bool stillNeedsCaptcha = false; if ((loginUser.IsAdmin) && (!trCaptchaField.Visible)) { stillNeedsCaptcha = (new MerchantPasswordPolicy()).ImageCaptcha; } if (!stillNeedsCaptcha) { //EITHER THIS IS NOT AN ADMIN USER, OR THE CAPTCHA IS ALREADY VISIBLE if ((!trCaptchaField.Visible) || (CaptchaImage.Authenticate(CaptchaInput.Text))) { //CAPTCHA IS HIDDEN OR VALIDATED, PROCEED WITH LOGIN ATTEMPT if (Membership.ValidateUser(UserName.Text, Password.Text)) { //LOGIN SUCCEEDED, MIGRATE USER IF NEEDED int newUserId = loginUser.Id; int oldUserId = AbleContext.Current.UserId; if ((oldUserId != newUserId) && (newUserId != 0)) { User.Migrate(AbleContext.Current.User, UserDataSource.Load(newUserId)); AbleContext.Current.UserId = newUserId; } //HANDLE LOGIN PROCESSING if (trRememberMe.Visible && RememberUserName.Checked) { HttpCookie cookie = new HttpCookie("UserName", UserName.Text); cookie.Expires = DateTime.MaxValue; Response.Cookies.Add(cookie); } else { Response.Cookies.Add(new HttpCookie("UserName", "")); } //CHECK FOR EXPIRED PASSWORDS PasswordPolicy policy; if (loginUser.IsAdmin) { policy = new MerchantPasswordPolicy(); } else { policy = new CustomerPasswordPolicy(); } if (policy.IsPasswordExpired(loginUser)) { ShowPasswordExpired(policy, loginUser); } else { switch (AbleContext.Current.Store.Settings.RestrictStoreAccess) { case AccessRestrictionType.AuthorizedGroupsOnly: if (!loginUser.IsAdmin && !loginUser.IsAuthorizedUser) { // STORE ACCESS IS RESTRICTED TO AUTHORIZED USERS ONLY LoginPanel.Visible = false; PasswordExpiredPanel.Visible = false; StoreFrontAccessDeniedPanel.Visible = true; } else { FormsAuthentication.RedirectFromLoginPage(UserName.Text, false); } break; case AccessRestrictionType.RegisteredUsersOnly: case AccessRestrictionType.None: //REDIRECT TO THE STANDARD PAGE FormsAuthentication.RedirectFromLoginPage(UserName.Text, false); break; } } } else { if (loginUser != null) { if (!loginUser.IsApproved) { AccountDisabled.IsValid = false; } else { PasswordPolicy policy; if (loginUser.IsAdmin) { policy = new MerchantPasswordPolicy(); } else { policy = new CustomerPasswordPolicy(); } int remainingTries = policy.MaxAttempts - loginUser.FailedPasswordAttemptCount; if (!loginUser.IsLockedOut && remainingTries > 0) { InvalidLogin.ErrorMessage += " You have {0} tries remaining."; InvalidLogin.ErrorMessage = String.Format(InvalidLogin.ErrorMessage, remainingTries); InvalidLogin.IsValid = false; } else { AccountLocked.ErrorMessage = String.Format(AccountLocked.ErrorMessage, policy.LockoutPeriod); AccountLocked.IsValid = false; } } } else { InvalidLogin.IsValid = false; } } } else { //CAPTCHA IS VISIBLE AND DID NOT AUTHENTICATE CustomValidator invalidInput = new CustomValidator(); invalidInput.ValidationGroup = "Login"; invalidInput.Text = "*"; invalidInput.ErrorMessage = "You did not input the verification number correctly."; invalidInput.IsValid = false; phCaptchaValidators.Controls.Add(invalidInput); CaptchaInput.Text = ""; Password.Attributes.Add("value", string.Empty); RefreshCaptcha(); } } else { //THIS IS AN ADMIN USER AND CAPTCHA IS NOT DISPLAYED YET trCaptchaField.Visible = true; trCaptchaImage.Visible = true; trRememberMe.Visible = _EnableAdminRememberMe; CaptchaImage.ChallengeText = StringHelper.RandomNumber(6); CustomValidator needsCaptcha = new CustomValidator(); needsCaptcha.ValidationGroup = "Login"; needsCaptcha.Text = "*"; needsCaptcha.ErrorMessage = "Please type the verification number to log in."; needsCaptcha.IsValid = false; phCaptchaValidators.Controls.Add(needsCaptcha); Password.Attributes.Add("value", Password.Text); } } else { //THIS IS AN INVALID USER NAME InvalidLogin.IsValid = false; } }
protected void LoginButton_Click(object sender, EventArgs e) { _LastPasswordValue = Password.Text; User loginUser = UserDataSource.LoadForUserName(UserName.Text); if (loginUser != null) { bool stillNeedsCaptcha = false; if ((loginUser.IsAdmin) && (!trCaptchaField.Visible)) { stillNeedsCaptcha = (new MerchantPasswordPolicy()).ImageCaptcha; } if (!stillNeedsCaptcha) { // IF CAPTCHA IS REQUIRED CHECK IF THE ENTRY IS VALID if ((!trCaptchaField.Visible) || (CaptchaImage.Authenticate(CaptchaInput.Text))) { // CAPTCHA IS HIDDEN OR VALIDATED, PROCEED WITH LOGIN ATTEMPT if (Membership.ValidateUser(UserName.Text, Password.Text)) { //LOGIN SUCCEEDED, MIGRATE USER IF NEEDED int newUserId = loginUser.Id; int oldUserId = AbleContext.Current.UserId; if ((oldUserId != newUserId) && (newUserId != 0)) { CommerceBuilder.Users.User.Migrate(AbleContext.Current.User, UserDataSource.Load(newUserId)); AbleContext.Current.UserId = newUserId; } //HANDLE LOGIN PROCESSING if (RememberUserName.Checked) { HttpCookie cookie = new HttpCookie("UserName", UserName.Text); cookie.Expires = DateTime.MaxValue; Response.Cookies.Add(cookie); } else { Response.Cookies.Add(new HttpCookie("UserName", "")); } //CHECK FOR EXPIRED PASSWORDS PasswordPolicy policy; if (loginUser.IsAdmin) { policy = new MerchantPasswordPolicy(); } else { policy = new CustomerPasswordPolicy(); } if (policy.IsPasswordExpired(loginUser)) { ShowPasswordExpired(policy, loginUser); } else { //REDIRECT TO THE STANDARD PAGE FormsAuthentication.SetAuthCookie(UserName.Text, false); Response.Redirect("EditBillAddress.aspx"); } } else { if (loginUser != null) { if (!loginUser.IsApproved) { AccountDisabled.IsValid = false; } else { PasswordPolicy policy; if (loginUser.IsAdmin) { policy = new MerchantPasswordPolicy(); } else { policy = new CustomerPasswordPolicy(); } int remainingTries = policy.MaxAttempts - loginUser.FailedPasswordAttemptCount; if (!loginUser.IsLockedOut && remainingTries > 0) { InvalidLogin.ErrorMessage += " You have {0} tries remaining."; InvalidLogin.ErrorMessage = String.Format(InvalidLogin.ErrorMessage, remainingTries); InvalidLogin.IsValid = false; } else { AccountLocked.ErrorMessage = String.Format(AccountLocked.ErrorMessage, policy.LockoutPeriod); AccountLocked.IsValid = false; } } } else { InvalidLogin.IsValid = false; } } } else { // CAPTCHA IS VISIBLE AND DID NOT AUTHENTICATE trCaptchaImage.Visible = true; trCaptchaField.Visible = true; CustomValidator invalidInput = new CustomValidator(); invalidInput.ID = Guid.NewGuid().ToString(); invalidInput.ValidationGroup = "Login"; invalidInput.Text = "*"; invalidInput.ErrorMessage = "You did not input the verification number correctly."; invalidInput.IsValid = false; phCaptchaValidators.Controls.Add(invalidInput); CaptchaInput.Text = ""; Password.Attributes.Add("value", string.Empty); RefreshCaptcha(); } } else { // CAPTCHA IS REQUIRED BUT IT IS NOT DISPLAYED YET trCaptchaField.Visible = true; trCaptchaImage.Visible = true; CaptchaImage.ChallengeText = StringHelper.RandomNumber(6); CustomValidator needsCaptcha = new CustomValidator(); needsCaptcha.ID = "CaptchaRequiredValidator"; needsCaptcha.ValidationGroup = "Login"; needsCaptcha.Text = "*"; needsCaptcha.ErrorMessage = "Please type the verification number to log in."; needsCaptcha.IsValid = false; phCaptchaValidators.Controls.Add(needsCaptcha); Password.Attributes.Add("value", Password.Text); } } else { //THIS IS AN INVALID USER NAME InvalidLogin.IsValid = false; } }
protected bool CreateNewAccount() { bool result = false; if (Page.IsValid && ValidatePassword()) { if ((!trCaptchaField.Visible) || CaptchaImage.Authenticate(CaptchaInput.Text)) { // PERFORM CUSTOM VALIDATION TO ENSURE EMAIL IS NOT ALREADY REGISTERED string userName = StringHelper.StripHtml(UserName.Text.Trim()); if (!UserDataSource.IsEmailRegistered(userName)) { // NO USER REGISTERED WITH THAT USERNAME OR EMAIL MembershipCreateStatus status; User newUser = UserDataSource.CreateUser(userName, userName, Password.Text, string.Empty, string.Empty, true, 0, out status); if (status == MembershipCreateStatus.Success) { // WE HAVE TO VALIDATE CREDENTIALS SO A MODIFIED FORM POST CANNOT ACCESS THIS CODE if (Membership.ValidateUser(userName, Password.Text)) { // SET A DEFAULT BILLING ADDRESS FOR THE USER newUser.PrimaryAddress.Email = userName; newUser.PrimaryAddress.CountryCode = AbleContext.Current.Store.DefaultWarehouse.CountryCode; newUser.PrimaryAddress.Residence = true; newUser.Save(); // MIGRATE ACTIVE USER TO NEW ACCOUNT CommerceBuilder.Users.User.Migrate(AbleContext.Current.User, newUser, false, true); AbleContext.Current.User = newUser; FormsAuthentication.SetAuthCookie(userName, false); result = true; } } else { InvalidRegistration.IsValid = false; switch (status) { case MembershipCreateStatus.DuplicateUserName: case MembershipCreateStatus.DuplicateEmail: InvalidRegistration.ErrorMessage = "The user-name you have provided is already registered. Sign in to access your account."; break; case MembershipCreateStatus.InvalidEmail: InvalidRegistration.ErrorMessage = "The email address you have provided is not valid."; break; case MembershipCreateStatus.InvalidUserName: InvalidRegistration.ErrorMessage = "The user-name you have provided is not valid."; break; case MembershipCreateStatus.InvalidPassword: InvalidRegistration.ErrorMessage = "The password you have provided is not valid."; break; default: InvalidRegistration.ErrorMessage = "Unexpected error in registration (" + status.ToString() + ")"; break; } } } else { DuplicateEmailValidator.IsValid = false; } } else { //CAPTCHA IS VISIBLE AND DID NOT AUTHENTICATE CustomValidator invalidInput = new CustomValidator(); invalidInput.ID = Guid.NewGuid().ToString(); invalidInput.Text = "*"; invalidInput.ErrorMessage = "You did not input the verification number correctly."; invalidInput.IsValid = false; phCaptchaValidators.Controls.Add(invalidInput); CaptchaInput.Text = ""; Password.Attributes.Add("value", string.Empty); RefreshCaptcha(); } } return(result); }