Example #1
0
        public void UpdateUser(string id, Rock.CMS.DTO.User User)
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();

            if (currentUser == null)
            {
                throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden);
            }

            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.UserService UserService  = new Rock.CMS.UserService();
                Rock.CMS.User        existingUser = UserService.Get(int.Parse(id));
                if (existingUser.Authorized("Edit", currentUser))
                {
                    uow.objectContext.Entry(existingUser).CurrentValues.SetValues(User);

                    if (existingUser.IsValid)
                    {
                        UserService.Save(existingUser, currentUser.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingUser.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this User", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Example #2
0
        public Rock.CMS.DTO.User ApiGet(string id, string apiKey)
        {
            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User        user        = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.UserService UserService = new Rock.CMS.UserService();
                    Rock.CMS.User        User        = UserService.Get(int.Parse(id));
                    if (User.Authorized("View", user))
                    {
                        return(User.DataTransferObject);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to View this User", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Example #3
0
        public void ApiDeleteUser(string id, string apiKey)
        {
            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User        user        = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.UserService UserService = new Rock.CMS.UserService();
                    Rock.CMS.User        User        = UserService.Get(int.Parse(id));
                    if (User.Authorized("Edit", user))
                    {
                        UserService.Delete(User, user.PersonId);
                        UserService.Save(User, user.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to Edit this User", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Example #4
0
        public void DeleteUser(string id)
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();

            if (currentUser == null)
            {
                throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden);
            }

            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.UserService UserService = new Rock.CMS.UserService();
                Rock.CMS.User        User        = UserService.Get(int.Parse(id));
                if (User.Authorized("Edit", currentUser))
                {
                    UserService.Delete(User, currentUser.PersonId);
                    UserService.Save(User, currentUser.PersonId);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this User", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Example #5
0
        public Rock.CMS.DTO.User Get(string id)
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();

            if (currentUser == null)
            {
                throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden);
            }

            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.UserService UserService = new Rock.CMS.UserService();
                Rock.CMS.User        User        = UserService.Get(int.Parse(id));
                if (User.Authorized("View", currentUser))
                {
                    return(User.DataTransferObject);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to View this User", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Example #6
0
        public void ApiUpdateUser(string id, string apiKey, Rock.CMS.DTO.User User)
        {
            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User        user        = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.UserService UserService  = new Rock.CMS.UserService();
                    Rock.CMS.User        existingUser = UserService.Get(int.Parse(id));
                    if (existingUser.Authorized("Edit", user))
                    {
                        uow.objectContext.Entry(existingUser).CurrentValues.SetValues(User);

                        if (existingUser.IsValid)
                        {
                            UserService.Save(existingUser, user.PersonId);
                        }
                        else
                        {
                            throw new WebFaultException <string>(existingUser.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                        }
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to Edit this User", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }