public bool CreateLoyalzooAccountFromPart(int partId) { try { ContentItem part = _contentManager.Get(partId); IUser userPart = part.As <IUser>(); LoyalzooUserPart loyalzooPart = part.As <LoyalzooUserPart>(); if (userPart != null && loyalzooPart != null) { APIResult createResult = _fidelityService.CreateLoyalzooAccount(loyalzooPart, userPart.UserName, userPart.Email); if (createResult.success) { return(true); } else { _notifier.Error(T("Registration failed: {0}", createResult.message)); } } else { _notifier.Error(T("The provided part cannot be used for registration.")); } return(false); } catch (Exception e) { _notifier.Error(T("Unable to register: {0}", e.Message)); return(false); } }
public void LoggedIn(IUser user) { try { var fidelitySettings = _orchardServices.WorkContext.CurrentSite.As <FidelitySiteSettingsPart>(); if (!string.IsNullOrWhiteSpace(fidelitySettings.DeveloperKey) && // Verifico che l'utente abbia già compilato le impostazioni della fidelity (fidelitySettings.RegisterOnLogin == LoyalzooRegistrationEnum.Always || (fidelitySettings.RegisterOnLogin == LoyalzooRegistrationEnum.External && _controllerContextAccessor.Context.Controller.GetType().FullName != "Orchard.Users.Controllers.AccountController"))) { LoyalzooUserPart loyalzooUserData = user.As <LoyalzooUserPart>(); if (string.IsNullOrWhiteSpace(loyalzooUserData.LoyalzooUsername) && string.IsNullOrWhiteSpace(loyalzooUserData.LoyalzooPassword) && string.IsNullOrWhiteSpace(loyalzooUserData.CustomerSessionId)) { APIResult accountCreationResult = _fidelityService.CreateLoyalzooAccountFromCookie(); if (accountCreationResult.success == true) { _controllerContextAccessor.Context.Controller.TempData.Add("LoyalzooRegistrationSuccess", true); } else { _controllerContextAccessor.Context.Controller.TempData.Add("LoyalzooRegistrationSuccess", false); } } } } catch { } }
public APIResult CreateLoyalzooAccountFromCookie() { try { var authenticatedUser = _authenticationService.GetAuthenticatedUser(); if (authenticatedUser != null) { LoyalzooUserPart loyalzooPart = authenticatedUser.As <LoyalzooUserPart>(); if (loyalzooPart != null) { return(CreateLoyalzooAccount(loyalzooPart, authenticatedUser.UserName, authenticatedUser.Email)); } else { return new APIResult { success = false, data = null, message = "The user is not configured to use Loyalzoo." } }; } else { return new APIResult { success = false, data = null, message = "Cookie not provided or not valid." } }; } catch (Exception e) { APIResult exceptionData = new APIResult(); exceptionData.success = false; exceptionData.message = e.Message; exceptionData.data = null; return(exceptionData); } }
public APIResult CreateLoyalzooAccountFromContext(CreateContentContext context) { try { IUser userPart = context.ContentItem.As <IUser>(); LoyalzooUserPart loyalzooPart = context.ContentItem.As <LoyalzooUserPart>(); if (userPart != null && loyalzooPart != null) { return(CreateLoyalzooAccount(loyalzooPart, userPart.UserName, userPart.Email)); //string userName = ""; //if (userPart.UserName == "testale2") // userName = Guid.NewGuid().ToString(); //else // userName = userPart.UserName; //return CreateLoyalzooAccount(loyalzooPart, userName, userPart.Email); } else { return new APIResult { success = false, data = null, message = "The user is not configured to use Loyalzoo." } }; } catch (Exception e) { APIResult exceptionData = new APIResult(); exceptionData.success = false; exceptionData.message = e.Message; exceptionData.data = null; return(exceptionData); } }
public APIResult CreateLoyalzooAccount(LoyalzooUserPart loyalzooPart, string username, string email) { try { APIResult result = new APIResult(); if (loyalzooPart != null && !String.IsNullOrWhiteSpace(username) && !String.IsNullOrWhiteSpace(email)) { if (String.IsNullOrWhiteSpace(loyalzooPart.LoyalzooUsername) && String.IsNullOrWhiteSpace(loyalzooPart.LoyalzooPassword) && String.IsNullOrWhiteSpace(loyalzooPart.CustomerSessionId)) { ConfigEnv configData = GetConfigData(); CDataCustomer customerData = new CDataCustomer(); customerData.first_name = username; customerData.email = email; customerData.username = username; customerData.password = Membership.GeneratePassword(12, 4); ILoyalzooCustomer customer = new Customer(); CResultCreate creationRequest = customer.Create(configData, customerData); if (creationRequest.success) { loyalzooPart.LoyalzooUsername = creationRequest.response.username; loyalzooPart.CustomerSessionId = creationRequest.response.session_id; loyalzooPart.LoyalzooPassword = Convert.ToBase64String(_encryptionService.Encode(Encoding.UTF8.GetBytes(customerData.password))); result.success = true; result.data = creationRequest.response; result.message = ""; } else { result.success = false; result.message = creationRequest.Errore.response; result.data = null; } } else { return new APIResult { success = false, data = null, message = "There is already some Loyalzoo data associated to the user. If you want to register a new account, delete the existing Loyalzoo data and then call this method again (any previous data associated to the user will be lost)." } }; } else { return new APIResult { success = false, data = null, message = "The user is not configured to use Loyalzoo." } }; return(result); } catch (Exception e) { APIResult exceptionData = new APIResult(); exceptionData.success = false; exceptionData.message = e.Message; exceptionData.data = null; return(exceptionData); } }