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); } } }
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); } } }
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); } } }
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); } } }
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 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); } } }
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 ); } }
private void DisplaySentLogin(Direction direction) { using (new Rock.Data.UnitOfWorkScope()) { PersonService personService = new PersonService(); Rock.CMS.UserService userService = new Rock.CMS.UserService(); Person person = personService.Get(Int32.Parse(hfSendPersonId.Value)); if (person != null) { var mergeObjects = new List <object>(); var values = new Dictionary <string, string>(); values.Add("ConfirmAccountUrl", RootPath + "ConfirmAccount"); mergeObjects.Add(values); Dictionary <object, List <object> > personObjects = new Dictionary <object, List <object> >(); var userObjects = new List <object>(); mergeObjects.Add(person); foreach (var user in userService.GetByPersonId(person.Id)) { if (user.AuthenticationType != Rock.CMS.AuthenticationType.Facebook) { userObjects.Add(user); } } personObjects.Add(person, userObjects); mergeObjects.Add(personObjects); var recipients = new Dictionary <string, List <object> >(); recipients.Add(person.Email, mergeObjects); Email email = new Email(Rock.SystemGuid.EmailTemplate.SECURITY_FORGOT_USERNAME); SetSMTPParameters(email); email.Send(recipients); } else { ShowErrorMessage("Invalid Person"); } } ShowPanel(3); }
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); } } }
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); } } }
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"); } } }
protected void btnDuplicatesNext_Click(object sender, EventArgs e) { int personId = Int32.Parse(Request.Form["DuplicatePerson"]); if (personId > 0) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); var users = userService.GetByPersonId(personId).ToList(); if (users.Count > 0) { DisplaySendLogin(personId, Direction.Forward); } else { DisplayConfirmation(personId); } } else { DisplaySuccess(CreateUser(CreatePerson(), true)); } }
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); } } }
public void ApiDeletePage( 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.PageService PageService = new Rock.CMS.PageService(); Rock.CMS.Page Page = PageService.Get( int.Parse( id ) ); if ( Page.Authorized( "Edit", user ) ) { PageService.Delete( Page, user.PersonId ); PageService.Save( Page, user.PersonId ); } else throw new WebFaultException<string>( "Not Authorized to Edit this Page", System.Net.HttpStatusCode.Forbidden ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
public void ApiCreatePage( string apiKey, Rock.CMS.DTO.Page Page ) { 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.PageService PageService = new Rock.CMS.PageService(); Rock.CMS.Page existingPage = new Rock.CMS.Page(); PageService.Add( existingPage, user.PersonId ); uow.objectContext.Entry(existingPage).CurrentValues.SetValues(Page); if (existingPage.IsValid) PageService.Save( existingPage, user.PersonId ); else throw new WebFaultException<string>( existingPage.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
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 ); } }
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); } } }
private void DisplaySentLogin( Direction direction ) { using ( new Rock.Data.UnitOfWorkScope() ) { PersonService personService = new PersonService(); Rock.CMS.UserService userService = new Rock.CMS.UserService(); Person person = personService.Get( Int32.Parse( hfSendPersonId.Value ) ); if ( person != null ) { var mergeObjects = new List<object>(); var values = new Dictionary<string, string>(); values.Add( "ConfirmAccountUrl", RootPath + "ConfirmAccount" ); mergeObjects.Add( values ); Dictionary<object, List<object>> personObjects = new Dictionary<object, List<object>>(); var userObjects = new List<object>(); mergeObjects.Add( person ); foreach ( var user in userService.GetByPersonId( person.Id ) ) if (user.AuthenticationType != Rock.CMS.AuthenticationType.Facebook) userObjects.Add( user ); personObjects.Add( person, userObjects ); mergeObjects.Add(personObjects); var recipients = new Dictionary<string, List<object>>(); recipients.Add(person.Email, mergeObjects); Email email = new Email( Rock.SystemGuid.EmailTemplate.SECURITY_FORGOT_USERNAME ); SetSMTPParameters( email ); email.Send( recipients ); } else ShowErrorMessage( "Invalid Person" ); } ShowPanel( 3 ); }
public void ApiUpdateEntityChange( string id, string apiKey, Rock.Core.DTO.EntityChange EntityChange ) { 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.EntityChangeService EntityChangeService = new Rock.Core.EntityChangeService(); Rock.Core.EntityChange existingEntityChange = EntityChangeService.Get( int.Parse( id ) ); if ( existingEntityChange.Authorized( "Edit", user ) ) { uow.objectContext.Entry(existingEntityChange).CurrentValues.SetValues(EntityChange); if (existingEntityChange.IsValid) EntityChangeService.Save( existingEntityChange, user.PersonId ); else throw new WebFaultException<string>( existingEntityChange.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } else throw new WebFaultException<string>( "Not Authorized to Edit this EntityChange", System.Net.HttpStatusCode.Forbidden ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
private Rock.CMS.User CreateUser(Person person, bool confirmed) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); return(userService.Create(person, Rock.CMS.AuthenticationType.Database, tbUserName.Text, Password, confirmed, CurrentPersonId)); }
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 ); } }
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 ); } }
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 ); } }
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" ); } }
private Rock.CMS.User CreateUser( Person person, bool confirmed ) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); return userService.Create( person, Rock.CMS.AuthenticationType.Database, tbUserName.Text, Password, confirmed, CurrentPersonId ); }
public Rock.CMS.DTO.Page 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.PageService PageService = new Rock.CMS.PageService(); Rock.CMS.Page Page = PageService.Get( int.Parse( id ) ); if ( Page.Authorized( "View", user ) ) return Page.DataTransferObject; else throw new WebFaultException<string>( "Not Authorized to View this Page", System.Net.HttpStatusCode.Forbidden ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
protected void btnDuplicatesNext_Click( object sender, EventArgs e ) { int personId = Int32.Parse( Request.Form["DuplicatePerson"] ); if ( personId > 0 ) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); var users = userService.GetByPersonId(personId).ToList(); if (users.Count > 0) DisplaySendLogin( personId, Direction.Forward ); else DisplayConfirmation( personId ); } else { DisplaySuccess( CreateUser( CreatePerson(), true ) ); } }