public APIResult <FidelityCustomer> CreateFidelityAccountFromCookie(string campaignId) { var authenticatedUser = _authenticationService.GetAuthenticatedUser(); if (authenticatedUser != null) { FidelityUserPart fideliyPart = (FidelityUserPart)(((dynamic)authenticatedUser.ContentItem).FidelityUserPart); if (fideliyPart != null) { return(CreateFidelityAccount(fideliyPart, authenticatedUser.UserName, authenticatedUser.Email, campaignId)); } else { return new APIResult <FidelityCustomer> { success = false, data = null, message = "The user is already register in " + GetProviderName() } }; } else { return new APIResult <FidelityCustomer> { success = false, data = null, message = "Cookie not provided or not valid." } }; }
public virtual FidelityCustomer GetCustomerFromIdOrEmail(string custId) { FidelityUserPart fidelityPart = null; if (IsValidEmail(custId)) { var userPart = _orchardServices.ContentManager.HqlQuery().ForPart <UserPart>().Where(a => a.ContentPartRecord <UserPartRecord>(), x => x.Eq("Email", custId)).List().FirstOrDefault(); if (userPart == null) { return(null); } fidelityPart = userPart.ContentItem.As <FidelityUserPart>(); } else { var userList = _orchardServices.ContentManager.Query <FidelityUserPart, FidelityUserPartRecord>().Where(x => x.CustomerId == custId).List().ToList(); try { fidelityPart = userList.First(); } catch (InvalidOperationException) { return(null); } } string pass = Encoding.UTF8.GetString(_encryptionService.Decode(Convert.FromBase64String(fidelityPart.FidelityPassword))); return(new FidelityCustomer { Id = fidelityPart.CustomerId, Username = fidelityPart.FidelityUsername, Password = pass }); }
public virtual APIResult <FidelityCustomer> CreateFidelityAccount(FidelityUserPart fidelityPart, string username, string email, string campaignId) { if (fidelityPart != null && !String.IsNullOrWhiteSpace(username)) { FidelityCustomer customer = new FidelityCustomer(email, username, Membership.GeneratePassword(12, 4)); APIResult <FidelityCustomer> creationRequest = _sendService.SendCustomerRegistration(settingsPart, customer, campaignId); if (creationRequest.success) { fidelityPart.FidelityUsername = customer.Username; fidelityPart.FidelityPassword = Convert.ToBase64String(_encryptionService.Encode(Encoding.UTF8.GetBytes(customer.Password))); if (!string.IsNullOrWhiteSpace(customer.Id)) { fidelityPart.CustomerId = customer.Id; } } return(creationRequest); } else { return new APIResult <FidelityCustomer> { success = false, data = null, message = "The user is not configured to use " + GetProviderName() } }; }
/// <summary> /// Ritorna l'il FidelityCustomer associato all'User autenticato su Orchard /// </summary> /// <returns>FidelityCustomer se esiste un utente autenticato, null altrimenti</returns> public virtual FidelityCustomer GetCustomerFromAuthenticatedUser() { var authenticatedUser = _authenticationService.GetAuthenticatedUser(); if (authenticatedUser != null) { FidelityUserPart fidelityPart = (FidelityUserPart)(((dynamic)authenticatedUser.ContentItem).FidelityUserPart); if (fidelityPart != null && !String.IsNullOrWhiteSpace(fidelityPart.FidelityUsername) && !String.IsNullOrWhiteSpace(fidelityPart.FidelityPassword) ) { string pass = Encoding.UTF8.GetString(_encryptionService.Decode(Convert.FromBase64String(fidelityPart.FidelityPassword))); FidelityCustomer customer = new FidelityCustomer(authenticatedUser.Email, fidelityPart.FidelityUsername, pass); if (String.IsNullOrWhiteSpace(fidelityPart.CustomerId)) { fidelityPart.CustomerId = _sendService.SendCustomerDetails(settingsPart, customer).data.Id; } customer.Id = fidelityPart.CustomerId; return(customer); } } return(null); }