public void SaveSettings(string userName, EPiServerProfile data) { if (SaveUserSettings != null) { SaveUserSettings(this, new UserSettingsEventHandlerArgs(userName, data)); } }
public ActionResult Index(RegisterViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var result = UiUserProvider.CreateUser(model.Username, model.Password, model.Email, null, null, true, out var status, out var errors); if (status == UIUserCreateStatus.Success) { UiRoleProvider.CreateRole(AdminRoleName); UiRoleProvider.AddUserToRoles(result.Username, new string[] { AdminRoleName }); if (ProfileManager.Enabled) { var profile = EPiServerProfile.Wrap(ProfileBase.Create(result.Username)); profile.Email = model.Email; profile.Save(); } AdministratorRegistrationPage.IsEnabled = false; SetFullAccessToWebAdmin(); var resFromSignIn = UiSignInManager.SignIn(UiUserProvider.Name, model.Username, model.Password); if (resFromSignIn) { return(Redirect("/episerver/cms")); } } AddErrors(errors); // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult CreateAdmin() { string storedRoleName = "WebAdmins"; string userName = "******"; string password = "******"; string email = "*****@*****.**"; var admin = _uIUserProvider.GetUser(userName); if (admin == null) { UIUserCreateStatus status; IEnumerable <string> errors = Enumerable.Empty <string>(); _uIUserProvider.CreateUser(userName, password, email, null, null, true, out status, out errors); _uIRoleProvider.CreateRole(storedRoleName); _uIRoleProvider.AddUserToRoles(userName, new string[] { storedRoleName }); if (ProfileManager.Enabled) { var profile = EPiServerProfile.Wrap(ProfileBase.Create(userName)); profile.Email = email; profile.Save(); } } return(RedirectToAction("Index")); }
// GET: CommentUserBlock public override ActionResult Index(CommentUserBlock currentBlock) { EPiServerProfile currentUser = EPiServerProfile.Current; var model = new CommentUserViewModel { Body = currentBlock.Body, User = currentUser.UserName }; //PageHelper => get current page /* * DynamicDataStore store = DynamicDataStoreFactory.Instance.CreateStore("People", typeof(Person)); * Identity id = store.Save(p); */ var pageRouteHelper = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance <EPiServer.Web.Routing.IPageRouteHelper>(); var pageReference = pageRouteHelper.PageLink; var id = pageReference.ID; PersonWithIDynamicData newPerson = new PersonWithIDynamicData { Name = Guid.NewGuid().ToString(), CreatedDate = DateTime.Now }; DynamicDataStore store = DynamicDataStoreFactory.Instance.CreateStore("Comment", typeof(PersonWithIDynamicData)); var loadedPerson = store.LoadAll <PersonWithIDynamicData>(); //var id = store.Save(newPerson); return(PartialView(model)); }
public ActionResult Index(RegisterViewModel model) { if (ModelState.IsValid) { UIUserCreateStatus status; IEnumerable <string> errors = Enumerable.Empty <string>(); var result = UIUserProvider.CreateUser(model.Username, model.Password, model.Email, null, null, true, out status, out errors); if (status == UIUserCreateStatus.Success) { UIRoleProvider.CreateRole(AdminRoleName); UIRoleProvider.AddUserToRoles(result.Username, new string[] { AdminRoleName }); if (ProfileManager.Enabled) { var profile = EPiServerProfile.Wrap(ProfileBase.Create(result.Username)); profile.Email = model.Email; profile.Save(); } AdministratorRegistrationPage.IsEnabled = false; SetFullAccessToWebAdmin(); var resFromSignIn = UISignInManager.SignIn(UIUserProvider.Name, model.Username, model.Password); if (resFromSignIn) { return(Redirect(UrlResolver.Current.GetUrl(ContentReference.StartPage))); } } AddErrors(errors); } // If we got this far, something failed, redisplay form return(View(model)); }
private void UpdateEpiProfile(SiteUser user) { var profile = EPiServerProfile.Get(user.Username); profile["Email"] = user.Email; profile.Save(); }
public ActionResult Index(RegisterViewModel model) { if (ModelState.IsValid) { UIUserCreateStatus status; IEnumerable <string> errors = Enumerable.Empty <string>(); var result = _UIUserProvider.CreateUser(model.Username, model.Password, model.Email, null, null, true, out status, out errors); if (status == UIUserCreateStatus.Success) { //Check if role exists, if it does not create it and set full permission to all pages of the site SetFullAccessToRole(AdminRoleName); //Add the newly created user to the role. _UIRoleProvider.AddUserToRoles(result.Username, new string[] { AdminRoleName }); if (ProfileManager.Enabled) { var profile = EPiServerProfile.Wrap(ProfileBase.Create(result.Username)); profile.Email = model.Email; profile.Save(); } //After user creation, sign-in the user account and redirect to Episerver CMS var resFromSignIn = _UISignInManager.SignIn(_UIUserProvider.Name, model.Username, model.Password); if (resFromSignIn) { return(Redirect("/episerver/cms")); } } AddErrors(errors); } // If we got this far, something failed, redisplay form return(View(_ViewPath, model)); }
public ActionResult Get() { var _username = User.Identity.Name; var profile = EPiServerProfile.Get(_username); return(Rest(profile.Language)); }
/// <inheritdoc /> public override ModuleViewModel CreateViewModel(ModuleTable moduleTable, IClientResourceService clientResourceService) { var options = ServiceLocator.Current.GetInstance <ExternalReviewOptions>(); var model = new AdvancedReviewsModuleViewModel(this, clientResourceService, options); var profile = EPiServerProfile.Get(PrincipalInfo.CurrentPrincipal.Identity.Name); model.Language = profile.Language; return(model); }
/// <summary>Send subscription data to handler</summary> /// <param name="profile">The profile for a subscriber</param> /// <param name="rootPage">Root for subscription</param> /// <param name="changedPages">The pages that has changed</param> protected virtual void SendToHandler(EPiServerProfile profile, PageData rootPage, PageDataCollection changedPages) { IUpdateCurrentLanguage instance = ServiceLocator.Current.GetInstance <IUpdateCurrentLanguage>(); if (this._languageBranchRepository.Load(profile.Language) != null) { instance.UpdateLanguage(profile.Language); } else { instance.UpdateLanguage(ContentLanguage.Instance.FinalFallbackCulture.Name); } string subscriptionHandler1 = SubscriptionJob.FindSubscriptionHandler(rootPage); SubscriptionJob.log.Debug((object)string.Format("Start processing subscription mail for {0}", (object)profile.DisplayName)); SubscriptionJob.log.Debug((object)string.Format("Uses subscription handler: {0}", subscriptionHandler1.Length == 0 ? (object)"Default" : (object)subscriptionHandler1)); ISubscriptionHandler subscriptionHandler2; if (string.IsNullOrEmpty(subscriptionHandler1)) { subscriptionHandler2 = (ISubscriptionHandler) new Gosso.EpiserverLegacy.Personalization.Internal.SubscriptionMail(this._localizationService, this._siteDefinitionResolver); } else { subscriptionHandler2 = Activator.CreateInstance(Type.GetType(subscriptionHandler1, true, true)) as ISubscriptionHandler; if (subscriptionHandler2 == null) { throw new EPiServerException(string.Format("Failed to create a instance of \"{0}\", does it implement ISubscriptionHandler?", (object)Settings.Instance.SubscriptionHandler)); } } subscriptionHandler2.User = profile.UserName; subscriptionHandler2.UserData = profile; try { subscriptionHandler2.Send(rootPage, changedPages); SubscriptionJob.log.Debug((object)string.Format("Finished processing subscription mail for {0}", (object)profile.DisplayName)); } catch (ConfigurationErrorsException ex) { SubscriptionJob.log.Error((object)string.Format("Failed to send subscription to {0} due to a configuration error", (object)profile.DisplayName), (Exception)ex); throw; } catch (SmtpException ex) { SubscriptionJob.log.Error((object)string.Format("Failed to send subscription to {0}", (object)profile.DisplayName), (Exception)ex); if (ex.StatusCode == SmtpStatusCode.MailboxUnavailable) { return; } throw; } catch (Exception ex) { SubscriptionJob.log.Error((object)string.Format("Failed to send subscription to {0}", (object)profile.DisplayName), ex); } }
protected internal virtual void CreateAdministratorIfNecessary() { if (!_firstRequest) { return; } _firstRequest = false; if (!this.Request.IsLocal) { return; } var userProvider = ServiceLocator.Current.GetInstance <UIUserProvider>(); userProvider.GetAllUsers(0, 1, out var numberOfUsers); if (numberOfUsers > 0) { return; } var user = userProvider.CreateUser("Administrator", "P@ssword12", "*****@*****.**", null, null, true, out var status, out var errors); if (status == UIUserCreateStatus.Success) { const string administrationRoleName = "WebAdmins"; var roleProvider = ServiceLocator.Current.GetInstance <UIRoleProvider>(); roleProvider.CreateRole(administrationRoleName); roleProvider.AddUserToRoles(user.Username, new[] { administrationRoleName }); if (ProfileManager.Enabled) { var profile = EPiServerProfile.Get(user.Username); profile.Email = user.Email; profile.Save(); } var contentSecurityRepository = ServiceLocator.Current.GetInstance <IContentSecurityRepository>(); var contentSecurityDescriptor = contentSecurityRepository.Get(ContentReference.RootPage).CreateWritableClone() as IContentSecurityDescriptor; // ReSharper disable PossibleNullReferenceException contentSecurityDescriptor.AddEntry(new AccessControlEntry(administrationRoleName, AccessLevel.FullAccess)); // ReSharper restore PossibleNullReferenceException contentSecurityRepository.Save(ContentReference.RootPage, contentSecurityDescriptor, SecuritySaveType.Replace); } else { // ReSharper disable PossibleMultipleEnumeration throw new InvalidOperationException("Could not create administrator.", errors.Any() ? new InvalidOperationException(errors.First()) : null); // ReSharper restore PossibleMultipleEnumeration } }
protected void UpdateProfileImage(object sender, EventArgs e) { var userName = userPicker.SelectedValue; var selectedProfile = EPiServerProfile.Get(userName); var imageUrl = GetFilePath(); if (!string.IsNullOrEmpty(imageUrl)) { selectedProfile.SetPropertyValue("ProfileImage", imageUrl); selectedProfile.Save(); } }
/// <summary> /// Initialize ticket and user name /// </summary> private void Initialize() { var ticketParameter = Request[InvitationSender.TicketParameter]; Ticket = string.IsNullOrEmpty(ticketParameter) ? null : InvitationTicket.Decrypt(ticketParameter); if ((Ticket != null) && !string.IsNullOrEmpty(Ticket.Email)) { var enumerator = Membership.FindUsersByEmail(Ticket.Email).GetEnumerator(); UserName = enumerator.MoveNext() ? ((MembershipUser)enumerator.Current).UserName : string.Empty; } Profile = string.IsNullOrEmpty(UserName) ? EPiServerProfile.Current : EPiServerProfile.Get(UserName); }
protected void Subscribe_Click(object sender, EventArgs e) { EPiServerProfile user = EPiServerProfile.Current; user.SubscriptionInfo.Interval = Int32.Parse(Interval.SelectedItem.Value); if (Email.Enabled) { user.Email = Email.Text; } user.Save(); }
/// <summary> /// Creates new user /// <returns>If user was created</returns> /// </summary> private bool CreateUser() { try { Membership.CreateUser(TextBoxUserName.Text, TextBoxPassword.Text, Ticket.Email); UserName = TextBoxUserName.Text; Profile = EPiServerProfile.Get(UserName); return true; } catch (Exception) { return false; } }
/// <summary> /// Process subscriptions and send notification about changes to subscribers. /// </summary> /// <param name="profile">The profile for the subscriber</param> /// <returns> /// Actual number of subscription notification messages sent. /// </returns> protected virtual int SendSubscriptions(EPiServerProfile profile) { int num = 0; IPrincipal principal = _userImpersonation.CreatePrincipal(profile.UserName); foreach (SubscriptionDescriptor subscribedPage in profile.SubscriptionInfo.SubscribedPages) { PageData pageData; try { pageData = this._contentRepository.Get <PageData>((ContentReference) new PageReference(subscribedPage.PageID)); } catch (ContentNotFoundException) { if (SubscriptionJob.log.IsWarnEnabled) { SubscriptionJob.log.WarnFormat("The user {0} subscribes to the page {1} that does not exists.", (object)profile.UserName, (object)subscribedPage.PageID); continue; } continue; } if (pageData != null && pageData["EPSUBSCRIBE"] != null) { foreach (string language in subscribedPage.Languages) { PageDataCollection changedPages = this.GetChangedPages(profile, language, subscribedPage, principal); if (changedPages.Count != 0) { PageData rootPage = this.GetPage(subscribedPage.PageID, language, principal, false) ?? SubscriptionJob.CreateLanguageBranchContainer(language); if (this.CanSendSubscription(profile, rootPage, changedPages)) { ++num; this.SendToHandler(profile, rootPage, changedPages); } } } } } if (num > 0) { return(num); } return(profile.SubscriptionInfo.SubscribedPages.Count != 0 ? 0 : -1); }
protected void RefreshImage(object sender, EventArgs e) { var userName = userPicker.SelectedValue; var userProfile = EPiServerProfile.Get(userName); var imageUrl = userProfile.GetPropertyValue("ProfileImage").ToString(); if (string.IsNullOrEmpty(imageUrl)) { tbFilePath.Text = string.Empty; profileImagePreview.Visible = false; } else { tbFilePath.Text = imageUrl; profileImagePreview.ImageUrl = imageUrl; profileImagePreview.Visible = true; } }
private void AddUser(string userName, string fullName, string passWord, string[] roleNames) { if (UIUserProvider.GetUser(userName) == null) { var email = string.Format("epic-{0}@mailinator.com", userName); IEnumerable <string> erros; UIUserCreateStatus status; var user = UIUserProvider.CreateUser(userName, passWord, email, null, null, true, out status, out erros); UIRoleProvider.AddUserToRoles(user.Username, roleNames); var profile = EPiServerProfile.Get(user.Username); var nameParts = fullName.Split(' '); profile["FirstName"] = nameParts[0]; profile["LastName"] = nameParts[1]; // E-mail must be part of profile properties to be resolved by QueryableNotificationUsersImpl profile["Email"] = email; profile.Save(); } }
/// <summary> /// Adds the data from the form to the current profile. /// </summary> protected void SetPostedData() { EPiServerProfile user = EPiServerProfile.Current; user.Company = StripAnyTags(Company.Text); user.Email = StripAnyTags(Email.Text); user.FirstName = StripAnyTags(FirstName.Text); user.LastName = StripAnyTags(LastName.Text); user.Title = StripAnyTags(Title.Text); user.Country = StripAnyTags(Country.Text); MembershipUser membershipUser = Membership.GetUser(user.UserName); if (EPiServer.Security.ProviderCapabilities.IsSupported(membershipUser.ProviderName, EPiServer.Security.ProviderCapabilities.Action.Update)) { membershipUser.Email = user.Email; Membership.UpdateUser(membershipUser); } }
/// <summary>Execute subscription job</summary> protected virtual string InternalExecute() { int num1 = 0; int num2 = 0; label_1: int totalRecords; ProfileInfoCollection allProfiles = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All, num2++, 1000, out totalRecords); if (allProfiles.Count == 0) { return(string.Format("{0} user profiles were found. {1} subscription e-mails were sent.", (object)totalRecords, (object)num1)); } IEnumerator enumerator = allProfiles.GetEnumerator(); try { while (enumerator.MoveNext()) { EPiServerProfile profile = EPiServerProfile.Get(((ProfileInfo)enumerator.Current).UserName); if (!SubscriptionJob.IsInInterval(profile.SubscriptionInfo.Interval, profile.SubscriptionInfo.LastMessage)) { int num3 = this.SendSubscriptions(profile); if (num3 >= 0) { profile.SubscriptionInfo.LastMessage = DateTime.Now; num1 += num3; profile.Save(); } } } goto label_1; } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } }
protected void Subscribe_Click(object sender, EventArgs e) { EPiServerProfile user = EPiServerProfile.Current; if (Email.Enabled) { Page.Validate("SubscriptionWizard"); if (!Page.IsValid) { return; } user.Email = Email.Text; } user.SubscriptionInfo.Interval = Int32.Parse(Interval.SelectedItem.Value); user.Save(); }
/// <summary> /// Gets the changed pages under one subscription root for a specific user. /// </summary> /// <param name="profile">The profile for a user.</param> /// <param name="language">The requested language.</param> /// <param name="subscribedPage">The subscribed subscription root.</param> /// <param name="principal">The principal for the user.</param> /// <returns>A collection of pages that have been changed and are children of the subscribedPage.</returns> protected PageDataCollection GetChangedPages(EPiServerProfile profile, string language, SubscriptionDescriptor subscribedPage, IPrincipal principal) { IList <PageLanguage> pageLanguageList = this._subscriptionDB.PagesChangedAfter(subscribedPage.PageID, profile.SubscriptionInfo.LastMessage, 100); int count = pageLanguageList.Count; int pageID = -1; PageDataCollection pageDataCollection = new PageDataCollection(); IList <string> stringList = (IList <string>) new List <string>(); foreach (PageLanguage pageLanguage in (IEnumerable <PageLanguage>)pageLanguageList) { if (string.Compare(pageLanguage.LanguageID, language, StringComparison.InvariantCultureIgnoreCase) == 0) { if (pageLanguage.PageID != pageID && pageID != -1) { PageData page = this.GetPage(pageID, pageLanguage.LanguageID, principal, true); if (page != null) { pageDataCollection.Add(page); } stringList.Clear(); } stringList.Add(pageLanguage.LanguageID); pageID = pageLanguage.PageID; } } if (pageID != -1) { foreach (string language1 in (IEnumerable <string>)stringList) { PageData page = this.GetPage(pageID, language1, principal, true); if (page != null) { pageDataCollection.Add(page); } } } return(pageDataCollection); }
/// <summary> /// Loads the user data from the current profile to the form. /// </summary> private void LoadUserData() { if (EPiServerProfile.Enabled) { // Get preset properties EPiServerProfile user = EPiServerProfile.Current; Company.Text = user.Company; FirstName.Text = user.FirstName; LastName.Text = user.LastName; Title.Text = user.Title; Country.Text = user.Country; MembershipUser membershipUser = Membership.GetUser(user.UserName); if (membershipUser != null && !String.IsNullOrEmpty(membershipUser.Email)) { Email.Text = membershipUser.Email; } else { Email.Text = user.Email; } } }
/// <summary> /// Redirects to UserProfile /// </summary> private static void RedirectToUserProfilePage(PageBase page) { EPiServerProfile user = EPiServerProfile.Current; if (user.IsAnonymous || !(string.IsNullOrEmpty(user.FirstName) || string.IsNullOrEmpty(user.LastName))) { return; } PageReference start = GetWorkroomStartPageLink(page); PageReference parent = DataFactory.Instance.GetPage(start).ParentLink; PageDataCollection children = DataFactory.Instance.GetChildren(parent); PageData data = children.FirstOrDefault(child => child.PageTypeName.Equals(UserProfilePageTypeName)); if (data == null) { return; } string symbol = data.LinkURL.Contains("?") ? "&" : "?"; string url = HttpUtility.UrlEncode(page.Request.RawUrl); string callUrl = string.Format("{0}{1}{2}={3}", data.LinkURL, symbol, returnUrlUserProfile, url); page.Response.Redirect(callUrl); }
public void Init(EPiServerProfile profile, IPrincipal userPrincipal) { Group = "Public"; Principal = userPrincipal; }
public UserSettingsEventHandlerArgs(string userName, EPiServerProfile data) { UserName = userName; Data = data; }
/// <summary> /// Resolves the email. /// </summary> /// <param name="userName">Name of the user.</param> /// <returns></returns> private static string ResolveEmail(string userName) { EPiServerProfile profile = EPiServer.Personalization.EPiServerProfile.Get(userName); return(profile != null ? profile.EmailWithMembershipFallback : String.Empty); }
/// <summary> /// Resolves the first name. /// </summary> /// <param name="Name">The name.</param> /// <returns></returns> private static string ResolveFirstName(string userName) { EPiServerProfile profile = EPiServer.Personalization.EPiServerProfile.Get(userName); return(profile != null ? profile.FirstName : String.Empty); }
/// <summary> /// Controls if a user can be notified about page changes. Called for each subscription being processed. /// </summary> /// <param name="profile">User's profile</param> /// <param name="rootPage">The root page for the suscription</param> /// <param name="changedPages">The pages that has changed</param> /// <returns> /// <b>True</b> if the subscription notification can be sent. /// Returning <b>false</b> cancels the notification for this user. /// </returns> protected virtual bool CanSendSubscription(EPiServerProfile profile, PageData rootPage, PageDataCollection changedPages) { return(true); }