public int UpdateFrom24() { // se è attiva la feature Laser.Orchard.Mobile, attiva anche Laser.Orchard.PushGateway if (_utilsServices.FeatureIsEnabled("Laser.Orchard.Mobile")) { _utilsServices.EnableFeature("Laser.Orchard.PushGateway"); } // se è attiva la feature Laser.Orchard.CommunicationGateway attiva anche Laser.Orchard.Mobile if (_utilsServices.FeatureIsEnabled("Laser.Orchard.CommunicationGateway")) { _utilsServices.EnableFeature("Laser.Orchard.Mobile"); } return(25); }
protected override void Published(PublishContentContext context) // L'update delle risposte può essere fatto solo nel published, altrimenti si alza un'eccezione "save the transient instance before flushing..." { base.Published(context); var userRegistrationPolicy = context.ContentItem.As <UserRegistrationPolicyPart>(); if (userRegistrationPolicy == null) { return; } if (_utilsServices.FeatureIsEnabled("Laser.Orchard.Policy")) { var policies = _usersExtensionsServices.BuildEditorForRegistrationPolicies(); if (_controllerAccessor.Context != null) { var answers = _controllerAccessor.Context.Controller.TempData["VolatileAnswers"] != null ? _controllerAccessor.Context.Controller.TempData["VolatileAnswers"].ToString() : ""; //userRegistrationPolicy.VolatileAnswers; if (!String.IsNullOrWhiteSpace(answers)) { var updateModel = policies.Select(x => new PolicyForUserViewModel { PolicyTextId = x.PolicyId, Accepted = answers.Split(',').Contains(x.PolicyId.ToString()), AnswerDate = DateTime.MinValue, // verrà automaticamente valorizzata in fase di salvataggio OldAccepted = false // non valorizza UserId in caso di nuove policy perché viene valorizzato dal metodo che le salva }).ToList(); _policyServices.PolicyForUserMassiveUpdate(updateModel, (IUser)context.ContentItem.As <UserPart>()); _controllerAccessor.Context.Controller.TempData["VolatileAnswers"] = null; } } } }
protected override void GetItemMetadata(GetContentItemMetadataContext context) { if (context.ContentItem.ContentType != "Site") { return; } if (_utilsServices.FeatureIsEnabled("Laser.Orchard.Policy")) { base.GetItemMetadata(context); context.Metadata.EditorGroupInfo.Add(new GroupInfo(T("UserExtras"))); } }
//GET protected override DriverResult Editor(UserRegistrationPolicyPart part, dynamic shapeHelper) { if (currentControllerAction != CONTROLLER_ACTION) { return(null); } if (_utilsServices.FeatureIsEnabled("Laser.Orchard.Policy")) { var shapeName = "Parts_UserRegistrationPolicy_Edit"; var templateName = "Parts/UserRegistrationPolicy_Edit"; var policies = _usersExtensionsServices.BuildEditorForRegistrationPolicies(); return(ContentShape(shapeName, () => shapeHelper.EditorTemplate(TemplateName: templateName, Model: policies, Prefix: Prefix))); } else { return(null); } }
protected override DriverResult Display(CommunicationContactPart part, string displayType, dynamic shapeHelper) { // check sulle permission (esclude il modulo Generator) if (_controllerContextAccessor.Context.Controller.GetType().Namespace != "Laser.Orchard.Generator.Controllers") { if (!IsAuthorized) { throw new System.Security.SecurityException("You do not have permission to access this content."); } } if (_utilsService.FeatureIsEnabled("Laser.Orchard.UserProfiler")) { IUserProfilingService _userProfilingService; if (_orchardServices.WorkContext.TryResolve <IUserProfilingService>(out _userProfilingService)) { var profiling = _userProfilingService.GetList(part.UserIdentifier); ((dynamic)(part.ContentItem)).ContactProfilingPart.Profiling = profiling; } } //Determine if we're on an admin page bool isAdmin = AdminFilter.IsApplied(_orchardServices.WorkContext.HttpContext.Request.RequestContext); if (isAdmin) { if (displayType == "Detail") { string logs = T("No log.").Text; if (string.IsNullOrWhiteSpace(part.Logs) == false) { logs = part.Logs; } var profile = part.ContentItem.Parts.FirstOrDefault(x => x.PartDefinition.Name == "ProfilePart"); return(Combined(ContentShape("Parts_CommunicationContact", () => shapeHelper.Parts_CommunicationContact(Logs: logs)), ContentShape("Parts_ProfilePart", () => shapeHelper.Parts_ProfilePart(ContentPart: profile)) )); } else { return(null); } } else { return(null); } }
//POST protected override DriverResult Editor(UserRegistrationPolicyPart part, IUpdateModel updater, dynamic shapeHelper) { var policyPart = part.As <PolicyPart>(); var settings = _orchardServices.WorkContext.CurrentSite.As <UserRegistrationSettingsPart>(); IList <UserPolicyAnswerWithContent> policies; if (part.As <PolicyPart>() != null && part.As <UserPart>() == null) { // The content has the PolicyPart and is not a User. // Having UserRegistrationPolicyPart means that we want to display policy accaptance before Saving/Publishing the content. policies = _usersExtensionsServices.BuildEditorForPolicies(policyPart); } else if (currentControllerAction != CONTROLLER_ACTION) { return(null); } else if (_utilsServices.FeatureIsEnabled("Laser.Orchard.Policy") && settings.IncludePendingPolicy == Policy.IncludePendingPolicyOptions.Yes) { policies = _usersExtensionsServices.BuildEditorForRegistrationPolicies(); } else { return(null); } if (updater != null && updater.TryUpdateModel(policies, Prefix, null, null)) { if (policies.Count(x => ( (x.PolicyAnswer == false) && x.UserHaveToAccept)) > 0) { updater.AddModelError("NotAcceptedPolicies", T("User has to accept policies!")); } //Insert answers in a ViewBag so they can be used from other modules var answers = policies.Select(x => new PolicyAnswer { PolicyTextId = x.PolicyId, Accepted = x.PolicyAnswer }).ToList(); _controllerAccessor.Context.Controller.ViewBag.PolicyAnswers = answers; _controllerAccessor.Context.Controller.TempData["VolatileAnswers"] = String.Join(",", policies.Where(x => x.PolicyAnswer).Select(x => x.PolicyId.ToString())); } return(ContentShape(_shapeName, () => shapeHelper.EditorTemplate(TemplateName: _templateName, Model: policies, Prefix: Prefix))); }
public ActionResult Index() { if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to manage open authentication settings"))) { return(new HttpUnauthorizedResult()); } var settings = _orchardServices.WorkContext.CurrentSite.As <OpenAuthenticationSettingsPart>(); var currentProviders = _providerConfigurationService.GetAll(); var viewModel = new IndexViewModel { AutoRegistrationEnabled = settings.AutoRegistrationEnabled, AutoMergeNewUsersEnabled = settings.AutoMergeNewUsersEnabled, CurrentProviders = currentProviders, ShowAppDirectSetting = _utilServices.FeatureIsEnabled("Laser.Orchard.OpenAuthentication.AppDirect"), AppDirectBaseUrl = settings.AppDirectBaseUrl }; return(View(viewModel)); }
public void Register(UserRegistration userRegistrationParams) { if (RegistrationSettings.UsersCanRegister) { var policyAnswers = new List <PolicyForUserViewModel>(); if (_utilsServices.FeatureIsEnabled("Laser.Orchard.Policy") && UserRegistrationExtensionsSettings.IncludePendingPolicy == Policy.IncludePendingPolicyOptions.Yes) { IEnumerable <PolicyTextInfoPart> policies = GetUserLinkedPolicies(userRegistrationParams.Culture); // controllo che tutte le policy abbiano una risposta e che le policy obbligatorie siano accettate var allRight = true; foreach (var policy in policies) { var policyId = policy.Id; var policyRequired = policy.UserHaveToAccept; var answer = userRegistrationParams.PolicyAnswers.Where(w => w.PolicyId == policyId).SingleOrDefault(); if (answer != null) { if (!answer.PolicyAnswer && policyRequired) { allRight = false; } } else if (answer == null && policyRequired) { allRight = false; } if (answer != null) { policyAnswers.Add(new PolicyForUserViewModel { OldAccepted = false, PolicyTextId = policyId, Accepted = answer.PolicyAnswer, AnswerDate = DateTime.Now }); } } if (!allRight) { throw new SecurityException(T("User has to accept policies!").Text); } } var registrationErrors = new List <string>(); if (ValidateRegistration(userRegistrationParams.Username, userRegistrationParams.Email, userRegistrationParams.Password, userRegistrationParams.ConfirmPassword, out registrationErrors)) { var createdUser = _membershipService.CreateUser(new CreateUserParams( userRegistrationParams.Username, userRegistrationParams.Password, userRegistrationParams.Email, userRegistrationParams.PasswordQuestion, userRegistrationParams.PasswordAnswer, (RegistrationSettings.UsersAreModerated == false) && (RegistrationSettings.UsersMustValidateEmail == false), false )); // _membershipService.CreateUser may return null and tell nothing about why it failed to create the user // if the Creating user event handlers set the flag to cancel user creation. if (createdUser == null) { throw new SecurityException(T("User registration failed.").Text); } // here user was created var favCulture = createdUser.As <FavoriteCulturePart>(); if (favCulture != null) { var culture = _commonsServices.ListCultures().SingleOrDefault(x => x.Culture.Equals(userRegistrationParams.Culture)); if (culture != null) { favCulture.Culture_Id = culture.Id; } else { // usa la culture di default del sito favCulture.Culture_Id = _cultureManager.GetCultureByName(_cultureManager.GetSiteCulture()).Id; } } if ((RegistrationSettings.UsersAreModerated == false) && (RegistrationSettings.UsersMustValidateEmail == false)) { _userEventHandler.LoggingIn(userRegistrationParams.Username, userRegistrationParams.Password); _authenticationService.SignIn(createdUser, userRegistrationParams.CreatePersistentCookie); // solleva l'evento LoggedIn sull'utente _userEventHandler.LoggedIn(createdUser); } // [HS] BEGIN: Whe have to save the PoliciesAnswers cookie and persist answers on the DB after Login/SignIn events because during Login/Signin events database is not updated yet and those events override cookie in an unconsistent way. if (_utilsServices.FeatureIsEnabled("Laser.Orchard.Policy") && UserRegistrationExtensionsSettings.IncludePendingPolicy == Policy.IncludePendingPolicyOptions.Yes) { _policyServices.PolicyForUserMassiveUpdate(policyAnswers, createdUser); } // [HS] END if (RegistrationSettings.UsersMustValidateEmail) { // send challenge e-mail var siteUrl = _orchardServices.WorkContext.CurrentSite.BaseUrl; if (string.IsNullOrWhiteSpace(siteUrl)) { siteUrl = HttpContext.Current.Request.ToRootUrlString(); } UrlHelper urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); _userService.SendChallengeEmail(createdUser, nonce => urlHelper.MakeAbsolute(urlHelper.Action("ChallengeEmail", "Account", new { Area = "Orchard.Users", nonce = nonce }), siteUrl)); } } else { throw new SecurityException(String.Join(", ", registrationErrors)); } } else { throw new SecurityException(T("User cannot register due to Site settings").Text); } }