Exemplo n.º 1
0
        public ActionResult CreateProfile(string profileName)
        {
            try
            {
                var profile = new shippingProfile()
                {
                    subdomainid = subdomainid.Value,
                    title       = profileName,
                    type        = ShippingProfileType.FLATRATE.ToString(),
                    permanent   = false
                };

                repository.AddShippingProfile(profile);

                return(Json(new
                {
                    profile.id,
                    profile.title
                }.ToJsonOKData()));
            }
            catch (Exception ex)
            {
                return(SendJsonErrorResponse(ex));
            }
        }
Exemplo n.º 2
0
        private void CreateDataStructures()
        {
            // CREATE DEFAULT STRUCTURES
            // add default inventory location
            var loc = new inventoryLocation
            {
                name       = GeneralConstants.INVENTORY_LOCATION_DEFAULT,
                subdomain  = mastersubdomain.id,
                lastUpdate = DateTime.UtcNow
            };

            repository.AddInventoryLocation(loc, mastersubdomain.id);

            // add default shipping profile
            var shippingProfile = new shippingProfile()
            {
                title       = "Default",
                type        = ShippingProfileType.FLATRATE.ToString(),
                subdomainid = mastersubdomain.id,
                permanent   = true
            };

            repository.AddShippingProfile(shippingProfile);

            // add default payment methods
            var method_bank = new paymentMethod
            {
                method       = PaymentMethod.BankTransfer.ToString(),
                name         = "Bank Deposit",
                instructions = "Please contact me for payment details"
            };

            mastersubdomain.paymentMethods.Add(method_bank);

            var method_cod = new paymentMethod
            {
                method       = PaymentMethod.COD.ToString(),
                name         = "Cash On Delivery",
                instructions = ""
            };

            mastersubdomain.paymentMethods.Add(method_cod);

            usr.passwordHash = Utility.ComputePasswordHash(email + password);

            // if user exist then we still need to verify email
            Random rnd = RandomNumberGenerator.Instance;

            usr.confirmationCode = rnd.Next();

            repository.Save();

            // generate liquid stuff
            new Thread(() => ThemeHandler.GenerateDefaultStructures(mastersubdomain.id)).Start();
        }
Exemplo n.º 3
0
        public void AddShippingProfile(shippingProfile profile)
        {
            // check if entry already exist
            var existing =
                db.shippingProfiles.SingleOrDefault(x => x.title == profile.title &&
                                                    x.subdomainid == profile.subdomainid &&
                                                    x.type == profile.type &&
                                                    x.etsy_templateid == profile.etsy_templateid);

            if (existing == null)
            {
                db.shippingProfiles.InsertOnSubmit(profile);
                db.SubmitChanges();
            }
            else
            {
                profile.id = existing.id;
            }
        }
Exemplo n.º 4
0
        public ActionResult NewAccount(string code, string id, string identifier, PageType pagetype)
        {
            var client = new OAuthFacebook(GeneralConstants.FACEBOOK_API_KEY, GeneralConstants.FACEBOOK_API_SECRET,
                                           HttpUtility.UrlEncode(
                                               string.Format(
                                                   "{0}/newaccount/{1}?identifier={2}&pagetype={3}",
                                                   GeneralConstants.FACEBOOK_APP_URL, id, identifier, pagetype)),
                                           "read_stream,email,publish_stream,offline_access,manage_pages");

            // starting our authorisation process
            if (string.IsNullOrEmpty(code))
            {
                return(RedirectToAction("Redirect", new{ url = client.AuthorizationLinkGet() }));
            }

            if (!client.AccessTokenGet(code))
            {
                return(View("Error", new FacebookViewData {
                    errorMessage = "Unable to obtain permission", pageUrl = pagetype.ToReturnUrl(identifier)
                }));
            }

            // check subdomain is valid
            id = id.ToLower();

            // also check special domain list
            if (GeneralConstants.SUBDOMAIN_RESTRICTED.Contains(id))
            {
                return(View("Error", new FacebookViewData {
                    errorMessage = "Store address is not available", pageUrl = pagetype.ToReturnUrl(identifier)
                }));
            }

            var mastersubdomain = repository.GetSubDomains().Where(x => x.name == id).SingleOrDefault();

            if (mastersubdomain != null)
            {
                return(View("Error", new FacebookViewData {
                    errorMessage = "Store address is not available", pageUrl = pagetype.ToReturnUrl(identifier)
                }));
            }

            var facebook = new FacebookService(client.token);
            var fb_usr   = facebook.People.GetUser("me");

            if (fb_usr == null)
            {
                return(View("Error", new FacebookViewData {
                    errorMessage = "Unable to create account", pageUrl = pagetype.ToReturnUrl(identifier)
                }));
            }

            // verify that email has not been used to register another account
            if (repository.GetUserByEmail(fb_usr.email).Where(x => (x.role & (int)UserRole.CREATOR) != 0).SingleOrDefault() != null)
            {
                Syslog.Write(ErrorLevel.INFORMATION, "Facebook email address in use: " + fb_usr.email);
                return(View("Error", new FacebookViewData {
                    errorMessage = "Email address is already registered", pageUrl = pagetype.ToReturnUrl(identifier)
                }));
            }

            var usr = new user
            {
                role                 = (int)UserRole.ADMIN,
                viewid               = Crypto.Utility.GetRandomString(),
                permissions          = (int)UserPermission.ADMIN,
                FBID                 = fb_usr.id,
                email                = fb_usr.email ?? "",
                externalProfileUrl   = fb_usr.link,
                firstName            = fb_usr.first_name,
                lastName             = fb_usr.last_name,
                gender               = fb_usr.gender,
                externalProfilePhoto = string.Format("https://graph.facebook.com/{0}/picture?type=large", fb_usr.id)
            };

            // create subdomain entry
            mastersubdomain = new MASTERsubdomain
            {
                flags                   = 0,
                name                    = id,
                total_outofstock        = 0,
                total_contacts_public   = 0,
                total_contacts_private  = 0,
                total_contacts_staff    = 0,
                total_invoices_sent     = 0,
                total_invoices_received = 0,
                total_orders_sent       = 0,
                total_orders_received   = 0,
                total_products_mine     = 0,
                accountType             = AccountPlanType.ULTIMATE.ToString()
            };

            repository.AddMasterSubdomain(mastersubdomain);

            // create organisation first
            var org = new organisation
            {
                subdomain = mastersubdomain.id,
                name      = fb_usr.name
            };

            repository.AddOrganisation(org);
            usr.organisation = org.id;

            // CREATE DEFAULT STRUCTURES
            // add default inventory location
            var loc = new inventoryLocation
            {
                name       = GeneralConstants.INVENTORY_LOCATION_DEFAULT,
                subdomain  = mastersubdomain.id,
                lastUpdate = DateTime.UtcNow
            };

            repository.AddInventoryLocation(loc, mastersubdomain.id);

            // add default shipping profile
            var shippingProfile = new shippingProfile()
            {
                title       = "Default",
                type        = ShippingProfileType.FLATRATE.ToString(),
                subdomainid = mastersubdomain.id
            };

            repository.AddShippingProfile(shippingProfile);

            // update subdomain entry
            mastersubdomain.creator = org.id;

            // create facebookpage to link to subdomain
            var newEntry = new facebookPage {
                subdomainid = mastersubdomain.id, pageid = identifier
            };

            repository.AddFacebookPage(newEntry);


            try
            {
                // if user exist then we still need to verify email
                Random rnd = RandomNumberGenerator.Instance;
                usr.confirmationCode = rnd.Next();
                repository.AddUser(usr);

                // generate photo
                new Thread(() => usr.externalProfilePhoto.ReadAndSaveFromUrl(mastersubdomain.id, usr.id, usr.id, PhotoType.PROFILE)).Start();

                // add access token
                var oauthdb = new oauth_token
                {
                    token_key    = client.token,
                    token_secret = "",
                    type         = OAuthTokenType.FACEBOOK.ToString(),
                    subdomainid  = mastersubdomain.id,
                    appid        = usr.id.ToString(),
                    authorised   = true
                };
                repository.AddOAuthToken(oauthdb);

                // obtain any other account tokens
                var accounts = facebook.Account.GetAccountTokens("me");
                if (accounts != null && accounts.data != null)
                {
                    foreach (var account in accounts.data)
                    {
                        if (account.name != null)
                        {
                            var ftoken = new facebook_token
                            {
                                pageid      = account.id,
                                subdomainid = mastersubdomain.id,
                                accesstoken = account.access_token,
                                name        = account.name
                            };
                            repository.AddUpdateFacebookToken(ftoken);
                        }
                    }
                }
                repository.Save();

                // send confirmation email
                var viewdata = new ViewDataDictionary()
                {
                    { "host", id.ToSubdomainUrl() },
                    { "confirmCode", usr.confirmationCode },
                    { "email", usr.email }
                };
                EmailHelper.SendEmailNow(EmailViewType.ACCOUNT_CONFIRMATION, viewdata, "New Account Details and Email Verification Link",
                                         usr.email, usr.ToFullName(), usr.id);
            }
            catch (Exception ex)
            {
                Syslog.Write(ex);
                return(View("Error", new FacebookViewData {
                    errorMessage = "Unable to create account", pageUrl = pagetype.ToReturnUrl(identifier)
                }));
            }

            return(RedirectToAction("Redirect", new { url = pagetype.ToReturnUrl(identifier) }));
        }