コード例 #1
0
        public void OverrideCacheForCurrentMember(string cacheKeyPrefix)
        {
            var currentMember = _membershipHelper.GetCurrentMember();

            if (currentMember == null)
            {
                throw new InvalidOperationException("No member is logged in.");
            }

            var cachePolicy = _policyRegistry.Get <ISyncPolicy>(CacheConstants.MemberOverridePolicy);

            cachePolicy.Execute(x => true, new Context(CacheConstants.MemberOverridePolicy + cacheKeyPrefix + currentMember.Key));
        }
コード例 #2
0
        // Check if a member is logged in or not
        private static bool MemberLoggedIn()
        {
            var msHelper      = new MembershipHelper(UmbracoContext.Current);
            var currentMember = msHelper.GetCurrentMember();

            return(currentMember != null ? true : false);
        }
        public string GetMemberProfileFieldValue(string alias)
        {
            if (HttpContext.Current.Request.IsAuthenticated)
            {
                var membershipHelper = new MembershipHelper(UmbracoContext.Current);
                var member           = membershipHelper.GetCurrentMember();
                if (member != null && member.HasProperty(alias))
                {
                    return(member.GetPropertyValue <string>(alias));
                }
            }

            return(string.Empty);
        }
        public string GetMemberType()
        {
            if (HttpContext.Current.Request.IsAuthenticated)
            {
                var membershipHelper = new MembershipHelper(UmbracoContext.Current);
                var member           = membershipHelper.GetCurrentMember();
                if (member != null)
                {
                    return(member.DocumentTypeAlias);
                }
            }

            return(string.Empty);
        }
コード例 #5
0
        public string GetMemberType()
        {
            if (HttpContext.Current.Request.IsAuthenticated)
            {
                var membershipHelper = new MembershipHelper(UmbracoContext.Current);
                var member = membershipHelper.GetCurrentMember();
                if (member != null)
                {
                    return member.DocumentTypeAlias;
                }

            }

            return string.Empty;
        }
        private static bool CanEditTournament(Tournament tournament, MembershipHelper membershipHelper)
        {
            var currentMember = membershipHelper.GetCurrentMember();

            if (currentMember == null)
            {
                return(false);
            }

            if (tournament.MemberKey == currentMember.Key)
            {
                return(true);
            }

            return(membershipHelper.IsMemberAuthorized(null, new[] { Groups.Administrators }, null));
        }
コード例 #7
0
        public ActionResult LogoutView(MemberModel model)
        {
            MembershipUser member = Membership.GetUser();

            if (member != null)
            {
                MembershipHelper  membershipHelper = new MembershipHelper(Umbraco.UmbracoContext);
                IPublishedContent username         = membershipHelper.GetCurrentMember();
                if (username != null)
                {
                    string memberName = username.Name;
                    model.Name = memberName != null ? memberName : member.UserName;
                }
            }
            return(PartialView("Member/Logout", model));
        }
コード例 #8
0
        public static IContent CreateUserContent(string name, int parentID, string documentTypeAlias)
        {
            IContent content = cs.CreateContent(name, parentID, documentTypeAlias);

              string author;
              MembershipHelper members = new MembershipHelper(UmbracoContext.Current);
              if (members.IsLoggedIn())
            author = members.GetCurrentMember().Name;
              else
            author = "anonymous";

              content.SetValue("isappealed", false);
              content.SetValue("author", author);

              return content;
        }
コード例 #9
0
        /// <summary>
        /// Returns Welcome message
        /// </summary>
        /// <returns>Welcome message</returns>
        public string GetWelcomeMessage()
        {
            var    member         = _membershipHelper.GetCurrentMember();
            var    firstName      = member.GetPropertyValue <string>("msFirstName");
            var    lastName       = member.GetPropertyValue <string>("msLastName");
            string welcomeMessage = "Welcome!";

            if (!firstName.IsNullOrWhiteSpace() && !lastName.IsNullOrWhiteSpace())
            {
                welcomeMessage = string.Format("Welcome, {0} {1}!", firstName, lastName);
            }
            else if (!firstName.IsNullOrWhiteSpace() && lastName.IsNullOrWhiteSpace())
            {
                welcomeMessage = string.Format("Welcome, {0}!", firstName);
            }
            return(welcomeMessage);
        }
コード例 #10
0
    void SimpilyForumsController_OnPostSaved(IContent sender, SimpilyForumsEventArgs e)
    {
        // we get passed IContent - but as we are going to go get loads of
        // other content, we will be quicker using IPublishedContent
        var umbHelper = new UmbracoHelper(UmbracoContext.Current);
        var mbrHelper = new MembershipHelper(UmbracoContext.Current);

        var post = umbHelper.TypedContent(sender.Id);

        if (post == null)
        {
            return;
        }

        // for us - the current user will have been the author
        var author = mbrHelper.GetCurrentMember();

        // work out the root of this post (top of the thread)
        var postRoot = post;

        if (post.Parent.DocumentTypeAlias == "Simpilypost")
        {
            // if we have a parent post, then this is a reply
            postRoot = post.Parent;
        }

        LogHelper.Info <ForumNotificationMgr>("Sending Notification for new post for {0}", () => postRoot.Name);

        List <string> receipients = GetRecipients(postRoot, mbrHelper);

        // remove the author from the list.
        var postAuthor = GetAuthorEmail(post, mbrHelper);

        if (receipients.Contains(postAuthor))
        {
            receipients.Remove(postAuthor);
        }

        if (receipients.Any())
        {
            SendNotificationEmail(postRoot, post, author, receipients, e.NewPost);
        }
    }
コード例 #11
0
        public Building CreateBuilding(Building building, string documentType, int parentId = 0)
        {
            //TODO: this way to find the 'main' parent sucks, should find a better way
            //through umbraco application published context
            var accountPropValue = Context.PublishedContentRequest.PublishedContent
                                   .Parent
                                   .Parent
                                   .GetValidPropertyValue(Constants.ACCOUNT_PROPERTY_ALIAS).ToString();

            int accountId = -1;

            int.TryParse(accountPropValue, out accountId);

            if (accountId <= 0)
            {
                return(null);
            }

            //if account prop value was found
            var memberId = _memberHelper.GetCurrentMember().Id;

            Building newBuilding = new Building();

            newBuilding.AccountId   = accountId;
            newBuilding.CreatedBy   = memberId;
            newBuilding.ModifiedBy  = memberId;
            newBuilding.CreatedOn   = DateTime.Now;
            newBuilding.ModifiedOn  = DateTime.Now;
            newBuilding.Description = building.Description;
            newBuilding.Name        = building.Name;


            var buildingInserted = _buildingRepo.Insert(newBuilding);

            //Try Create Building Content on backoffice
            if (buildingInserted != null)
            {
                IContent buildingContent = CreateBuildingContent(buildingInserted, documentType, parentId);
            }

            return(buildingInserted);
        }
コード例 #12
0
        private static bool CanEditMatch(Match match, MembershipHelper membershipHelper)
        {
            var currentMember = membershipHelper.GetCurrentMember();

            if (currentMember == null)
            {
                return(false);
            }

            if (match.MemberKeys().Contains(currentMember.Key))
            {
                return(true);
            }

            var allowedGroups = new List <string>(match.MemberGroupNames());

            allowedGroups.AddRange(new[] { Groups.Administrators });

            return(membershipHelper.IsMemberAuthorized(null, allowedGroups, null));
        }
コード例 #13
0
        private void UpsertContext(IEnumerable <PersonalisationTag> tags = null)
        {
            var member = _membershipHelper.GetCurrentMember();

            if (member == null)
            {
                return;
            }

            var context = GetContext() ?? new PersonalisationContext()
            {
                MemberId = member.Id
            };

            if (tags?.Any() ?? false)
            {
                context.Tags = tags;
            }

            _sessionService.SetSessionContext(context);
        }
コード例 #14
0
ファイル: SettingsService.cs プロジェクト: ImgBotApp/spectrum
        /// <summary>
        /// Gets the customer node.
        /// </summary>
        /// <returns></returns>
        /// <inheritdoc />
        public IPublishedContent GetCustomerNode()
        {
            MembershipHelper membershipHelper = new MembershipHelper(umbracoContext);

            IPublishedContent currentMember = membershipHelper.GetCurrentMember();

            if (currentMember != null)
            {
                string currentUserName = currentMember.Name;

                if (Cache.ContainsKey(Constants.Nodes.CustomerNodeName + currentUserName))
                {
                    return(Cache[Constants.Nodes.CustomerNodeName + currentUserName]);
                }

                IPublishedContent settingsNode = GetSettingsNode();

                if (settingsNode != null)
                {
                    IEnumerable <IPublishedContent> customerNodes = settingsNode.Children.Where(x => x.DocumentTypeAlias == "customer");

                    foreach (IPublishedContent customerNode in customerNodes)
                    {
                        CustomerModel customerModel = new CustomerModel(customerNode);

                        if (customerModel.Users.Contains(currentUserName))
                        {
                            if (customerModel.CacheSettings)
                            {
                                Cache.Add(Constants.Nodes.CustomerNodeName + currentUserName, customerNode);
                            }

                            return(customerNode);
                        }
                    }
                }
            }

            return(null);
        }
コード例 #15
0
 public IPublishedContent GetCurrentMember()
 {
     return(_membershipHelper.GetCurrentMember());
 }
コード例 #16
0
    void SimpilyForumsController_OnPostSaved(IContent sender, SimpilyForumsEventArgs e)
    {
        // we get passed IContent - but as we are going to go get loads of
        // other content, we will be quicker using IPublishedContent
        var umbHelper = new UmbracoHelper(UmbracoContext.Current);
        var mbrHelper = new MembershipHelper(UmbracoContext.Current);

        var post = umbHelper.TypedContent(sender.Id);
        if (post == null)
            return;

        // for us - the current user will have been the author
        var author = mbrHelper.GetCurrentMember();

        // work out the root of this post (top of the thread)
        var postRoot = post;
        if (post.Parent.DocumentTypeAlias == "Simpilypost")
        {
            // if we have a parent post, then this is a reply
            postRoot = post.Parent;
        }

        LogHelper.Info<ForumNotificationMgr>("Sending Notification for new post for {0}", () => postRoot.Name);

        List<string> receipients = GetRecipients(postRoot, mbrHelper);

        // remove the author from the list.
        var postAuthor = GetAuthorEmail(post, mbrHelper);
        if (receipients.Contains(postAuthor))
            receipients.Remove(postAuthor);

        if (receipients.Any())
        {
            SendNotificationEmail(postRoot, post, author, receipients, e.NewPost);
        }
    }
コード例 #17
0
        /// <summary>
        /// Helper method to generate the access/options available for the logged member user
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="contentModel"></param>
        /// <returns></returns>
        public static MvcHtmlString AccountSettings(this HtmlHelper helper, MembershipHelper membershipHelper, IPublishedContent contentModel)
        {
            if (membershipHelper == null)
            {
                return(MvcHtmlString.Empty);
            }

            if (!membershipHelper.IsLoggedIn())
            {
                return(MvcHtmlString.Empty);
            }

            StringBuilder sb = new StringBuilder();

            //try get configuration starting node id for the application
            int applicationRootId = -1;

            int.TryParse(ConfigurationManager.AppSettings["rootNodeId"], out applicationRootId);

            //if no starting root id specified, skip and return
            if (applicationRootId <= 0)
            {
                return(MvcHtmlString.Empty);
            }

            IPublishedContent dashboardContent = null;

            //Get the current member logged in
            var memberLoggedIn = membershipHelper.GetCurrentMember();
            var umbracoHelper  = new UmbracoHelper(UmbracoContext.Current);

            //fail fast if non found
            if (memberLoggedIn == null || umbracoHelper == null)
            {
                return(MvcHtmlString.Empty);
            }

            //check if member logged in is ASSOCIATED with an account
            //check if property accountid is set and a value is assigned to it, otherwise default to ""
            if (!memberLoggedIn.IsPropertyValid(Constants.ACCOUNT_PROPERTY_ALIAS))
            {
                return(MvcHtmlString.Empty);
            }

            int accountId = -1;

            int.TryParse(memberLoggedIn.GetValidPropertyValue(Constants.ACCOUNT_PROPERTY_ALIAS).ToString(), out accountId);

            //fail fast if account id was not found on member logged in
            if (accountId <= 0)
            {
                return(MvcHtmlString.Empty);
            }

            //Try to get the Content NODE for the application ('home')
            IPublishedContent mainContent = umbracoHelper.TypedContent(applicationRootId);

            if (mainContent != null)
            {
                bool isEnabled = false;
                if (contentModel.DocumentTypeAlias.Equals(Constants.BUILDINGLISTING_DOCUMENTTYPE_ALIAS, StringComparison.OrdinalIgnoreCase) ||
                    contentModel.DocumentTypeAlias.Equals(Constants.BUILDING_DOCUMENTTYPE_ALIAS, StringComparison.OrdinalIgnoreCase))
                {
                    isEnabled = true;
                }

                //find the content node for the account user
                //dashboardContent = mainContent.FirstChild();
                dashboardContent = mainContent.Children()
                                   .Where(x => x.IsDocumentType(Constants.ACCOUNT_DOCUMENTTYPE_ALIAS))
                                   .FirstOrDefault(x => x.IsPropertyValid(Constants.ACCOUNT_PROPERTY_ALIAS) && (int)x.GetValidPropertyValue(Constants.ACCOUNT_PROPERTY_ALIAS) == accountId);

                if (dashboardContent != null)
                {
                    sb.Append(string.Concat("<li class='", contentModel.Id == dashboardContent.Id || isEnabled ? "current_page_item" : null, "'>"));
                    sb.Append(string.Concat("<a href='", dashboardContent.Url, "'>Dashboard</a>"));
                    sb.Append("</li>");
                }
            }
            return(new MvcHtmlString(sb.ToString()));
        }
コード例 #18
0
ファイル: MemberRepository.cs プロジェクト: yasrah/Demo
 public string GetCurrentMemberName()
 {
     return(memberHelper.GetCurrentMember().Name);
 }
コード例 #19
0
        public static IPublishedContent GetCurrentMember()
        {
            var membershipHelper = new MembershipHelper(UmbracoContext.Current);

            return(membershipHelper.GetCurrentMember());
        }
コード例 #20
0
        /// <summary>
        /// Ensures that access to current node is permitted.
        /// </summary>
        /// <remarks>Redirecting to a different site root and/or culture will not pick the new site root nor the new culture.</remarks>
        private void EnsurePublishedContentAccess()
        {
            const string tracePrefix = "EnsurePublishedContentAccess: ";

            if (_pcr.PublishedContent == null)
            {
                throw new InvalidOperationException("There is no PublishedContent.");
            }

            var path = _pcr.PublishedContent.Path;

            var publicAccessAttempt = Services.PublicAccessService.IsProtected(path);

            if (publicAccessAttempt)
            {
                ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Page is protected, check for access", () => tracePrefix);

                var membershipHelper = new MembershipHelper(_routingContext.UmbracoContext);

                if (membershipHelper.IsLoggedIn() == false)
                {
                    ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Not logged in, redirect to login page", () => tracePrefix);

                    var loginPageId = publicAccessAttempt.Result.LoginNodeId;

                    if (loginPageId != _pcr.PublishedContent.Id)
                    {
                        _pcr.PublishedContent = _routingContext.UmbracoContext.ContentCache.GetById(loginPageId);
                    }
                }
                else if (Services.PublicAccessService.HasAccess(_pcr.PublishedContent.Id, Services.ContentService, _pcr.GetRolesForLogin(membershipHelper.CurrentUserName)) == false)
                {
                    ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Current member has not access, redirect to error page", () => tracePrefix);
                    var errorPageId = publicAccessAttempt.Result.NoAccessNodeId;
                    if (errorPageId != _pcr.PublishedContent.Id)
                    {
                        _pcr.PublishedContent = _routingContext.UmbracoContext.ContentCache.GetById(errorPageId);
                    }
                }
                else
                {
                    if (membershipHelper.IsUmbracoMembershipProviderActive())
                    {
                        // grab the current member
                        var member = membershipHelper.GetCurrentMember();
                        // if the member has the "approved" and/or "locked out" properties, make sure they're correctly set before allowing access
                        var memberIsActive = true;
                        if (member != null)
                        {
                            if (member.HasProperty(Constants.Conventions.Member.IsApproved) == false)
                            {
                                memberIsActive = member.GetPropertyValue <bool>(Constants.Conventions.Member.IsApproved);
                            }

                            if (member.HasProperty(Constants.Conventions.Member.IsLockedOut) == false)
                            {
                                memberIsActive = member.GetPropertyValue <bool>(Constants.Conventions.Member.IsLockedOut) == false;
                            }
                        }

                        if (memberIsActive == false)
                        {
                            ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Current member is either unapproved or locked out, redirect to error page", () => tracePrefix);
                            var errorPageId = publicAccessAttempt.Result.NoAccessNodeId;
                            if (errorPageId != _pcr.PublishedContent.Id)
                            {
                                _pcr.PublishedContent = _routingContext.UmbracoContext.ContentCache.GetById(errorPageId);
                            }
                        }
                        else
                        {
                            ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Current member has access", () => tracePrefix);
                        }
                    }
                    else
                    {
                        ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Current custom MembershipProvider member has access", () => tracePrefix);
                    }
                }
            }
            else
            {
                ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Page is not protected", () => tracePrefix);
            }
        }
コード例 #21
0
 public static IPartier GetCurrentPartier(this MembershipHelper members)
 {
     return(members.GetCurrentMember() as IPartier);
 }
コード例 #22
0
 public static bool IsLoggedInPartier(this MembershipHelper members)
 {
     return(members.IsLoggedIn() && members.GetCurrentMember() is IPartier);
 }