public ActionResult SilentLogin(string token)
        {
            var service = new IdentityService();
            var response = service.SignIn(token);

            if (response.Status)
            {
                return RedirectToAction("Index");
            }
            else
            {
                return RedirectToAction("Login");
            }
        }
        public ActionResult Register(string ReturnUrl, AccountRegistrationViewModel model)
        {
            try
            {
                var orderConfiguration = Utilities.GetCurrentMarket().Configuration.Orders;

                // Save the customer
                var request = new CreateCustomerRequest(); //removed model.middlename because is not used in project JWJ 02July2015
                request.FirstName = model.FirstName;
                request.LastName = model.LastName;
                request.Email = model.Username;
                request.Phone = model.PhoneNumber;

                request.CanLogin = true;
                request.LoginName = model.Username;
                request.LoginPassword = model.Password;
                request.CustomerType = CustomerTypes.RetailCustomer;

                request.CustomerStatus = CustomerStatuses.Active;

                request.InsertEnrollerTree = true;
                request.EnrollerID = (model.EnrollerID != 0) ? model.EnrollerID : Identity.Owner.CustomerID;
                request.SponsorID = Identity.Owner.CustomerID;
                request.InsertUnilevelTree = true;
                request.EntryDate = DateTime.Now;
                request.DefaultWarehouseID = orderConfiguration.WarehouseID;
                request.CurrencyCode = orderConfiguration.CurrencyCode;
                request.LanguageID = orderConfiguration.LanguageID;

                var response = Exigo.WebService().CreateCustomer(request);

                // Sign the customer into their backoffice
                var service = new IdentityService();
                service.SignIn(model.Username, model.Password);

                if (ReturnUrl.IsNotEmpty()) return Redirect(ReturnUrl);
                else return RedirectToAction("index", "account", new { webalias = Identity.Owner.WebAlias });
            }
            catch (Exception e)
            {
                ViewBag.Error = e.Message;
                if (ReturnUrl.IsNotEmpty()) return RedirectToAction("register", "account", new { success = false, ReturnUrl = ReturnUrl, webalias = Identity.Owner.WebAlias });
                else return RedirectToAction("register", "account", new { success = false, webalias = Identity.Owner.WebAlias });

            }
        }
 /// <summary>
 /// Refreshes the current identity by fetching a fresh identity and saving it to the autnehtication cookie.
 /// </summary>
 public void Refresh()
 {
     var service = new IdentityService();
     service.CreateFormsAuthenticationTicket(this.CustomerID);
 }
        public JsonNetResult Login(LoginViewModel model)
        {
            var service = new IdentityService();
            var response = service.SignIn(model.LoginName, model.Password);

            if (response.Status)
            {
                var selectedCountry = GlobalUtilities.GetSelectedCountryCode();

                if (response.Country != selectedCountry)
                {
                    Exigo.PropertyBags.Delete(PropertyBag);
                    Exigo.PropertyBags.Delete(ShoppingCart);

                    var country = (response.Country.IsEmpty()) ? "US" : response.Country;

                    GlobalUtilities.SetSelectedCountryCode(country);

                    GlobalUtilities.SetCurrentCulture();
                }
            }

            return new JsonNetResult(response);
        }
 public static CustomerIdentity Deserialize(string data)
 {
     try
     {
         var ticket = FormsAuthentication.Decrypt(data);
         return new CustomerIdentity(ticket);
     }
     catch
     {
         var service = new IdentityService();
         service.SignOut();
         return null;
     }
 }