public static string UpdatePassword(string passwordData) { int updateCustomerId = 0; Hashtable cusHash = EncryptionHelper.Unpack(EncryptionHelper.Decrypt(passwordData, cryptKey)); GCDCustomer retCus = new GCDCustomer(cusHash); retCus.Success = false; if (cusHash.ContainsKey("CustomerID") && int.TryParse(cusHash["CustomerID"].ToString(), out updateCustomerId)) { if (cusHash.ContainsKey("NewPassword")) { string newPassword = cusHash["NewPassword"].ToString(); using (CastleClubEntities entities = new CastleClubEntities()) { Customer customer = entities.Customers.Where(c => c.Id == updateCustomerId).FirstOrDefault(); Password password = new Password(newPassword); customer.Password = password.SaltedPassword; customer.SaltKey = password.SaltKey; customer.UnEncryptPass = "";// newPassword; entities.SaveChanges(); retCus.Success = true; } } } return(EncryptionHelper.Encrypt(retCus.ToString(), cryptKey)); }
public static string LogonSecureByGroup(string logonData, string groupId) { GCDCustomer retCus = new GCDCustomer(); retCus.Success = false; retCus.AccountLocked = false; if (string.IsNullOrEmpty(groupId)) { groupId = "1181"; } using (CastleClubEntities entities = new CastleClubEntities()) { Site site = entities.Sites.Where(s => s.GroupId == groupId).FirstOrDefault(); if (site != null) { string li = EncryptionHelper.Decrypt(logonData, cryptKey); string[] linf = li.Split('&'); if (linf.Length == 2) { string[] cinf = linf[0].Split('='); string[] pinf = linf[1].Split('='); string email = cinf[1]; if (cinf.Length == 2 && pinf.Length == 2) { Customer customer = entities.Customers.Where(c => c.SiteId == site.Id && c.Email == email).FirstOrDefault(); if (customer != null) { string chkPass = pinf[1]; Password pwd = new Password(chkPass, customer.SaltKey); if (customer.BadLoginCount < 5 && customer.Password == pwd.SaltedPassword) { if (customer.Status != CustomerStatus.ACTIVE) { retCus.Messages = "Customer Account Not Found, Invalid or Cancelled"; } else { retCus.FirstName = customer.FirstName; retCus.LastName = customer.LastName; retCus.Address1 = customer.Address; retCus.Address2 = String.Empty; retCus.City = customer.City; retCus.State = entities.States.Where(s => s.Id == customer.StateId).FirstOrDefault().Name; retCus.Country = "USA"; retCus.Email = customer.Email; retCus.Phone = customer.Phone; retCus.CustomerID = customer.Id; retCus.RegisterDate = customer.CreatedAt; retCus.MemberID = "M" + site.GroupId + "-" + customer.Id; retCus.Validator = logonData; retCus.Success = true; retCus.Zip = customer.ZipCode; retCus.CreatedAt = customer.CreatedAt; var creditCard = customer.CreditCards.FirstOrDefault(); if (creditCard != null) { retCus.CreditCardNumber = creditCard.LastFourDigit; retCus.CreditCardType = creditCard.Type; retCus.CreditCardMonthExpired = 1; retCus.CreditCardYearExpired = DateTime.Now.Year; } customer.BadLoginCount = 0; entities.SaveChanges(); } } else { retCus.Messages = "Logon Failed"; if (customer.BadLoginCount > 4) { retCus.AccountLocked = true; } else { customer.BadLoginCount = customer.BadLoginCount + 1; entities.SaveChanges(); retCus.AccountLocked = false; } } } } } else { retCus.Messages = "Missing or Null Data Field"; } if (retCus.Success == false && retCus.Messages.Length == 0) { retCus.Messages = "Logon Failed"; } return(EncryptionHelper.Encrypt(retCus.ToString(), cryptKey)); } else { return(String.Empty); } } }
public static string UpdateCustomer(string customerData, bool sendEmail) { int updateCustomerId = 0; Hashtable cusHash = EncryptionHelper.Unpack(EncryptionHelper.Decrypt(customerData, cryptKey)); GCDCustomer retCus = new GCDCustomer(cusHash); GCDCreditCard retCreditCard = new GCDCreditCard(cusHash); retCus.Success = false; if (cusHash.ContainsKey("CustomerID") && int.TryParse(cusHash["CustomerID"].ToString(), out updateCustomerId)) { using (CastleClubEntities entities = new CastleClubEntities()) { Customer customer = entities.Customers.Where(c => c.Id == updateCustomerId).FirstOrDefault(); if (customer != null) { Password passwordHash = new Password(cusHash["PasswordOld"].ToString(), customer.SaltKey); if (customer.Password == passwordHash.SaltedPassword) { customer.FirstName = retCus.FirstName; customer.LastName = retCus.LastName; customer.Address = retCus.Address1; customer.City = retCus.City; State state = entities.States.FirstOrDefault(s => s.Name.ToLower() == retCus.State.ToLower()); customer.StateId = state != null?state.Id.ToString() : string.Empty; customer.Email = retCus.Email; customer.Phone = retCus.Phone; customer.ZipCode = retCus.Zip; var creditCard = customer.CreditCards.FirstOrDefault(); if (creditCard != null && !string.IsNullOrEmpty(retCreditCard.CreditCard) && Utils.CreditCardHelper.Valid(retCreditCard.CreditCard, false)) { var today = DateTime.Now; if (today.Year > retCus.CreditCardYearExpired || (today.Year == retCus.CreditCardYearExpired && today.Month >= retCreditCard.Month)) { throw new Exception("The credit card is invalid."); } var encryptData = CastleClub.BusinessLogic.Utils.EncryptionHelper.EncryptRSACertificate("ccNum:" + retCreditCard.CreditCard + ";cVV:;ccExp:" + Utils.CreditCardHelper.GetExpDate(retCreditCard.Month, retCreditCard.Year)); string lastFourDigit = retCreditCard.CreditCard.Substring(retCreditCard.CreditCard.Length - 4, 4); string type = Utils.CreditCardHelper.GetCardType(retCreditCard.CreditCard); creditCard.CreatedAt = DateTime.Now; creditCard.Data = encryptData; creditCard.LastFourDigit = lastFourDigit; creditCard.Type = type; long newPaymentProfile; string message = string.Empty; if (CastleClub.BusinessLogic.AuthorizeAPI.CIM.CreateNewCustomerPaymentProfile(customer.Site.GetDT(), customer.GetDT(false), retCreditCard.CreditCard, Utils.CreditCardHelper.GetExpDate(retCreditCard.Month, retCreditCard.Year), out newPaymentProfile, out message)) { creditCard.AuthorizePaymentProfileId = newPaymentProfile; } else { throw new Exception(message); } } bool setPassword = false; if (!string.IsNullOrEmpty(retCus.PasswordNow)) { Password password = new Password(retCus.PasswordNow); customer.Password = password.SaltedPassword; customer.SaltKey = password.SaltKey; setPassword = true; } retCus.Success = true; entities.SaveChanges(); if (sendEmail && setPassword) { string smtpAddress = CastleClub.BusinessLogic.Data.GlobalParameters.Smtp; string emailFrom = customer.Site.Email; string passwordEmail = customer.Site.PasswordEmail; //CastleClub.BusinessLogic.Data.GlobalParameters.EmailPassword; string subject = string.Format(Properties.Resources.SetPasswordSubjectEmail, customer.Site.Name); string body = string.Format(Properties.Resources.SetPasswordBodyEmail, customer.Site.Name, retCus.PasswordNow); Utils.Email.SendEmail(emailFrom, passwordEmail, smtpAddress, subject, body, new List <string>() { customer.Email }, false); } } else { retCus.Success = false; retCus.Messages = "The password for the customer not match."; } } else { retCus.Messages = "Error custmer ID."; } } } return(EncryptionHelper.Encrypt(retCus.ToString(), cryptKey)); }
public static string CreateCustomer(string data, bool sendEmail) { try { var hash = EncryptionHelper.Unpack(EncryptionHelper.Decrypt(data, cryptKey)); GCDSite site = new GCDSite(hash); GCDCustomer customer = new GCDCustomer(hash); customer.CreatedAt = DateTime.Now; customer.Success = false; if (!string.IsNullOrEmpty(site.GroupID) && !string.IsNullOrEmpty(customer.CreditCardNumber) && !string.IsNullOrEmpty(customer.Email)) { CustomerDT customerDT = new CustomerDT() { Address = customer.Address1, BadLoginCount = 0, CancelledDate = null, City = customer.City, ClearPassword = customer.Password, CreatedAt = customer.CreatedAt, Email = customer.Email, FirstName = customer.FirstName, LastName = customer.LastName, MemberId = customer.MemberID, NcId = 0, NextBillDate = DateTime.Now.AddDays(30), Phone = customer.Phone, StateId = CastleClub.BusinessLogic.Managers.LocationsManager.GetStates().FirstOrDefault(x => x.Name.ToLower() == customer.State.ToLower()).Id, Status = CustomerStatus.ACTIVE, ZipCode = customer.Zip }; //var siteDT = CastleClub.BusinessLogic.Managers.SitesManager.GetSite(customerDT.SiteId); customerDT = CastleClub.BusinessLogic.Managers.CustomersManager.NewCustomer(site.GroupID, customerDT, customer.CreditCardNumber, CreditCardHelper.GetExpDate(customer.CreditCardMonthExpired, customer.CreditCardYearExpired)); if (customerDT != null) { customer.Success = true; //if (sendEmail) /**** * if ((siteDT.SendWelcomeEmail) && (siteDT.WelcomeEmailDelay != null) && (siteDT.WelcomeEmailDelay == 0)) * //send welcome email if it hasn't a delay * { * string smtpAddress = siteDT.SmtpAddress;//CastleClub.BusinessLogic.Data.GlobalParameters.Smtp; * //var siteDT = CastleClub.BusinessLogic.Managers.SitesManager.GetSite(customerDT.SiteId); * * string emailFrom = siteDT.Email; * string passwordEmail = siteDT.PasswordEmail;//CastleClub.BusinessLogic.Data.GlobalParameters.EmailPassword; * string subject = string.Format(Properties.Resources.WelcomeSubjectEmail, siteDT.Name); * // + " " + customer.LastName * string body = string.Format(Properties.Resources.WelcomeBodyEmail, customer.FirstName, * customer.Email, customer.Password, siteDT.Name, siteDT.Name, "PartsGeek", * siteDT.Price, siteDT.PricePerQuarter, siteDT.Phone, siteDT.Email, siteDT.OfferDomain); * * Utils.Email.SendEmail(emailFrom, passwordEmail, smtpAddress, subject, body, new List<string>() { customer.Email }, true); * } * **/ } } else { customer.Messages = "Credit card and email are necessary."; } return(EncryptionHelper.Encrypt(customer.ToString(), cryptKey)); }catch (Exception e) { Utils.EventViewer.Writte("WEBSERVICE", "Create Customers", e.Message + " " + e.StackTrace, System.Diagnostics.EventLogEntryType.Error); throw e; } }
public static string ResetPasswordByGroup(string resetData, string groupId, bool sendMail) { int siteId = 0; Hashtable cusHash = EncryptionHelper.Unpack(EncryptionHelper.Decrypt(resetData, cryptKey)); GCDCustomer retCus = new GCDCustomer(cusHash); retCus.Success = false; if (cusHash.ContainsKey("Email") && int.TryParse(groupId, out siteId)) { using (CastleClubEntities entities = new CastleClubEntities()) { Site site = entities.Sites.FirstOrDefault(x => x.GroupId == siteId.ToString()); if (site != null) { siteId = site.Id; string email = cusHash["Email"].ToString(); Customer customer = entities.Customers.FirstOrDefault(c => c.SiteId == siteId && c.Email == email); if (customer != null) { /*Password password = new Password(); * customer.Password = password.SaltedPassword; * customer.SaltKey = password.SaltKey; * entities.SaveChanges(); * retCus.Success = true;*/ if (sendMail && !string.IsNullOrEmpty(retCus.Password)) { string smtpAddress = CastleClub.BusinessLogic.Data.GlobalParameters.Smtp; string emailFrom = site.Email; string passwordEmail = site.PasswordEmail; //CastleClub.BusinessLogic.Data.GlobalParameters.EmailPassword; string subject = string.Format(Properties.Resources.SetPasswordSubjectEmail, site.Name); var url = string.Format(GlobalParameters.UrlResetPassword, retCus.Password, retCus.Validator); //pasamos el dominio en password y el guid en validator string body = string.Format(Properties.Resources.SetPasswordBodyEmail, url, site.Name); Utils.Email.SendEmail(emailFrom, passwordEmail, smtpAddress, subject, body, new List <string>() { customer.Email }, true); retCus.Success = true; } else if (!sendMail && !string.IsNullOrEmpty(retCus.Password)) { Password password = new Password(retCus.Password); customer.Password = password.SaltedPassword; customer.SaltKey = password.SaltKey; entities.SaveChanges(); retCus.Success = true; } } else { retCus.Messages = "Invalid Email"; } } else { retCus.Messages = "Invalid GroupId"; } } } else { retCus.Messages = "Invalid Email"; } CastleClub.BusinessLogic.Utils.EventViewer.WriteToFile("Log Web Service", retCus.Messages, "c:\\users\\administrator\\desktop\\log.txt"); return(EncryptionHelper.Encrypt(retCus.ToString(), cryptKey)); }