Skip to content

Commit

Permalink
add crypt CBComSelMemberController
Browse files Browse the repository at this point in the history
  • Loading branch information
CloudBreadPaPa committed Mar 24, 2016
1 parent 556f3d5 commit ee184b4
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 51 deletions.
1 change: 1 addition & 0 deletions CloudBread.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@
<Compile Include="Models\AddMemberItemPurchase.cs" />
<Compile Include="Models\ComSelGiftDepository.cs" />
<Compile Include="Models\ComSelItemList1.cs" />
<Compile Include="Models\ComSelMember.cs" />
<Compile Include="Models\EncryptedData.cs" />
<Compile Include="Models\MobileServiceContext.cs" />
<Compile Include="Models\RowcountResult.cs" />
Expand Down
91 changes: 40 additions & 51 deletions Controllers/CBComSelMemberController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,70 +29,41 @@
using System.Security.Claims;
using Microsoft.Practices.TransientFaultHandling;
using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.SqlAzure;
using CloudBread.Models;

namespace CloudBread.Controllers
{
[MobileAppController]
public class CBComSelMemberController : ApiController
{

public class InputParams {
public string memberID;
}

public class Model
public HttpResponseMessage Post(ComSelMemberInputParams p)
{
public string MemberID { get; set; }
public string MemberPWD { get; set; }
public string EmailAddress { get; set; }
public string EmailConfirmedYN { get; set; }
public string PhoneNumber1 { get; set; }
public string PhoneNumber2 { get; set; }
public string PINumber { get; set; }
public string Name1 { get; set; }
public string Name2 { get; set; }
public string Name3 { get; set; }
public string DOB { get; set; }
public string RecommenderID { get; set; }
public string MemberGroup { get; set; }
public string LastDeviceID { get; set; }
public string LastIPaddress { get; set; }
public string LastLoginDT { get; set; }
public string LastLogoutDT { get; set; }
public string LastMACAddress { get; set; }
public string AccountBlockYN { get; set; }
public string AccountBlockEndDT { get; set; }
public string AnonymousYN { get; set; }
public string _3rdAuthProvider { get; set; }
public string _3rdAuthID { get; set; }
public string _3rdAuthParam { get; set; }
public string PushNotificationID { get; set; }
public string PushNotificationProvider { get; set; }
public string PushNotificationGroup { get; set; }
public string sCol1 { get; set; }
public string sCol2 { get; set; }
public string sCol3 { get; set; }
public string sCol4 { get; set; }
public string sCol5 { get; set; }
public string sCol6 { get; set; }
public string sCol7 { get; set; }
public string sCol8 { get; set; }
public string sCol9 { get; set; }
public string sCol10 { get; set; }
// try decrypt data
if (!string.IsNullOrEmpty(p.token) && globalVal.CloudBreadCryptSetting == "AES256")
{
try
{
string decrypted = Crypto.AES_decrypt(p.token, globalVal.CloudBreadCryptKey, globalVal.CloudBreadCryptIV);
p = JsonConvert.DeserializeObject<ComSelMemberInputParams>(decrypted);

}
}
catch (Exception ex)
{
ex = (Exception)Activator.CreateInstance(ex.GetType(), "Decrypt Error", ex);
throw ex;
}
}

public List<Model> Post(InputParams p)
{
// Get the sid or memberID of the current user.
var claimsPrincipal = this.User as ClaimsPrincipal;
string sid = CBAuth.getMemberID(p.memberID, claimsPrincipal);
string sid = CBAuth.getMemberID(p.memberID, this.User as ClaimsPrincipal);
p.memberID = sid;

Logging.CBLoggers logMessage = new Logging.CBLoggers();
string jsonParam = JsonConvert.SerializeObject(p);

List<Model> result = new List<Model>();
List<ComSelMemberModel> result = new List<ComSelMemberModel>();
HttpResponseMessage response = new HttpResponseMessage();
EncryptedData encryptedResult = new EncryptedData();

try
{
Expand All @@ -110,7 +81,7 @@ public List<Model> Post(InputParams p)
{
while (dreader.Read())
{
Model workItem = new Model()
ComSelMemberModel workItem = new ComSelMemberModel()
{
MemberID = dreader[0].ToString(),
MemberPWD = dreader[1].ToString(),
Expand Down Expand Up @@ -159,7 +130,25 @@ public List<Model> Post(InputParams p)
}
connection.Close();
}
return result;

/// Encrypt the result response
if (globalVal.CloudBreadCryptSetting == "AES256")
{
try
{
encryptedResult.token = Crypto.AES_encrypt(JsonConvert.SerializeObject(result), globalVal.CloudBreadCryptKey, globalVal.CloudBreadCryptIV);
response = Request.CreateResponse(HttpStatusCode.OK, encryptedResult);
return response;
}
catch (Exception ex)
{
ex = (Exception)Activator.CreateInstance(ex.GetType(), "Encrypt Error", ex);
throw ex;
}
}

response = Request.CreateResponse(HttpStatusCode.OK, result);
return response;
}
}

Expand Down
54 changes: 54 additions & 0 deletions Models/ComSelMember.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CloudBread.Models
{
public class ComSelMemberInputParams
{
public string memberID;
public string token;
}

public class ComSelMemberModel
{
public string MemberID { get; set; }
public string MemberPWD { get; set; }
public string EmailAddress { get; set; }
public string EmailConfirmedYN { get; set; }
public string PhoneNumber1 { get; set; }
public string PhoneNumber2 { get; set; }
public string PINumber { get; set; }
public string Name1 { get; set; }
public string Name2 { get; set; }
public string Name3 { get; set; }
public string DOB { get; set; }
public string RecommenderID { get; set; }
public string MemberGroup { get; set; }
public string LastDeviceID { get; set; }
public string LastIPaddress { get; set; }
public string LastLoginDT { get; set; }
public string LastLogoutDT { get; set; }
public string LastMACAddress { get; set; }
public string AccountBlockYN { get; set; }
public string AccountBlockEndDT { get; set; }
public string AnonymousYN { get; set; }
public string _3rdAuthProvider { get; set; }
public string _3rdAuthID { get; set; }
public string _3rdAuthParam { get; set; }
public string PushNotificationID { get; set; }
public string PushNotificationProvider { get; set; }
public string PushNotificationGroup { get; set; }
public string sCol1 { get; set; }
public string sCol2 { get; set; }
public string sCol3 { get; set; }
public string sCol4 { get; set; }
public string sCol5 { get; set; }
public string sCol6 { get; set; }
public string sCol7 { get; set; }
public string sCol8 { get; set; }
public string sCol9 { get; set; }
public string sCol10 { get; set; }
}
}

0 comments on commit ee184b4

Please sign in to comment.