示例#1
0
        public void ApiDeletePageRoute(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.PageRouteService PageRouteService = new Rock.CMS.PageRouteService();
                    Rock.CMS.PageRoute        PageRoute        = PageRouteService.Get(int.Parse(id));
                    if (PageRoute.Authorized("Edit", user))
                    {
                        PageRouteService.Delete(PageRoute, user.PersonId);
                        PageRouteService.Save(PageRoute, user.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to Edit this PageRoute", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
示例#2
0
        public Rock.CRM.DTO.Address ApiGeocode(string apiKey, Rock.CRM.DTO.Address address)
        {
            using (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)
                {
                    if (address != null)
                    {
                        Rock.CRM.AddressService addressService = new Rock.CRM.AddressService();
                        Rock.CRM.Address        addressModel   = addressService.Geocode(address, user.PersonId);
                        return(addressModel.DataTransferObject);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Invalid Address", System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
示例#3
0
        public void ApiCreateFieldType(string apiKey, Rock.Core.DTO.FieldType FieldType)
        {
            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.Core.FieldTypeService FieldTypeService  = new Rock.Core.FieldTypeService();
                    Rock.Core.FieldType        existingFieldType = new Rock.Core.FieldType();
                    FieldTypeService.Add(existingFieldType, user.PersonId);
                    uow.objectContext.Entry(existingFieldType).CurrentValues.SetValues(FieldType);

                    if (existingFieldType.IsValid)
                    {
                        FieldTypeService.Save(existingFieldType, user.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingFieldType.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
示例#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);
                }
            }
        }
示例#5
0
        private void DisplayConfirmation(int personId)
        {
            PersonService personService = new PersonService();
            Person        person        = personService.Get(personId);

            if (person != null)
            {
                Rock.CMS.User user = CreateUser(person, false);

                var mergeObjects = new List <object>();
                mergeObjects.Add(person);
                mergeObjects.Add(user);

                var values = new Dictionary <string, string>();
                values.Add("ConfirmAccountUrl", RootPath + "ConfirmAccount");
                mergeObjects.Add(values);

                var recipients = new Dictionary <string, List <object> >();
                recipients.Add(person.Email, mergeObjects);

                Email email = new Email(Rock.SystemGuid.EmailTemplate.SECURITY_CONFIRM_ACCOUNT);
                SetSMTPParameters(email);
                email.Send(recipients);

                ShowPanel(4);
            }
            else
            {
                ShowErrorMessage("Invalid Person");
            }
        }
示例#6
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);
                }
            }
        }
示例#7
0
        public Rock.Core.DTO.FieldType 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.Core.FieldTypeService FieldTypeService = new Rock.Core.FieldTypeService();
                    Rock.Core.FieldType        FieldType        = FieldTypeService.Get(int.Parse(id));
                    if (FieldType.Authorized("View", user))
                    {
                        return(FieldType.DataTransferObject);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to View this FieldType", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
        public void ApiFlushGlobal(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)
                {
                    FlushGlobal();
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
示例#9
0
        private void DisplaySuccess(Rock.CMS.User user)
        {
            FormsAuthentication.SignOut();
            FormsAuthentication.SetAuthCookie(tbUserName.Text, false);
            Session["UserIsAuthenticated"] = true;

            if (user != null && user.PersonId.HasValue)
            {
                PersonService personService = new PersonService();
                Person        person        = personService.Get(user.PersonId.Value);

                if (person != null)
                {
                    var mergeObjects = new List <object>();
                    mergeObjects.Add(person);
                    mergeObjects.Add(user);

                    var values = new Dictionary <string, string>();
                    values.Add("ConfirmAccountUrl", RootPath + "ConfirmAccount");
                    mergeObjects.Add(values);

                    var recipients = new Dictionary <string, List <object> >();
                    recipients.Add(person.Email, mergeObjects);

                    Email email = new Email(Rock.SystemGuid.EmailTemplate.SECURITY_ACCOUNT_CREATED);
                    SetSMTPParameters(email);
                    email.Send(recipients);

                    lSuccessCaption.Text = AttributeValue("SuccessCaption");
                    if (lSuccessCaption.Text.Contains("{0}"))
                    {
                        lSuccessCaption.Text = string.Format(lSuccessCaption.Text, person.FirstName);
                    }

                    ShowPanel(5);
                }
                else
                {
                    ShowErrorMessage("Invalid Person");
                }
            }
            else
            {
                ShowErrorMessage("Invalid User");
            }
        }
示例#10
0
        public void ApiMove(string id, string apiKey, Rock.CMS.DTO.BlockInstance BlockInstance)
        {
            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.BlockInstanceService BlockInstanceService  = new Rock.CMS.BlockInstanceService();
                    Rock.CMS.BlockInstance        existingBlockInstance = BlockInstanceService.Get(int.Parse(id));

                    if (existingBlockInstance.Authorized("Edit", user))
                    {
                        // If the block was moved from or to the layout section, then all the pages
                        // that use that layout need to be flushed from cache
                        if (existingBlockInstance.Layout != BlockInstance.Layout)
                        {
                            if (existingBlockInstance.Layout != null)
                            {
                                Rock.Web.Cache.Page.FlushLayout(existingBlockInstance.Layout);
                            }
                            if (BlockInstance.Layout != null)
                            {
                                Rock.Web.Cache.Page.FlushLayout(BlockInstance.Layout);
                            }
                        }

                        uow.objectContext.Entry(existingBlockInstance).CurrentValues.SetValues(BlockInstance);
                        BlockInstanceService.Move(existingBlockInstance);
                        BlockInstanceService.Save(existingBlockInstance, user.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to Edit this BlockInstance", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
示例#11
0
        protected void btnUserInfoNext_Click(object sender, EventArgs e)
        {
            Password        = tbPassword.Text;
            PasswordConfirm = tbPasswordConfirm.Text;

            if (Page.IsValid)
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User        user        = userService.GetByUserName(tbUserName.Text);
                if (user == null)
                {
                    DisplayDuplicates(Direction.Forward);
                }
                else
                {
                    ShowErrorMessage("Username already exists");
                }
            }
        }
示例#12
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);
                }
            }
        }
示例#13
0
        public void ApiUpdatePageRoute(string id, string apiKey, Rock.CMS.DTO.PageRoute PageRoute)
        {
            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.PageRouteService PageRouteService  = new Rock.CMS.PageRouteService();
                    Rock.CMS.PageRoute        existingPageRoute = PageRouteService.Get(int.Parse(id));
                    if (existingPageRoute.Authorized("Edit", user))
                    {
                        uow.objectContext.Entry(existingPageRoute).CurrentValues.SetValues(PageRoute);

                        if (existingPageRoute.IsValid)
                        {
                            PageRouteService.Save(existingPageRoute, user.PersonId);
                        }
                        else
                        {
                            throw new WebFaultException <string>(existingPageRoute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                        }
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to Edit this PageRoute", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
示例#14
0
        public void ApiCreateUser( 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 = new Rock.CMS.User();
                    UserService.Add( existingUser, user.PersonId );
                    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>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
示例#15
0
        public void CreateUser( 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 = new Rock.CMS.User();
                UserService.Add( existingUser, currentUser.PersonId );
                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 );
            }
        }
示例#16
0
        void Actions_ExcelExportClick(object sender, EventArgs e)
        {
            // create default settings
            string filename      = "export.xlsx";
            string workSheetName = "Export";
            string title         = "Rock ChMS Export";


            MemoryStream ms    = new MemoryStream();
            ExcelPackage excel = new ExcelPackage(ms);

            // if the grid has a caption customize on it
            if (this.Caption != null && this.Caption != string.Empty)
            {
                excel.Workbook.Properties.Title = this.Caption;
                workSheetName = this.Caption;
                filename      = this.Caption.Replace(" ", "") + ".xlsx";
                title         = this.Caption;
            }
            else
            {
                excel.Workbook.Properties.Title = "Rock ChMS Export";
            }

            // add author info
            Rock.CMS.User user = Rock.CMS.UserService.GetCurrentUser();
            if (user != null)
            {
                excel.Workbook.Properties.Author = user.Person.FullName;
            }
            else
            {
                excel.Workbook.Properties.Author = "Rock ChMS";
            }

            // add the page that created this
            excel.Workbook.Properties.SetCustomPropertyValue("Source", this.Page.Request.Url.OriginalString);

            ExcelWorksheet worksheet = excel.Workbook.Worksheets.Add(workSheetName);

            // write data to worksheet there are three supported data sources
            // DataTables, DataViews and ILists

            int rowCounter    = 4;
            int columnCounter = 1;

            if (this.DataSource is DataTable || this.DataSource is DataView)
            {
                DataTable data = null;

                if (this.DataSource is DataTable)
                {
                    data = ( DataTable )this.DataSource;
                }
                else if (this.DataSource is DataView)
                {
                    data = (( DataView )this.DataSource).Table;
                }

                // print headings
                foreach (DataColumn column in data.Columns)
                {
                    worksheet.Cells[3, columnCounter].Value = column.ColumnName.SplitCase();
                    columnCounter++;
                }

                // print data
                foreach (DataRow row in data.Rows)
                {
                    for (int i = 0; i < data.Columns.Count; i++)
                    {
                        worksheet.Cells[rowCounter, i].Value = row[i].ToString();

                        // format background color for alternating rows
                        if (rowCounter % 2 == 1)
                        {
                            worksheet.Cells[rowCounter, columnCounter].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells[rowCounter, columnCounter].Style.Fill.BackgroundColor.SetColor(Color.FromArgb(240, 240, 240));
                        }
                    }
                    rowCounter++;
                }
            }
            else
            {
                // get access to the List<> and its properties
                IList data  = ( IList )this.DataSource;
                Type  oType = data.GetType().GetProperty("Item").PropertyType;
                IList <PropertyInfo> props = new List <PropertyInfo>(oType.GetProperties());

                // print column headings
                foreach (PropertyInfo prop in props)
                {
                    worksheet.Cells[3, columnCounter].Value = prop.Name.SplitCase();
                    columnCounter++;
                }

                // print data
                foreach (var item in data)
                {
                    columnCounter = 1;
                    foreach (PropertyInfo prop in props)
                    {
                        object propValue = prop.GetValue(item, null);

                        string value = "";
                        if (propValue != null)
                        {
                            value = propValue.ToString();
                        }

                        worksheet.Cells[rowCounter, columnCounter].Value = value;

                        // format background color for alternating rows
                        if (rowCounter % 2 == 1)
                        {
                            worksheet.Cells[rowCounter, columnCounter].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells[rowCounter, columnCounter].Style.Fill.BackgroundColor.SetColor(Color.FromArgb(240, 240, 240));
                        }

                        if (propValue is DateTime)
                        {
                            worksheet.Cells[rowCounter, columnCounter].Style.Numberformat.Format = "MM/dd/yyyy hh:mm";
                        }

                        columnCounter++;
                    }

                    rowCounter++;
                }
            }

            // format header range
            using (ExcelRange r = worksheet.Cells[3, 1, 3, columnCounter])
            {
                r.Style.Font.Bold        = true;
                r.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                r.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(223, 223, 223));
                r.Style.Font.Color.SetColor(Color.Black);
                r.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Left;
            }

            // format and set title
            worksheet.Cells[1, 1].Value = title;
            using (ExcelRange r = worksheet.Cells[1, 1, 1, columnCounter])
            {
                r.Merge = true;
                r.Style.Font.SetFromFont(new Font("Calibri", 22, FontStyle.Regular));
                r.Style.Font.Color.SetColor(Color.White);
                r.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Left;
                r.Style.Fill.PatternType    = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                r.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(34, 41, 55));

                // set border
                r.Style.Border.Left.Style   = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
                r.Style.Border.Right.Style  = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
                r.Style.Border.Top.Style    = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
                r.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
            }

            // TODO: add image to worksheet

            // freeze panes
            worksheet.View.FreezePanes(3, 1);

            // autofit columns for all cells
            worksheet.Cells.AutoFitColumns(0);

            // add the auto filter / sorting
            worksheet.Cells[3, 1, rowCounter, columnCounter].AutoFilter = true;

            // add alternating highlights


            // set some footer text
            worksheet.HeaderFooter.OddHeader.CenteredText     = title;
            worksheet.HeaderFooter.OddFooter.RightAlignedText = string.Format("Page {0} of {1}", ExcelHeaderFooter.PageNumber, ExcelHeaderFooter.NumberOfPages);

            excel.Save();

            byte[] byteArray = ms.ToArray();

            // send the spreadsheet to the browser
            this.Page.EnableViewState = false;
            this.Page.Response.Clear();
            //this.Page.Response.ContentType = "application/vnd.ms-excel";
            this.Page.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            this.Page.Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename);

            this.Page.Response.Charset = "";
            this.Page.Response.BinaryWrite(byteArray);
            this.Page.Response.Flush();
            this.Page.Response.End();

            throw new NotImplementedException();
        }
示例#17
0
 /// <summary>
 /// Returns <c>true</c> if the user is authorized to perform the selected action on this object.
 /// </summary>
 /// <param name="action">The action.</param>
 /// <param name="user">The user.</param>
 /// <returns></returns>
 public virtual bool Authorized(string action, Rock.CMS.User user)
 {
     return(Security.Authorization.Authorized(this, action, user));
 }