예제 #1
0
        public bool DeleteUser(string email)
        {
            var usr = profileRepo.GetProfileByEmail(email);

            //-- Delete CF4 Profile
            if (usr != default(Profile))
            {
                if (CfIdentity.UserID != usr.ID && !CfPrincipal.IsGod())
                {
                    throw new AccessViolationException("Cannot delete a profile that does not belong to you.");
                }
                DeleteCfProfileAndRelatedData(usr);
            }

            //-- Delete CF3 Profile
            var cf3Profile = new cf.DataAccess.cf3.ClimberProfileDA().GetClimberProfile(email);

            if (cf3Profile != default(Cf3Profile))
            {
                new cf.DataAccess.cf3.ClimberProfileDA().DeleteUserCompletely(cf3Profile.ID);
            }

            //-- Delete Membership User
            var mUser = Membership.GetUser(email);

            if (mUser != default(MembershipUser))
            {
                Membership.DeleteUser(email);
            }

            return(true);
        }
 public void OnAuthorization(AuthorizationContext filterContext)
 {
     if (!CfPrincipal.IsGod())
     {
         HandleUnauthorizedRequest(filterContext);
     }
 }
예제 #3
0
        public ActionResult CountryEdit(string id)
        {
            if (CfPrincipal.IsGod())
            {
                //-- TODO Put error check
                var cachedCountry = AppLookups.Countries.Where(c => c.NameUrlPart == id).SingleOrDefault();
                var country       = geoSvc.GetCountryByID(cachedCountry.ID);
                ViewBag.Country = country;

                var geoJsonUrl = Stgs.MapSvcRelativeUrl + "country/" + id;

                var mapModel = new Bing7GeoJsonMapViewModel("climbing-map-" + id, 720, 480, geoJsonUrl);
                //mapModel.Buttons.Add(new Bing7MapButtonModel() { ButtonText = "Track LatLong", ButtonEventInitializer = "toggleTrackLatLong()" });
                ViewBag.MapModel = mapModel;

                return(View(new CountryEditViewModel()
                {
                    WKT = new string(country.Geo.STAsText().Value),
                    GeoReduceThreshold = country.GeoReduceThreshold
                }));
            }
            else
            {
                throw new AccessViolationException("You must be a GOD level Climbfind user to moderate country data! Moderate province or city level data instead.");
            }
        }
예제 #4
0
        public ActionResult PlaceAjaxRefresh(Guid id)
        {
            var posts    = new List <PostRendered>();
            var postType = GetPostTypeFromQueryString();

            if (id == Guid.Empty)
            {
                posts = postSvc.GetPostForEverywhere(postType, ClientAppType.CfWeb);
            }
            else if (id == Stgs.MyFeedID)
            {
                posts = postSvc.GetUsersFeed(CfIdentity.UserID, postType, ClientAppType.CfWeb).Posts;
            }
            else
            {
                var place = AppLookups.GetCacheIndexEntry(id);

                if (place.Type.ToPlaceCateogry() == PlaceCategory.Area)
                {
                    posts = postSvc.GetPostForArea(id, postType, ClientAppType.CfWeb);
                }
                else
                {
                    posts = postSvc.GetPostForLocation(id, postType, ClientAppType.CfWeb);
                }
            }

            return(PartialView("Partials/FeedPostList", new FeedPostListViewData()
            {
                FeedPosts = posts, UserHasDeletePostRights = CfPrincipal.IsGod()
            }));
        }
        public override void OnException(ExceptionContext context)
        {
            CfTrace.Error(context.Exception);

            if (context.Exception is AccessViolationException)
            {
                context.Result = new ViewResult()
                {
                    ViewName = "Unauthorized"
                };
                (context.Result as ViewResult).ViewBag.Msg = context.Exception.Message;
                context.ExceptionHandled = true;
            }
            else
            {
                var ex = getBaseException(context.Exception);

                var errorDisplayText = ex.Message;
                if (CfIdentity.IsAuthenticated && CfPrincipal.IsGod())
                {
                    errorDisplayText = ex.ToString();
                }

                context.Result = new ViewResult()
                {
                    ViewName = "Error"
                };
                (context.Result as ViewResult).ViewBag.Msg = errorDisplayText;
                context.ExceptionHandled = true;
            }


            base.OnException(context);
        }
예제 #6
0
        public void DeleteMediaOpinion(MediaOpinion obj)
        {
            if (obj.UserID != CfIdentity.UserID & !CfPrincipal.IsGod())
            {
                throw new AccessViolationException("Cannot delete opinion that was not added by you");
            }

            medRatingRepo.Delete(obj.ID);

            UpdateMediaOpinionMeta(obj.MediaID);
        }
예제 #7
0
        public void DeleteMedia(Media obj)
        {
            if (obj.AddedByUserID != CfIdentity.UserID & !CfPrincipal.IsGod())
            {
                throw new AccessViolationException("Cannot delete media that was not added by you");
            }

            //var comments = obj.MediaOpinion;
            medRatingRepo.Delete(medRatingRepo.GetAll().Where(r => r.MediaID == obj.ID).Select(r => r.ID).ToList());

            medRepo.Delete(obj.ID);
        }
예제 #8
0
        public void DeletePost(Post obj)
        {
            var currentUserID             = CfIdentity.UserID;
            var userHasRightsToDeletePost = (currentUserID == obj.UserID) || CfPrincipal.IsGod();

            if (!userHasRightsToDeletePost)
            {
                throw new AccessViolationException("Delete Post: Cannot delete this post, it does not belong to the current user.");
            }

            postRepo.Delete(obj.ID);
        }
예제 #9
0
        public void RemoveMediaTag(Media media, Guid onObjectID)
        {
            var tag = media.ObjectMedias.Where(om => om.OnOjectID == onObjectID).SingleOrDefault();

            if (media.AddedByUserID != CfIdentity.UserID & !CfPrincipal.IsGod())
            {
                throw new AccessViolationException("Cannot untag media that was not added by you");
            }
            if (tag == null)
            {
                throw new AccessViolationException("Cannot tag media that already has tag with objID " + onObjectID);
            }

            medRepo.RemoveMediaTag(tag);
        }
예제 #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public void DeleteOpinion(Opinion obj)
        {
            if (obj.UserID != CfIdentity.UserID & !CfPrincipal.IsGod())
            {
                throw new AccessViolationException("Cannot delete Opinion that was not added by you");
            }

            rateRepo.Delete(obj.ID);

            var objectsRatins = rateRepo.GetAll().Where(r => r.ObjectID == obj.ObjectID).ToList();

            UpdateRatedObject(obj.ObjectID, objectsRatins);

            postSvc.DeleteOpinionPost(obj);
        }
예제 #11
0
        public ObjectMedia AddMediaTag(Media media, Guid onObjectID)
        {
            var alreadyTagged = media.ObjectMedias.Where(om => om.OnOjectID == onObjectID).Count() > 0;

            if (media.AddedByUserID != CfIdentity.UserID & !CfPrincipal.IsGod())
            {
                throw new AccessViolationException("Cannot tag media that was not added by you");
            }
            if (alreadyTagged)
            {
                throw new AccessViolationException("Cannot tag media that already has tag with objID " + onObjectID);
            }

            var tag = new ObjectMedia()
            {
                MediaID = media.ID, OnOjectID = onObjectID
            };

            medRepo.AddMediaTag(tag);

            return(tag);
        }
예제 #12
0
        /// <summary>
        /// Used when needing to add (append) messages to a specific conversation
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Conversation GetConversationById(Guid id)
        {
            var convo = convoRepo.GetByID(id);

            if (convo.PartyBID != CfIdentity.UserID && convo.PartyAID != CfIdentity.UserID && !CfPrincipal.IsGod())
            {
                throw new AccessViolationException("Cannot retrieve conversation that you are not part of");
            }
            return(convo);
        }
예제 #13
0
        public void DeleteComment(Guid postID, Guid commentID)
        {
            var post    = GetPostByID(postID);
            var comment = post.PostComments.Where(c => c.ID == commentID).Single();

            var userID = CfIdentity.UserID;

            var userHasRightsToDeletePost = (userID == post.UserID) || (userID == comment.UserID) || CfPrincipal.IsGod();

            if (!userHasRightsToDeletePost)
            {
                throw new AccessViolationException("Delete Post: Cannot delete this comment, because neither the post nor the comment belong to the current user.");
            }

            postRepo.DeletePostComment(post.ID, commentID);
        }