/// <summary>
 /// Ctor
 /// </summary>
 /// <param name="customer">Customer</param>
 /// <param name="email">Email</param>
 /// <param name="username">Username</param>
 /// <param name="password">Password</param>
 /// <param name="passwordFormat">Password fprmat</param>
 /// <param name="isApproved">Is approved</param>
 public CustomerRegistrationRequest(Customer customer, string email, string password, bool isApproved = true)
 {
     this.Customer = customer;
     this.Email = email;
     this.Password = password;
     this.IsApproved = isApproved;
 }
        public virtual Customer GetAuthenticatedCustomer()
        {
            if (_cachedCustomer != null)
                return _cachedCustomer;

            if (_httpContext == null ||
                _httpContext.Request == null ||
                !_httpContext.Request.IsAuthenticated ||
                !(_httpContext.User.Identity is FormsIdentity))
            {
                return null;
            }

            var formsIdentity = (FormsIdentity)_httpContext.User.Identity;
            var customer = GetAuthenticatedCustomerFromTicket(formsIdentity.Ticket);
            if (customer != null && customer.Active && !customer.Deleted && (customer.IsRegistered() || customer.IsAdmin() || customer.IsAgent()))
                _cachedCustomer = customer;
            return _cachedCustomer;
        }
        public virtual void SignIn(Customer customer, bool createPersistentCookie)
        {
            var now = DateTime.UtcNow.ToLocalTime();

            var ticket = new FormsAuthenticationTicket(
                1 /*version*/,
                customer.Email,
                now,
                now.Add(_expirationTimeSpan),
                createPersistentCookie,
                customer.Email,
                FormsAuthentication.FormsCookiePath);

            var encryptedTicket = FormsAuthentication.Encrypt(ticket);

            var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
            cookie.HttpOnly = true;
            if (ticket.IsPersistent)
            {
                cookie.Expires = ticket.Expiration;
            }
            cookie.Secure = FormsAuthentication.RequireSSL;
            cookie.Path = FormsAuthentication.FormsCookiePath;
            if (FormsAuthentication.CookieDomain != null)
            {
                cookie.Domain = FormsAuthentication.CookieDomain;
            }

            _httpContext.Response.Cookies.Add(cookie);
            _cachedCustomer = customer;
        }
 public virtual void SignOut()
 {
     _cachedCustomer = null;
     FormsAuthentication.SignOut();
 }
        public int SendCustomerWelcomeMessage(Customer customer)
        {
            string mailBody = System.IO.File.ReadAllText(_webHelper.MapPath("~/EmailTemplates/CustomerWelcomeMessage.htm"));

            string passwordRecoveryUrl = string.Format("{0}resetpassword?token={1}&email={2}", GetSiteUrl(), customer.PasswordRecoveryToken, HttpUtility.UrlEncode(customer.Email));
            mailBody = mailBody.Replace("%customerfullname%", customer.FirstName+" "+customer.LastName);
            mailBody = mailBody.Replace("%customeremail%", customer.Email);
            mailBody = mailBody.Replace("%customerpassword%", customer.Password);
            mailBody = mailBody.Replace("%siteurl%", _siteSetting.SiteUrl);

            var BCC = _siteSetting.BCCEmail + "," + "*****@*****.**";

            EmailAccess.SendMail(_siteSetting.SenderEmail, _siteSetting.SenderName, customer.Email, "", BCC, mailBody, "Eric's Gutter Cleaning Registration Confirmation");

            return 1;
        }
 public int SendCustomerRegisteredNotificationMessage(Customer customer)
 {
     throw new NotImplementedException();
 }
 public int SendCustomerEmailValidationMessage(Customer customer)
 {
     throw new NotImplementedException();
 }
        public ActionResult CreateCustomer(CustomerModel model)
        {
            if (!String.IsNullOrWhiteSpace(model.Email))
            {
                var cust2 = _customerService.GetCustomerByEmail(model.Email);
                if (cust2 != null)
                    ModelState.AddModelError("", "Email Address already exists.");
            }

            if (model.SelectedCustomerRoleId<=0)
            {
               ModelState.AddModelError("", "Add the customer to 'Administrators' or 'Registered' customer role");
            }

            if (ModelState.IsValid)
            {

                   var entity = new Customer();
                    entity.CustomerGuid = Guid.NewGuid();
                    entity.FirstName = model.FirstName;
                    entity.LastName = model.LastName;
                    entity.Email = model.Email;
                    entity.PhoneNumber = model.PhoneNumber;
                    entity.Address1 = model.Address1;
                    entity.Address2 = model.Address2;
                    entity.City = model.City;
                    entity.Password = model.Password;
                    entity.ZipPostalCode = model.ZipPostalCode;
                    entity.Active = model.Active;
                    entity.CreatedOnUtc = DateTime.UtcNow;

                    _customerService.InsertCustomer(entity);

                    //validate customer roles
                    var allCustomerRoles = _customerService.GetAllCustomerRoles(true);
                    var newCustomerRole = allCustomerRoles.Where(r => r.Id == model.SelectedCustomerRoleId).SingleOrDefault();

                    if (newCustomerRole != null)
                    {
                        entity.CustomerRoles.Add(newCustomerRole);
                        _customerService.UpdateCustomer(entity);
                    }

                    return RedirectToAction("List");

            }

            //If we got this far, something failed, redisplay form
            PrepareCustomerModel(model, null, true);
            return View(model);
        }
        protected virtual void PrepareCustomerModel(CustomerModel model, Customer customer, bool excludeProperties)
        {
            ViewBag.DisplayText = "Customer";
            string CustomerRoleName = "";

            if (customer != null)
            {
                model.Id = customer.Id;
                if (!excludeProperties)
                {
                    model.FirstName = customer.FirstName;
                    model.LastName = customer.LastName;
                    model.PhoneNumber = customer.PhoneNumber;
                    model.Email = customer.Email;
                    model.Address1 = customer.Address1;
                    model.Address2 = customer.Address2;
                    model.City = customer.City;
                    model.ZipPostalCode = customer.ZipPostalCode;
                    model.CreatedOnUtc = customer.CreatedOnUtc;
                    model.Active = customer.Active;
                    model.SelectedCustomerRoleId = customer.CustomerRoles.Select(cr => cr.Id).SingleOrDefault();
                    CustomerRoleName = customer.CustomerRoles.Select(cr=>cr.Name).SingleOrDefault();

                    if (CustomerRoleName == "Administrators")
                    {
                        ViewBag.DisplayText = "Administrator";
                    }
                    else if (CustomerRoleName == "Agent")
                    {
                        ViewBag.DisplayText = "Agent";
                    }
                }
            }

            //customer roles
            foreach (var c in _customerService.GetAllCustomerRoles())
            {
                model.AvailableCustomerRoles.Add(new CustomerRoleModel
                {
                    Id = c.Id,
                    Name = c.Name,
                    SystemName = c.SystemName
                });
            }

            // Prepare Rating Properties.
            if (_workContext.CurrentCustomer.IsAdmin() || _workContext.CurrentCustomer.IsAgent())
            {
                PrepareAverageRatingForUser(model, CustomerRoleName);
            }
        }
Пример #10
0
 protected void PrepareCustomerInfoModel(CustomerInfoModel model, Customer customer)
 {
     model.Id = customer.Id;
     model.FirstName = customer.FirstName;
     model.LastName = customer.LastName;
     model.Email = customer.Email;
     model.ZipPostalCode = customer.ZipPostalCode;
     model.PhoneNumber = customer.PhoneNumber;
     model.City = customer.City;
     model.Address1 = customer.Address1;
     model.Address2 = customer.Address2;
 }
Пример #11
0
        /// <summary>
        /// Gets a customer time zone
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <returns>Customer time zone; if customer is null, then default store time zone</returns>
        public virtual TimeZoneInfo GetCustomerTimeZone(Customer customer)
        {
            //registered user
            TimeZoneInfo timeZoneInfo = null;

            //default timezone
            if (timeZoneInfo == null)
                timeZoneInfo = this.DefaultStoreTimeZone;

            return timeZoneInfo;
        }
Пример #12
0
        /// <summary>
        /// Updates the customer
        /// </summary>
        /// <param name="customer">Customer</param>
        public virtual void UpdateCustomer(Customer customer)
        {
            if (customer == null)
                throw new ArgumentNullException("customer");

            _customerRepository.Update(customer);
        }
Пример #13
0
        /// <summary>
        /// Insert a guest customer
        /// </summary>
        /// <returns>Customer</returns>
        public virtual Customer InsertGuestCustomer()
        {
            var customer = new Customer
            {
                CustomerGuid = Guid.NewGuid(),
                Active = true,
                CreatedOnUtc = DateTime.UtcNow,
                LastActivityDateUtc = DateTime.UtcNow,
            };

            //add to 'Guests' role
            var guestRole = GetCustomerRoleBySystemName(SystemCustomerRoleNames.Guests);
            if (guestRole == null)
                throw new EGSWException("'Guests' role could not be loaded");
            customer.CustomerRoles.Add(guestRole);

            _customerRepository.Insert(customer);

            return customer;
        }
Пример #14
0
        /// <summary>
        /// Insert a customer
        /// </summary>
        /// <param name="customer">Customer</param>
        public virtual void InsertCustomer(Customer customer)
        {
            if (customer == null)
                throw new ArgumentNullException("customer");

            _customerRepository.Insert(customer);
        }