Skip to content
Permalink
Browse files Browse the repository at this point in the history
+ Changed vCard to be secured by adjustments to the People/GetVCard/ …
…REST controller.
  • Loading branch information
shivambareria committed Jan 12, 2019
1 parent 15b5834 commit 576f5ec
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 158 deletions.
44 changes: 44 additions & 0 deletions Rock.Rest/Controllers/PeopleController.Partial.cs
Expand Up @@ -21,6 +21,7 @@
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Http;
using System.Web.Http.OData;
Expand Down Expand Up @@ -876,6 +877,49 @@ public override void Delete( int id )
}

#endregion

#region VCard

/// <summary>
/// Returns VCard for person.
/// </summary>
/// <param name="personGuid">The person Guid.</param>
/// <returns></returns>
[HttpGet]
[Authenticate, Secured]
[System.Web.Http.Route( "api/People/VCard/{personGuid}" )]
public HttpResponseMessage GetVCard( Guid personGuid )
{
var rockContext = ( Rock.Data.RockContext ) Service.Context;

var person = new PersonService( rockContext ).Get( personGuid );
if ( person == null )
{
throw new HttpResponseException( new System.Net.Http.HttpResponseMessage( HttpStatusCode.NotFound ) );
}

string fileName = person.FullName + ".vcf";
HttpResponseMessage result = new HttpResponseMessage( HttpStatusCode.OK );

var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields( null, GetPerson() );
mergeFields.Add( "Person", person );
string vCard = GlobalAttributesCache.Value( "VCardFormat" ).ResolveMergeFields( mergeFields ).Trim();

// remove empty lines (the vcard spec is very picky)
vCard = Regex.Replace( vCard, @"^\s+$[\r\n]*", "", RegexOptions.Multiline );

var inputEncoding = Encoding.Default;
var outputEncoding = Encoding.GetEncoding( 28591 );
var cardBytes = inputEncoding.GetBytes( vCard );
var outputBytes = Encoding.Convert( inputEncoding, outputEncoding, cardBytes );
result.Content = new ByteArrayContent( outputBytes );
result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue( "text/vcard" );
result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue( "attachment" );
result.Content.Headers.ContentDisposition.FileName = fileName;
return result;
}

#endregion
}

/// <summary>
Expand Down
156 changes: 0 additions & 156 deletions RockWeb/App_Code/GetVCard.ashx.cs

This file was deleted.

2 changes: 1 addition & 1 deletion RockWeb/Blocks/Crm/PersonDetail/Bio.ascx.cs
Expand Up @@ -175,7 +175,7 @@ protected override void OnLoad( EventArgs e )
FollowingsHelper.SetFollowing( Person.PrimaryAlias, pnlFollow, this.CurrentPerson );
}

hlVCard.NavigateUrl = ResolveRockUrl( string.Format( "~/GetVCard.ashx?Person={0}", Person.Id ) );
hlVCard.NavigateUrl = ResolveUrl( string.Format( "~/api/People/VCard/{0}", Person.Guid ) );

var socialCategoryGuid = GetAttributeValue( "SocialMediaCategory" ).AsGuidOrNull();
if ( socialCategoryGuid.HasValue )
Expand Down
1 change: 0 additions & 1 deletion RockWeb/GetVCard.ashx

This file was deleted.

0 comments on commit 576f5ec

Please sign in to comment.