Skip to content

Commit

Permalink
adding crypt CBComSelMemberGameInfoesController
Browse files Browse the repository at this point in the history
  • Loading branch information
CloudBreadPaPa committed Mar 24, 2016
1 parent ee184b4 commit 56c5472
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 36 deletions.
1 change: 1 addition & 0 deletions CloudBread.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@
<Compile Include="Models\ComSelGiftDepository.cs" />
<Compile Include="Models\ComSelItemList1.cs" />
<Compile Include="Models\ComSelMember.cs" />
<Compile Include="Models\ComSelMemberGameInfoes.cs" />
<Compile Include="Models\EncryptedData.cs" />
<Compile Include="Models\MobileServiceContext.cs" />
<Compile Include="Models\RowcountResult.cs" />
Expand Down
76 changes: 40 additions & 36 deletions Controllers/CBComSelMemberGameInfoesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,55 +30,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 CBComSelMemberGameInfoesController : ApiController
{

public class InputParams { public string MemberID;}

public class Model
public HttpResponseMessage Post(ComSelMemberGameInfoesInputParams p)
{
public string MemberID { get; set; }
public string Level { get; set; }
public string Exps { get; set; }
public string Points { get; set; }
public string UserSTAT1 { get; set; }
public string UserSTAT2 { get; set; }
public string UserSTAT3 { get; set; }
public string UserSTAT4 { get; set; }
public string UserSTAT5 { get; set; }
public string UserSTAT6 { get; set; }
public string UserSTAT7 { get; set; }
public string UserSTAT8 { get; set; }
public string UserSTAT9 { get; set; }
public string UserSTAT10 { 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<ComSelMemberGameInfoesInputParams>(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<ComSelMemberGameInfoesModel> result = new List<ComSelMemberGameInfoesModel>();
HttpResponseMessage response = new HttpResponseMessage();
EncryptedData encryptedResult = new EncryptedData();

try
{
Expand All @@ -96,7 +82,7 @@ public List<Model> Post(InputParams p)
{
while (dreader.Read())
{
Model workItem = new Model()
ComSelMemberGameInfoesModel workItem = new ComSelMemberGameInfoesModel()
{
MemberID = dreader[0].ToString(),
Level = dreader[1].ToString(),
Expand Down Expand Up @@ -130,7 +116,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
41 changes: 41 additions & 0 deletions Models/ComSelMemberGameInfoes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CloudBread.Models
{
public class ComSelMemberGameInfoesInputParams
{
public string MemberID { get; set; }
public string token { get; set; }
}

public class ComSelMemberGameInfoesModel
{
public string MemberID { get; set; }
public string Level { get; set; }
public string Exps { get; set; }
public string Points { get; set; }
public string UserSTAT1 { get; set; }
public string UserSTAT2 { get; set; }
public string UserSTAT3 { get; set; }
public string UserSTAT4 { get; set; }
public string UserSTAT5 { get; set; }
public string UserSTAT6 { get; set; }
public string UserSTAT7 { get; set; }
public string UserSTAT8 { get; set; }
public string UserSTAT9 { get; set; }
public string UserSTAT10 { 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 56c5472

Please sign in to comment.