예제 #1
0
        private static MemberData GetMemberData()
        {
            var membershipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current);

            if (membershipHelper.GetCurrentLoginStatus().IsLoggedIn == false)
            {
                return(null);
            }

            var userName = membershipHelper.CurrentUserName;

            var memberData = ApplicationContext.Current.ApplicationCache.RuntimeCache
                             .GetCacheItem <MemberData>("MemberData" + userName, () =>
            {
                var member = membershipHelper.GetCurrentMember();

                var avatarService    = new AvatarService();
                var memberAvatarPath = avatarService.GetMemberAvatar(member);
                memberAvatarPath     = HostingEnvironment.MapPath($"~{memberAvatarPath}");
                var avatarImage      = avatarService.GetMemberAvatarImage(memberAvatarPath);

                var roles = member.GetRoles();

                var topicService = new TopicService(ApplicationContext.Current.DatabaseContext);
                var latestTopics = topicService.GetLatestTopicsForMember(member.Id, maxCount: 100);

                var newTosAccepted = true;
                var tosAccepted    = member.GetPropertyValue <DateTime>("tos");
                var newTosDate     = new DateTime(2018, 03, 26);
                if ((newTosDate - tosAccepted).TotalDays > 1)
                {
                    newTosAccepted = false;
                }

                var avatarPath = avatarService.GetMemberAvatar(member);
                var avatarHtml = avatarService.GetImgWithSrcSet(avatarPath, member.Name, 100);

                var data = new MemberData
                {
                    Member              = member,
                    AvatarImage         = avatarImage,
                    AvatarImageTooSmall = avatarImage != null && (avatarImage.Width < 400 || avatarImage.Height < 400),
                    Roles              = roles,
                    LatestTopics       = latestTopics,
                    AvatarHtml         = avatarHtml,
                    AvatarPath         = avatarPath,
                    NumberOfForumPosts = member.ForumPosts(),
                    Karma              = member.Karma(),
                    TwitterHandle      = member.GetPropertyValue <string>("twitter").Replace("@", string.Empty),
                    IsAdmin            = member.IsAdmin(),
                    Email              = member.GetPropertyValue <string>("Email"),
                    IsBlocked          = member.GetPropertyValue <bool>("blocked"),
                    NewTosAccepted     = newTosAccepted
                };

                return(data);
            }, TimeSpan.FromMinutes(5));

            return(memberData);
        }
예제 #2
0
        public static bool IsInGroup(string groupName)
        {
            var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current);
            var currentMember    = memberShipHelper.GetCurrentMember();

            return(currentMember != null && IsMemberInGroup(groupName, currentMember));
        }
예제 #3
0
        public static IPublishedContent GetMember(int id)
        {
            var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current);
            var currentMember    = memberShipHelper.GetCurrentMember();

            return(currentMember);
        }
        public JsonResult CheckProfileURLAvailable(string profileURL)
        {
            var membershipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current);

            //Get Current Member
            var member = membershipHelper.GetCurrentMember();

            if (member != null)
            {
                //If the Url is the same as the one currently stored for this user, return Ok
                if (member.GetPropertyValue <string>("profileURL") == profileURL)
                {
                    return(Json(true, JsonRequestBehavior.AllowGet));
                }

                //Check if an exisiting member is already using this Url:
                //TODO-1: Maybe just exclude the current user in below search and delete the line above?
                var checkProfileURL = Services.MemberService.GetMembersByPropertyValue("profileUrl", profileURL).FirstOrDefault();

                //If an exisiting member was found, then return negative
                if (checkProfileURL != null)
                {
                    return(Json(String.Format("The profile URL '{0}' is already in use.", profileURL), JsonRequestBehavior.AllowGet));
                }

                //Otherwise everything is good
                return(Json(true, JsonRequestBehavior.AllowGet));
            }

            // No member found
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
        public JsonResult CheckEmailIsUsed(string emailAddress)
        {
            var membershipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current);

            //Get Current Member
            var member = membershipHelper.GetCurrentMember();

            if (member != null)
            {
                //if the email is the same as the one stored then it's OK
                if (member.GetPropertyValue <string>("Email") == emailAddress)
                {
                    return(Json(true, JsonRequestBehavior.AllowGet));
                }

                //Try and get member by email typed in
                var checkEmail = Services.MemberService.GetByEmail(emailAddress);
                if (checkEmail != null)
                {
                    return(Json(String.Format("The email address '{0}' is already in use.", emailAddress), JsonRequestBehavior.AllowGet));
                }

                return(Json(true, JsonRequestBehavior.AllowGet));
            }

            // No member found
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
예제 #6
0
        public int GetCurrentUserId()
        {
            var memberService        = ApplicationContext.Services.MemberService;
            var memberHelper         = new Umbraco.Web.Security.MembershipHelper(UmbracoContext);
            IPublishedContent member = memberHelper.GetCurrentMember();
            var id = member.Id;

            return(id);
        }
예제 #7
0
        public static bool IsModerator()
        {
            var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current);
            var currentMember    = memberShipHelper.GetCurrentMember();

            if (currentMember.Id == 0)
            {
                return(false);
            }

            var moderatorRoles = new[] { "admin", "HQ", "Core", "MVP" };

            return(moderatorRoles.Any(moderatorRole => IsMemberInGroup(moderatorRole, currentMember)));
        }
예제 #8
0
        public string SaveWebCamImage(string memberGuid)
        {
            var url = HttpContext.Current.Request["AvatarUrl"];

            if (string.IsNullOrEmpty(url) == false)
            {
                return("true");
            }

            var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current);
            var member           = memberShipHelper.GetCurrentMember();

            if (member == null)
            {
                return("error");
            }

            var imageBytes = HttpContext.Current.Request.BinaryRead(HttpContext.Current.Request.ContentLength);
            var file       = member.Id.ToString(CultureInfo.InvariantCulture);
            var avatar     = string.Format("/media/avatar/{0}.jpg", file);
            var path       = HttpContext.Current.Server.MapPath(avatar);

            using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
            {
                ms.Write(imageBytes, 0, imageBytes.Length);

                var newImage = Image.FromStream(ms, true).GetThumbnailImage(64, 48, ThumbnailCallback, new IntPtr());

                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                newImage.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
            }

            var memberService = ApplicationContext.Current.Services.MemberService;
            var m             = memberService.GetById(member.Id);

            m.SetValue("avatar", avatar);

            return(avatar);
        }
        public ActionResult RenderEditProfile()
        {
            // Get the current member
            var membershipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current);
            var currentMember    = membershipHelper.GetCurrentMember();

            ProfileViewModel profileModel = new ProfileViewModel();

            profileModel.Name         = currentMember.Name;
            profileModel.EmailAddress = currentMember.GetPropertyValue <string>("Email");
            profileModel.MemberID     = currentMember.Id;
            profileModel.Description  = currentMember.GetPropertyValue <string>("description");
            profileModel.ProfileURL   = currentMember.GetPropertyValue <string>("profileURL");
            profileModel.Twitter      = currentMember.GetPropertyValue <string>("twitter");
            profileModel.LinkedIn     = currentMember.GetPropertyValue <string>("linkedIn");
            profileModel.Skype        = currentMember.GetPropertyValue <string>("skype");

            //Pass the model to the view
            return(PartialView("EditProfile", profileModel));
        }