Пример #1
0
        public void ClearForeignNetworkLinks(string ForeignID, Customer.ForeignUserTypes type)
        {
            try
            {
                TableServiceContextV2 clearContext = new TableServiceContextV2(client.BaseUri.ToString(), client.Credentials);

                string partitionKey = ((int)type).ToString() + "+" + ForeignID;

                var f = (from e in clearContext.CreateQuery<CustomerForeignNetworkConnectionDb>(TableName) where e.PartitionKey == partitionKey select e).AsTableServiceQuery();

                List<string> custPartitions = new List<string>();

                foreach (CustomerForeignNetworkConnectionDb d in f)
                {
                    custPartitions.Add("Cust" + d.CustomerID.ToString());
                    clearContext.DeleteObject(d);
                }

                clearContext.SaveChangesWithRetries(SaveChangesOptions.Batch);

                foreach (string s in custPartitions)
                {
                    var c = (from e in context.CreateQuery<CustomerForeignNetworkConnectionDb>(TableName) where e.PartitionKey == s && e.RowKey == partitionKey select e).FirstOrDefault();
                    clearContext.DeleteObject(c);
                    clearContext.SaveChangesWithRetries();
                }

                clearContext = null;
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine("FOREIGN NETWORK EXCEPTION: " + e.ToString());
            }
        }
Пример #2
0
 public long Add(Customer c)
 {
     c.EmailAddress = c.EmailAddress.Trim().ToLower(); // store email addresses trimmed and in lowercase
     Database.Customer dbc = CustomerToDbCustomer(c);
     db.Customer.AddObject(dbc);
     db.SaveChanges();
     db.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbc);
     return dbc.ID;
 }
Пример #3
0
        public ChallengeStatus(ChallengeStatusDb d)
        {
            // this.UniqueID = d.RowKey;
            this.CustomerID = d.CustomerID;
            this.ChallengeID = d.ChallengeID;
            this.Status = d.Status;
            this.ChallengeOriginatorCustomerID = d.ChallengeOriginatorCustomerID;

            this.Customer = null;
        }
Пример #4
0
 public long Add(Customer c)
 {
     var p = CustToDynParm(c);
     using (SqlConnection db = new SqlConnection(connStr))
     {
         db.Open();
         p.Add("@InsertID", dbType: DbType.Int64, direction: ParameterDirection.Output);
         db.Execute("spCustomerAdd", p, commandType: CommandType.StoredProcedure);
         return p.Get<long>("@InsertID");
     }
 }
Пример #5
0
        public static Dictionary<string, long> GetNotifyQueueMessageData(NotifyType emailType, Customer Source, Customer Target, Challenge Challenge)
        {
            Dictionary<string, long> data = new Dictionary<string, long>();

            data.Add("nType", (long)emailType);
            if(Source!=null)
                data.Add("SrcID", Source.ID);
            if(Target!=null)
                data.Add("TgtID", Target.ID);
            if(Challenge!=null)
                data.Add("ChaID", Challenge.ID);

            return data;
        }
Пример #6
0
        public OnboardResult CompleteFirstStepForeignUserOnboard(string handle, Customer.ForeignUserTypes type, string token = null, string tokenSecret = null)
        {
            OnboardResult r = new OnboardResult();

            Customer c = RepoFactory.GetCustomerRepo().GetWithForeignUserID(handle, type);

            if (c == null)
            {
                Customer newCust = new Customer()
                {
                    ForeignUserID = handle,
                    ForeignUserType = (int)type,
                    Type = (int)Customer.TypeCodes.Unclaimed,
                    BillingType = (int)BillingSystem.BillingProcessorFactory.SupportedBillingProcessor.None
                };

                newCust.ID = RepoFactory.GetCustomerRepo().Add(newCust);

                RepoFactory.GetCustomerRepo().AddForeignNetworkForCustomer(newCust.ID, handle, type);

                r.Customer = newCust;
            }
            else
            {
                // we don't put this in the repo, we're just
                // using it as a DTO to get the token and secret
                // back to the controller
                r.Customer = c;
            }

            OnboardToken newToken = new OnboardToken()
            {
                CustomerID = r.Customer.ID,
                VerificationString = System.Guid.NewGuid().ToString(),
                Token = token,
                Secret = tokenSecret,
                AccountType = (int)type,
                ForeignUserID = handle
            };

            RepoFactory.GetOnboardTokenRepo().Add(newToken);

            r.OnboardToken = newToken;

            return r;
        }
Пример #7
0
        private DMTDataRepositories.Database.Customer CustomerToDbCustomer(Customer cust)
        {
            if (cust == null)
                return null;

            DMTDataRepositories.Database.Customer dbCust = new DMTDataRepositories.Database.Customer(); // Database.Customer.CreateCustomer(cust.ID, cust.FirstName, cust.LastName);

            if (cust.FirstName == null) cust.FirstName = "";
            if (cust.LastName == null) cust.LastName = "";
            if (cust.EmailAddress == null) cust.EmailAddress = "";
            if (cust.Password == null) cust.Password = "";
            if (cust.Address == null) cust.Address = "";
            if (cust.Address2 == null) cust.Address2 = "";
            if (cust.City == null) cust.City = "";
            if (cust.State == null) cust.State = "";
            if (cust.ZIPCode == null) cust.ZIPCode = "";
            if (cust.FacebookAccessToken == null) cust.FacebookAccessToken = "";
            if (cust.FacebookExpires == null) cust.FacebookExpires = "";
            if (cust.FacebookUserID == null) cust.FacebookUserID = "";
            if (cust.BillingID == null) cust.BillingID = "";
            if (cust.BillingType == null) cust.BillingType = 0;
            if (cust.AvatarURL == null) cust.AvatarURL = "";

            dbCust.FirstName = cust.FirstName;
            dbCust.LastName = cust.LastName;
            dbCust.EmailAddress = cust.EmailAddress;
            dbCust.Password = cust.Password;
            dbCust.Address1 = cust.Address;
            dbCust.Address2 = cust.Address2;
            dbCust.City = cust.City;
            dbCust.State = cust.State;
            dbCust.ZIPCode = cust.ZIPCode;
            dbCust.FacebookAccessToken = cust.FacebookAccessToken;
            dbCust.FacebookExpires = cust.FacebookExpires;
            dbCust.FacebookUserID = cust.FacebookUserID;
            dbCust.BillingID = cust.BillingID;
            dbCust.BillingType = cust.BillingType;
            dbCust.AvatarURL = cust.AvatarURL;
            dbCust.Type = cust.Type;

            return dbCust;
        }
Пример #8
0
        public void AddForeignNetworkForCustomer(long ID, string ForeignID, Customer.ForeignUserTypes type)
        {
            CustomerForeignNetworkConnection f = new CustomerForeignNetworkConnection { CustomerID = ID, UserID = ForeignID, Type = (int)type };

            // store it for both kinds of lookup:
            //      * by foreign ID
            //      * by customer ID
            //
            CustomerForeignNetworkConnectionDb fDB1 = new CustomerForeignNetworkConnectionDb(f, true);
            CustomerForeignNetworkConnectionDb fDB2 = new CustomerForeignNetworkConnectionDb(f, false);

            context.AttachTo(TableName, fDB1, null);
            context.AttachTo(TableName, fDB2, null);

            context.UpdateObject(fDB1);
            context.UpdateObject(fDB2);

            context.SaveChangesWithRetries();

            context.Detach(fDB1);
            context.Detach(fDB2);
        }
Пример #9
0
 public Customer GetWithForeignUserID(string ID, Customer.ForeignUserTypes type)
 {
     return this.GetWithID(this.GetIDForForeignUserID(ID, type));
 }
Пример #10
0
        public long GetIDForForeignUserID(string ID, Customer.ForeignUserTypes type)
        {
            string partitionKey = ((int)type).ToString() + "+" + ID;

            System.Diagnostics.Trace.WriteLine("Trying to find foreign user " + partitionKey);

            var f = (from e in context.CreateQuery<CustomerForeignNetworkConnectionDb>(TableName) where e.PartitionKey == partitionKey select e).FirstOrDefault<CustomerForeignNetworkConnectionDb>();

            if (f != null && f.CustomerID > 0)
            {
                System.Diagnostics.Trace.WriteLine("Found foreign user " + partitionKey + " with customer ID " + f.CustomerID.ToString());
                return f.CustomerID;
            }
            else
            {
                System.Diagnostics.Trace.WriteLine("Couldn't find foreign user " + partitionKey);
                return 0;
            }
        }
Пример #11
0
        //[HttpPost]
        //public void Claim(
        /*
        private void CoreHandleFacebookSignup(Customer newCustomer)
        {
            Customer tryFB = Repo.GetWithFacebookID(newCustomer.FacebookUserID);

            // if we have an unclaimed FB user, claim them now
            // rather than making a new account.
            if (tryFB != null && tryFB.FacebookUserID == newCustomer.FacebookUserID)
            {
                tryFB.Type = (int)Customer.TypeCodes.Default;
                tryFB.FacebookAccessToken = newCustomer.FacebookAccessToken;
                tryFB.FacebookExpires = newCustomer.FacebookExpires;

                Repo.Update(tryFB);
            }
            else
            {
                Repo.Add(newCustomer);
            }

        }*/
        private void CoreCreateSendVerificationEmail(Customer newCustomer)
        {
            AuthorizationRepository authRepo = new AuthorizationRepository();

            Authorization a = new Authorization("verify-" + Guid.NewGuid().ToString());
            a.Valid = false;
            a.EmailAddress = newCustomer.EmailAddress;
            a.CustomerID = newCustomer.ID;

            authRepo.Add(a);

            String authUrl = "http://dareme.to/verify/" + a.Token;
        }
Пример #12
0
 public ChallengeStatus()
 {
     this.Customer = null;
 }
Пример #13
0
        public void Update(Customer profile)
        {
            Customer c = Repo.GetWithID(profile.ID);

            if (Security.DetermineAudience(c) != Security.Audience.Owner)
                throw new HttpResponseException(System.Net.HttpStatusCode.Forbidden);

            if(profile.FirstName!=null && !profile.FirstName.Equals(""))
                c.FirstName = profile.FirstName;

            if (profile.LastName != null && !profile.LastName.Equals(""))
                c.LastName = profile.LastName;

            if (profile.AvatarURL != null && !profile.AvatarURL.Equals(""))
                c.AvatarURL = profile.AvatarURL;

            if (profile.Address != null && !profile.Address.Equals(""))
                c.Address = profile.Address;

            if (profile.Address2 != null && !profile.Address2.Equals(""))
                c.Address2 = profile.Address2;

            if (profile.City != null && !profile.City.Equals(""))
                c.City = profile.City;

            if (profile.State != null && !profile.State.Equals(""))
                c.State = profile.State;

            if (profile.ZIPCode != null && !profile.ZIPCode.Equals(""))
                c.ZIPCode = profile.ZIPCode;

            Repo.Update(c);
        }
Пример #14
0
 public Audience DetermineVisibility(Customer c)
 {
     return Audience.Users;
 }
Пример #15
0
        private DynamicParameters CustToDynParm(Customer c, bool inclID=false)
        {
            var p = new DynamicParameters();

            if (c.FirstName == null)
                c.FirstName = "";
            if (c.LastName == null)
                c.LastName = "";
            if (c.EmailAddress == null)
                c.EmailAddress = "";
            if (c.Address == null)
                c.Address = "";
            if (c.Address2 == null)
                c.Address2 = "";
            if (c.City == null)
                c.City = "";
            if (c.State == null)
                c.State = "";
            if (c.ZIPCode == null)
                c.ZIPCode = "";
            if (c.FacebookAccessToken == null)
                c.FacebookAccessToken = "";
            if (c.FacebookExpires == null)
                c.FacebookExpires = "";
            if (c.FacebookUserID == null)
                c.FacebookUserID = "";
            if (c.Password == null)
                c.Password = "";
            if (c.BillingID == null)
                c.BillingID = "";
            if (c.AvatarURL == null)
                c.AvatarURL = "";

            p.Add("@FirstName", c.FirstName, dbType: DbType.String, direction: ParameterDirection.Input);
            p.Add("@LastName", c.LastName, dbType: DbType.String, direction: ParameterDirection.Input);
            p.Add("@EmailAddress", c.EmailAddress, dbType: DbType.String, direction: ParameterDirection.Input);
            p.Add("@Address", c.Address, dbType: DbType.String, direction: ParameterDirection.Input);
            p.Add("@Address2", c.Address2, dbType: DbType.String, direction: ParameterDirection.Input);
            p.Add("@City", c.City, dbType: DbType.String, direction: ParameterDirection.Input);
            p.Add("@State", c.State, dbType: DbType.String, direction: ParameterDirection.Input);
            p.Add("@ZIPCode", c.ZIPCode, dbType: DbType.String, direction: ParameterDirection.Input);
            p.Add("@FacebookAccessToken", c.FacebookAccessToken, dbType: DbType.String, direction: ParameterDirection.Input);
            p.Add("@FacebookExpires", c.FacebookExpires, dbType: DbType.String, direction: ParameterDirection.Input);
            p.Add("@FacebookUserID", c.FacebookUserID, dbType: DbType.String, direction: ParameterDirection.Input);
            p.Add("@Password", c.Password, dbType: DbType.String, direction: ParameterDirection.Input);
            p.Add("@BillingType", c.BillingType, dbType: DbType.Int32, direction: ParameterDirection.Input);
            p.Add("@BillingID", c.BillingID, dbType: DbType.String, direction: ParameterDirection.Input);
            p.Add("@Type", c.Type, dbType: DbType.Int32, direction: ParameterDirection.Input);
            p.Add("@AvatarURL", c.AvatarURL, dbType: DbType.String, direction: ParameterDirection.Input);
            p.Add("@ForeignUserType", c.ForeignUserType, dbType: DbType.Int32, direction: ParameterDirection.Input);
            if (inclID)
                p.Add("@ID", c.ID, dbType: DbType.Int64, direction: ParameterDirection.Input);

            return p;
        }
Пример #16
0
 public Customer GetWithForeignUserID(string ID, Customer.ForeignUserTypes type)
 {
     throw new NotImplementedException();
 }
Пример #17
0
        public bool LinkForeignUserToCustomer(Customer custToLink, string handle, Customer.ForeignUserTypes type)
        {
            ICustomerRepository custRepo=RepoFactory.GetCustomerRepo();
            OnboardResult res = new OnboardResult();

            if (type == Customer.ForeignUserTypes.Twitter)
            {
                if (!handle.StartsWith("@"))
                    handle = "@" + handle;
            }

            Customer c = custRepo.GetWithForeignUserID(handle, type);
            if (c != null)
            {
                if (c.ID == custToLink.ID)
                    return true;

                if (c.Type != (int)Customer.TypeCodes.Unclaimed)
                    return false;

                try
                {
                    RepoFactory.GetChallengeRepo().MoveChallengesToCustomer(c.ID, custToLink.ID);
                    custRepo.RemoveForeignNetworkForCustomer(c.ID, handle, type);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Trace.WriteLine("Onboard Exception: " + e.ToString());
                }

                custRepo.Remove(c.ID);
            }

            custRepo.AddForeignNetworkForCustomer(custToLink.ID, handle, type);
            return true;
        }
Пример #18
0
 public static void NotifyNewChallenge(Customer Source, Customer Target, Challenge Challenge)
 {
     RepoFactory.GetProcessingQueue().PutQueueMessage(ProcessingQueue.MessageType.Notify,
         GetNotifyQueueMessageData(NotifyType.NewChallenge, Source, Target, Challenge));
 }
Пример #19
0
 public static void NotifyChallengeYouBackedAwardedDissented(Customer Target, Challenge Challenge)
 {
     RepoFactory.GetProcessingQueue().PutQueueMessage(ProcessingQueue.MessageType.Notify,
         GetNotifyQueueMessageData(NotifyType.ChallengeYouBackedAwardedDissented, null, Target, Challenge));
 }
Пример #20
0
        public void RemoveForeignNetworkForCustomer(long ID, string ForeignID, Customer.ForeignUserTypes type)
        {
            CustomerForeignNetworkConnection f = new CustomerForeignNetworkConnection { CustomerID = ID, UserID = ForeignID, Type = (int)type };

            CustomerForeignNetworkConnectionDb fDB1 = new CustomerForeignNetworkConnectionDb(f, true);
            CustomerForeignNetworkConnectionDb fDB2 = new CustomerForeignNetworkConnectionDb(f, false);

            context.AttachTo(TableName, fDB1);
            context.AttachTo(TableName, fDB2);

            context.DeleteObject(fDB1);
            context.SaveChangesWithRetries();

            context.DeleteObject(fDB2);
            context.SaveChangesWithRetries();
        }
Пример #21
0
 public void Update(Customer c)
 {
     using (SqlConnection db = new SqlConnection(connStr))
     {
         db.Open();
         var p = CustToDynParm(c, true);
         db.Execute("spCustomerUpdate", p, commandType: CommandType.StoredProcedure);
     }
 }
Пример #22
0
        public static Customer Filter(Customer c)
        {
            Customer filtered = new Customer();

            filtered.ID = c.ID;
            filtered.FirstName = c.FirstName;
            filtered.LastName = c.LastName;
            filtered.AvatarURL = c.AvatarURL;

            return filtered;
        }
Пример #23
0
        private Customer FilterForAudience(Customer c, Security.Audience Audience)
        {
            Customer filtered = new Customer();

            switch (Audience)
            {
                case Security.Audience.Anybody:
                    filtered.FirstName = c.FirstName;
                    filtered.LastName = c.LastName;
                    filtered.AvatarURL = c.AvatarURL;
                    filtered.ID = c.ID;
                    break;
                case Security.Audience.Friends:
                    filtered.FirstName = c.FirstName;
                    filtered.LastName = c.LastName;
                    filtered.AvatarURL = c.AvatarURL;
                    filtered.ID = c.ID;
                    break;
                case Security.Audience.Owner:
                    filtered = c;
                    filtered.Password = null;
                    break;
                case Security.Audience.Users:
                    filtered.FirstName = c.FirstName;
                    filtered.LastName = c.LastName;
                    filtered.AvatarURL = c.AvatarURL;
                    filtered.ID = c.ID;
                    break;
            }

            return filtered;
        }
Пример #24
0
 public Audience DetermineAudience(Customer c)
 {
     return CoreDetermineAudience(c.ID);
 }
Пример #25
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Customer EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCustomer(Customer customer)
 {
     base.AddObject("Customer", customer);
 }
Пример #26
0
 /// <summary>
 /// Create a new Customer object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="firstName">Initial value of the FirstName property.</param>
 /// <param name="lastName">Initial value of the LastName property.</param>
 public static Customer CreateCustomer(global::System.Int64 id, global::System.String firstName, global::System.String lastName)
 {
     Customer customer = new Customer();
     customer.ID = id;
     customer.FirstName = firstName;
     customer.LastName = lastName;
     return customer;
 }
Пример #27
0
        private Customer DbCustomerToCustomer(Database.Customer dbCust)
        {
            if (dbCust == null)
                return null;

            Customer c = new Customer();

            c.ID = dbCust.ID;
            c.FirstName = dbCust.FirstName;
            c.LastName = dbCust.LastName;
            c.EmailAddress = dbCust.EmailAddress;
            c.Address = dbCust.Address1;
            c.Address2 = dbCust.Address2;
            c.City = dbCust.City;
            c.State = dbCust.State;
            c.ZIPCode = dbCust.ZIPCode;
            c.FacebookUserID = dbCust.FacebookUserID;
            c.FacebookAccessToken = dbCust.FacebookAccessToken;
            c.FacebookExpires = dbCust.FacebookExpires;
            c.BillingID = dbCust.BillingID;
            c.Password = dbCust.Password;
            c.AvatarURL = dbCust.AvatarURL;

            if(dbCust.BillingType!=null)
                c.BillingType = (int)dbCust.BillingType;

            return c;
        }
Пример #28
0
        public static Customer Filter(Customer c)
        {
            Customer filtered = new Customer();

            filtered.Address = null;
            filtered.Address2 = null;
            filtered.BillingID = null;
            filtered.BillingType = 0;
            filtered.City = null;
            filtered.State = null;
            filtered.ZIPCode = null;
            filtered.Password = null;
            filtered.EmailAddress = null;
            filtered.FacebookAccessToken = null;
            filtered.FacebookExpires = null;
            filtered.FacebookUserID = null;

            filtered.ID = c.ID;
            filtered.FirstName = c.FirstName;
            filtered.LastName = c.LastName;
            filtered.AvatarURL = c.AvatarURL;

            return filtered;
        }
Пример #29
0
 public void Update(Customer c)
 {
     Database.Customer dbc=CustomerToDbCustomer(c);
     db.Customer.Attach(dbc);
     db.SaveChanges();
 }
Пример #30
0
        public void Signup(Customer newCustomer)
        {
            if (newCustomer.AvatarURL == null || newCustomer.AvatarURL.Equals(""))
                newCustomer.AvatarURL = "http://images.dareme.to/avatars/default.jpg";

            if(newCustomer.Password==null || newCustomer.Password.Equals(""))
            {
                // no authentication details provided for this customer
                throw new HttpResponseException("No credentials were supplied -- a password are required.", System.Net.HttpStatusCode.InternalServerError);
            }

            //newCustomer.BillingType = (int)BillingSystem.BillingProcessorFactory.SupportedBillingProcessor.Stripe;
            newCustomer.BillingType = (int)BillingSystem.BillingProcessorFactory.SupportedBillingProcessor.None;

            if (newCustomer.FirstName == null || newCustomer.FirstName.Equals("") || newCustomer.LastName == null || newCustomer.LastName.Equals(""))
                throw new HttpResponseException("New customers must supply a first and last name.", System.Net.HttpStatusCode.InternalServerError);

            CustomerSignupResult c=this.HandleCredentialSignup(newCustomer);

            if (c.Result != CustomerSignupResult.ResultCode.Success)
                throw new HttpResponseException("Couldn't sign up the new customer: " + c.Result.ToString(), System.Net.HttpStatusCode.Forbidden);

            // send back a blank 200; the client should now try to authorize
        }