示例#1
0
 public void CustomerAccountDeleted(Membership.CustomerAccount account)
 {
     if (OnCustomerAccountDeleted != null)
     {
         OnCustomerAccountDeleted(this, account);
     }
 }
示例#2
0
        public bool ResetPasswordForCustomer(string email, string newPassword)
        {
            bool            result = false;
            CustomerAccount u      = Customers.FindByEmail(email);

            if (u != null)
            {
                u.Password = u.EncryptPassword(newPassword);
                Membership.CreateUserStatus s = CreateUserStatus.None;
                result = UpdateCustomer(u, ref s);
            }
            return(result);
        }
示例#3
0
        public bool UpdateCustomerEmail(CustomerAccount user, string newEmail)
        {
            string oldEmail = user.Email;

            user.Email = newEmail;
            bool result = UpdateCustomer(user);

            if (result)
            {
                Integration.Current().CustomerAccountEmailChanged(oldEmail, newEmail);
            }
            return(result);
        }
        public override bool Execute(OrderTaskContext context)
        {
            CustomerAccount u = context.MTApp.MembershipServices.Customers.FindByEmail(context.Order.UserEmail);
            if (u != null)
            {
                if (u.Bvin != string.Empty)
                {
                    return true;
                }
            }

            CustomerAccount n = new CustomerAccount();
            n.Email = context.Order.UserEmail;
            int length = WebAppSettings.PasswordMinimumLength;
            if (length < 8) length = 8;
            string newPassword = MerchantTribe.Web.PasswordGenerator.GeneratePassword(length);
            n.Password = newPassword;
            n.FirstName = context.Order.ShippingAddress.FirstName;
            n.LastName = context.Order.ShippingAddress.LastName;

            if (context.MTApp.MembershipServices.CreateCustomer(n, n.Password))
            {
                // Update Addresses for Customer
                context.Order.BillingAddress.CopyTo(n.BillingAddress);
                context.Order.ShippingAddress.CopyTo(n.ShippingAddress);
                context.MTApp.MembershipServices.UpdateCustomer(n);
                context.Order.CustomProperties.Add("bvsoftware", "allowpasswordreset", "1");

                // Email Password to Customer
                HtmlTemplate t = context.MTApp.ContentServices.GetHtmlTemplateOrDefault(HtmlTemplateType.ForgotPassword);
                if (t != null)
                {
                    System.Net.Mail.MailMessage m;

                    List<IReplaceable> replacers = new List<IReplaceable>();
                    replacers.Add(n);
                    replacers.Add(new Replaceable("[[NewPassword]]", newPassword));
                    t = t.ReplaceTagsInTemplate(context.MTApp, replacers);

                    m = t.ConvertToMailMessage(n.Email);

                    if (MailServices.SendMail(m) == false)
                    {
                        EventLog.LogEvent("Create Account During Checkout", "Failed to send email to new customer " + n.Email, EventLogSeverity.Warning);
                    }
                }
            }
            context.UserId = n.Bvin;

            return true;
        }
示例#5
0
        public SystemOperationResult ValidateUser(string email, string password)
        {
            SystemOperationResult result = new SystemOperationResult();

            CustomerAccount u = Customers.FindByEmail(email);

            if (u != null)
            {
                if (DoPasswordsMatchForCustomer(password, u) == true)
                {
                    CustomerCheckLock(u);
                    if (u.Locked == false)
                    {
                        // Reset Failed Login Count
                        if (u.FailedLoginCount > 0)
                        {
                            u.FailedLoginCount = 0;
                            UpdateCustomer(u);
                        }
                        result.Success = true;
                    }
                    else
                    {
                        result.Success = false;
                        result.Message = Content.SiteTerms.GetTerm(Content.SiteTermIds.AccountLocked);
                    }
                }
                else
                {
                    result.Message      = Content.SiteTerms.GetTerm(Content.SiteTermIds.LoginIncorrect);
                    u.FailedLoginCount += 1;
                    UpdateCustomer(u);
                    CustomerCheckLock(u);
                }
            }
            else
            {
                result.Message = Content.SiteTerms.GetTerm(Content.SiteTermIds.LoginIncorrect);
            }

            if (result.Success == false)
            {
                EventLog.LogEvent("Membership", "Login Failed for User: " + email, EventLogSeverity.Information);
            }

            return(result);
        }
示例#6
0
 public void CustomerCheckLock(CustomerAccount c)
 {
     if (c.Locked == true)
     {
         if (DateTime.Compare(DateTime.UtcNow, c.LockedUntilUtc) > 0)
         {
             UnlockCustomer(c);
         }
     }
     else
     {
         if (c.FailedLoginCount >= WebAppSettings.UserLockoutAttempts)
         {
             LockCustomer(c);
             EventLog.LogEvent("Membership", "User Account " + c.Email + " was locked.", EventLogSeverity.Warning);
         }
     }
 }
示例#7
0
        public bool ChangePasswordForCustomer(string email, string oldPassword, string newPassword)
        {
            bool result = false;

            CustomerAccount u = Customers.FindByEmail(email);

            if (u != null)
            {
                if (DoPasswordsMatchForCustomer(oldPassword, u) == true)
                {
                    u.Password = u.EncryptPassword(newPassword);
                    Membership.CreateUserStatus s = CreateUserStatus.None;
                    result = UpdateCustomer(u, ref s);
                }
            }

            return(result);
        }
示例#8
0
        private void RenderSingleItem(StringBuilder sb, CustomerAccount a)
        {
            string destinationLink = "users_edit.aspx?id=" + a.Bvin + "&page=" + currentPage + "&keyword=" + System.Web.HttpUtility.UrlEncode(keyword);
            string deleteLink = destinationLink.Replace("_edit", "_delete");

            sb.Append("<tr><td><a href=\"" + destinationLink + "\">");
            sb.Append("<img src=\"" + MerchantTribe.Commerce.Contacts.GravatarHelper.GetGravatarUrlForEmailWithSize(a.Email, 40) + "\" alt=\"" + a.Email + "\" />");
            sb.Append("</a></td>");


            sb.Append("<td><a href=\"" + destinationLink + "\">");
            sb.Append(a.LastName + "," + a.FirstName);
            sb.Append("</a></td>");

            sb.Append("<td><a href=\"" + destinationLink + "\">");
            sb.Append(a.Email);
            sb.Append("</a></td>");

            
            //sb.Append("<td><a onclick=\"return window.confirm('Delete this item?');\" href=\"" + deleteLink + "\" class=\"btn\"><b>Delete</b></a></td>");
            sb.Append("<td><a href=\"" + destinationLink + "\" class=\"btn\"><b>Edit</b></a></td></tr>");
        }
示例#9
0
        public bool LoginCustomer(string email, string password, ref string errorMessage, System.Web.HttpContextBase context, ref string userId, MerchantTribeApplication app)
        {
            bool result = false;

            try
            {
                SystemOperationResult op = ValidateUser(email, password);
                if (op.Success == false)
                {
                    errorMessage = op.Message;
                    return(false);
                }

                CustomerAccount u = Customers.FindByEmail(email);
                if (u == null)
                {
                    errorMessage = "Please check your email address and password and try again.";
                    return(false);
                }

                userId = u.Bvin;

                Cookies.SetCookieString(WebAppSettings.CookieNameAuthenticationTokenCustomer(app.CurrentStore.Id),
                                        u.Bvin,
                                        context, false, new EventLog());
                result = true;
            }
            catch (Exception ex)
            {
                result = false;
                EventLog.LogEvent(ex);
                errorMessage = "Unknown login error. Contact administrator for assistance.";
            }

            return(result);
        }
 public bool UpdateCustomerEmail(CustomerAccount user, string newEmail)
 {
     string oldEmail = user.Email;
     user.Email = newEmail;
     bool result = UpdateCustomer(user);
     if (result)
     {
         context.IntegrationEvents.CustomerAccountEmailChanged(oldEmail, newEmail);
     }
     return result;
 }
示例#11
0
 public void LockCustomer(CustomerAccount c)
 {
     c.Locked         = true;
     c.LockedUntilUtc = DateTime.UtcNow.AddMinutes(WebAppSettings.UserLockoutMinutes);
     UpdateCustomer(c);
 }
示例#12
0
 private CustomerAccount GetSelectedUserAccount()
 {
     CustomerAccount result = new CustomerAccount();
     result = MTApp.MembershipServices.Customers.Find(this.UserIdField.Value);
     return result;
 }
 public void LockCustomer(CustomerAccount c)
 {
     c.Locked = true;
     c.LockedUntilUtc = DateTime.UtcNow.AddMinutes(WebAppSettings.UserLockoutMinutes);
     UpdateCustomer(c);
 }
示例#14
0
        private void RenderUser(CustomerAccount u)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            int totalCount = 0;
            List<OrderSnapshot> orders = MTApp.OrderServices.Orders.FindByUserId(u.Bvin, 1, int.MaxValue, ref totalCount);
            if (orders == null)
            {
                orders = new List<OrderSnapshot>();
            }

            sb.Append(AddString(u.Email));
            //If Contacts.MailingList.CheckMembership("8858e25b-d9a0-4ae7-b74b-bdecd0c77a8d", u.Email) Then
            //    sb.Append(AddString("YES"))
            //Else
            //    sb.Append(AddString("NO"))
            //End If

            sb.Append(AddString(u.LastName));
            sb.Append(AddString(u.FirstName));

            bool renderEmpty = false;

            if ((u.Addresses != null))
            {
                if (u.Addresses.Count > 0)
                {
                    sb.Append(AddString(u.Addresses[u.Addresses.Count - 1].Line1 + u.Addresses[u.Addresses.Count - 1].Line2));
                    sb.Append(AddString(u.Addresses[u.Addresses.Count - 1].RegionName));
                    sb.Append(AddString(u.Addresses[u.Addresses.Count - 1].City));
                    sb.Append(AddString(u.Addresses[u.Addresses.Count - 1].PostalCode));
                }
                else
                {
                    renderEmpty = true;
                }
            }
            else
            {
                if (orders.Count > 0)
                {
                    if (orders[0].ShippingAddress != null)
                    {
                        sb.Append(AddString(orders[0].ShippingAddress.Line1 + orders[0].ShippingAddress.Line2));
                        sb.Append(AddString(orders[0].ShippingAddress.RegionName));
                        sb.Append(AddString(orders[0].ShippingAddress.City));
                        sb.Append(AddString(orders[0].ShippingAddress.PostalCode));
                    }
                    else
                    {
                        renderEmpty = true;
                    }
                }
                else
                {
                    MerchantTribe.Commerce.Contacts.Address ship = u.ShippingAddress;
                    if (ship != null)
                    {
                        if (ship.Line1.Trim().Length > 0)
                        {
                            sb.Append(AddString(ship.Line1 + ship.Line2));
                            sb.Append(AddString(ship.RegionName));
                            sb.Append(AddString(ship.City));
                            sb.Append(AddString(ship.PostalCode));
                        }
                        else
                        {
                            renderEmpty = true;
                        }
                    }
                    else
                    {
                        renderEmpty = true;
                    }
                }

                if (renderEmpty)
                {
                    sb.Append(AddString(" "));
                    sb.Append(AddString(" "));
                    sb.Append(AddString(" "));
                    sb.Append(AddString(" "));
                }
            }


            foreach (Product p in _SelectedProducts)
            {
                sb.Append(AddString(CountPurchases(u.Bvin, p.Bvin, orders)));
            }

            sb.Append(System.Environment.NewLine);
            this.txtResults.Text += sb.ToString();
        }
        private bool Save()
        {
            bool result = false;

            // Check password length
            if (this.PasswordField.Text.Trim().Length < WebAppSettings.PasswordMinimumLength)
            {
                this.lblError.Text = "Password must be at least " + WebAppSettings.PasswordMinimumLength + " characters long.";
                return false;
            }

            bool emailChanged = false;
            string oldEmailAddress = string.Empty;
            string newEmailAddress = this.EmailField.Text.Trim();

            CustomerAccount u;
            u = MTApp.MembershipServices.Customers.Find(this.BvinField.Value);
            if (u == null) u = new CustomerAccount();

            if (u != null)
            {

                u.Notes = this.CommentField.Text.Trim();
                if (string.Compare(u.Email.Trim(), this.EmailField.Text.Trim(), true) != 0)
                {
                    oldEmailAddress = u.Email.Trim();
                    emailChanged = true;
                }
                u.FirstName = this.FirstNameField.Text.Trim();
                u.LastName = this.LastNameField.Text.Trim();
                u.TaxExempt = this.chkTaxExempt.Checked;
                //u.CustomQuestionAnswers = this.CustomQuestionAnswerTextBox.Text.Trim();

                if (u.Locked != this.LockedField.Checked)
                {
                    // Lock Status Changed
                    if (this.LockedField.Checked == true)
                    {
                        MTApp.MembershipServices.LockCustomer(u);
                    }
                    else
                    {
                        MTApp.MembershipServices.UnlockCustomer(u);
                    }
                }

                u.PricingGroupId = PricingGroupDropDownList.SelectedValue;

                CreateUserStatus s = CreateUserStatus.None;

                if (this.BvinField.Value == string.Empty)
                {
                    // Create new user
                    result = MTApp.MembershipServices.CreateCustomer(u, ref s, this.PasswordField.Text.Trim());
                }
                else
                {

                    if (this.PasswordField.Text != "********")
                    {
                        u.Password = u.EncryptPassword(this.PasswordField.Text.Trim());
                    }

                    // Update User
                    result = MTApp.MembershipServices.UpdateCustomer(u, ref s);
                }

                if (result == false)
                {
                    switch (s)
                    {
                        case CreateUserStatus.DuplicateUsername:
                            this.lblError.Text = "That username already exists. Select another username.";
                            break;
                        default:
                            this.lblError.Text = "Unable to save user. Uknown error.";
                            break;
                    }
                }
                else
                {
                    // Update bvin field so that next save will call updated instead of create
                    this.BvinField.Value = u.Bvin;

                    if (emailChanged)
                    {
                        if (MTApp.MembershipServices.UpdateCustomerEmail(u, newEmailAddress))
                        {
                            MTApp.CurrentRequestContext.IntegrationEvents.CustomerAccountEmailChanged(oldEmailAddress, u.Email);
                        }
                    }
                }
            }

            return result;
        }
示例#16
0
 protected void btnNewUserSave_Click(object sender, System.EventArgs e)
 {
     this.lblNewUserMessage.Text = string.Empty;
     CustomerAccount u = new CustomerAccount();
     u.Email = this.NewUserEmailField.Text.Trim();
     u.FirstName = this.NewUserFirstNameField.Text.Trim();
     u.LastName = this.NewUserLastNameField.Text.Trim();
     string clearPassword = MerchantTribe.Web.PasswordGenerator.GeneratePassword(12);            
     
     if (MTApp.MembershipServices.CreateCustomer(u, clearPassword) == true)
     {
         MerchantTribe.Commerce.Controls.UserSelectedEventArgs args = new MerchantTribe.Commerce.Controls.UserSelectedEventArgs();
         args.UserAccount = MTApp.MembershipServices.Customers.Find(u.Bvin);
         this.UserSelected(args);
     }
     else
     {
         this.lblNewUserMessage.Text = "<span class=\"errormessage\">Unable to create this account at this time. Unknown Error.</span>";
     }
 }
示例#17
0
 private void TagOrderWithUser(CustomerAccount account)
 {
     CustomerAccount u = account;
     if (u != null)
     {
         if (u.Bvin != string.Empty)
         {
             this.UserIdField.Value = u.Bvin;
             o.UserID = u.Bvin;
             u.CheckIfNewAddressAndAddNoUpdate(this.BillToAddress.GetAsAddress());
             u.CheckIfNewAddressAndAddNoUpdate(this.ShipToAddress.GetAsAddress());
             MTApp.MembershipServices.Customers.Update(u);
         }
     }
 }
 public bool CheckIfNewAddressAndAddWithUpdate(CustomerAccount a, Contacts.Address address)
 {
     bool addressWasAdded = a.CheckIfNewAddressAndAddNoUpdate(address);
     if (addressWasAdded) UpdateCustomer(a);
     return addressWasAdded;
 }                                        
 public void UnlockCustomer(CustomerAccount c)
 {
     c.Locked = false;
     c.FailedLoginCount = 0;
     c.LockedUntilUtc = DateTime.UtcNow.AddMilliseconds(-1);
     UpdateCustomer(c);
 }
        public ActionResult CreateAccount(SignInViewModel posted)
        {
            SignInSetup();
            SignInViewModel model = new SignInViewModel();

            // bail out if this is a private store that doesn't allow registrations
            if (ViewBag.IsPrivateStore) return View("SignIn", model);

            // Process Requrest
            ValidateModelResponse validated = ValidateLoginModel(posted, false);
            if (validated.Success == false)
            {
                foreach(string s in validated.ResultMessages)
                {
                    FlashWarning(s);
                }
            }
            else
            {
                bool result = false;
              
                CustomerAccount u = new CustomerAccount();

                if (u != null)
                {
                    u.Email = posted.Email.Trim();
                    CreateUserStatus s = CreateUserStatus.None;
                    // Create new user
                    result = MTApp.MembershipServices.CreateCustomer(u, ref s, posted.Password.Trim());

                    if (result == false)
                    {
                        switch (s)
                        {
                            case CreateUserStatus.DuplicateUsername:                                
                                FlashWarning("That email already exists. Select another email or login to your current account.");
                                break;
                            default:                                
                                FlashWarning("Unable to save user. Unknown error.");
                                break;
                        }
                    }
                    else
                    {
                        // Update bvin field so that next save will call updated instead of create
                        MerchantTribe.Web.Cookies.SetCookieString(MerchantTribe.Commerce.WebAppSettings.CookieNameAuthenticationTokenCustomer(MTApp.CurrentStore.Id),
                                                                  u.Bvin,
                                                                  this.Request.RequestContext.HttpContext, false, new EventLog());
                        Redirect("~/account");
                    }
                }
            }
            return View("SignIn", model);
        }
 public void CustomerCheckLock(CustomerAccount c)
 {
     if (c.Locked == true)
     {
         if (DateTime.Compare(DateTime.UtcNow, c.LockedUntilUtc) > 0)
         {
             UnlockCustomer(c);
         }
     }
     else
     {
         if (c.FailedLoginCount >= WebAppSettings.UserLockoutAttempts)
         {
             LockCustomer(c);
             EventLog.LogEvent("Membership", "User Account " + c.Email + " was locked.", EventLogSeverity.Warning);
         }
     }
 }
        // Create or Update
        public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata)
        {
            string data = string.Empty;
            string bvin = FirstParameter(parameters);
            ApiResponse<CustomerAccountDTO> response = new ApiResponse<CustomerAccountDTO>();

            CustomerAccountDTO postedItem = null;
            try
            {
                postedItem = MerchantTribe.Web.Json.ObjectFromJson<CustomerAccountDTO>(postdata);
            }
            catch(Exception ex)
            {
                response.Errors.Add(new ApiError("EXCEPTION", ex.Message));
                return MerchantTribe.Web.Json.ObjectToJson(response);                
            }

            CustomerAccount item = new CustomerAccount();
            item.FromDto(postedItem);

            if (bvin == string.Empty)
            {
                CustomerAccount existing = MTApp.MembershipServices.Customers.FindByEmail(item.Email);
                if (existing == null || existing.Bvin == string.Empty)
                {
                    string clearPassword = querystring["pwd"];
                    if (clearPassword.Trim().Length < 1)
                    {
                        clearPassword = MerchantTribe.Web.PasswordGenerator.GeneratePassword(10);
                    }
                    // Create
                    bool result = MTApp.MembershipServices.CreateCustomer(item, clearPassword);
                    bvin = item.Bvin;
                }
                else
                {
                    bvin = existing.Bvin;
                }
            }
            else
            {
                MTApp.MembershipServices.UpdateCustomer(item);
            }
            CustomerAccount resultItem = MTApp.MembershipServices.Customers.Find(bvin);
            if (resultItem != null)
            {
                response.Content = resultItem.ToDto();
                // Address Import
                foreach (AddressDTO a in postedItem.Addresses)
                {
                    Address addr = new Address();
                    addr.FromDto(a);
                    MTApp.MembershipServices.CheckIfNewAddressAndAddWithUpdate(resultItem,addr);
                }
            }
            
            data = MerchantTribe.Web.Json.ObjectToJson(response);            
            return data;
        }