diff --git a/Swift.DAL/BL/SwiftSystem/ApplicationUserDao.cs b/Swift.DAL/BL/SwiftSystem/ApplicationUserDao.cs index 52e9187..2940006 100644 --- a/Swift.DAL/BL/SwiftSystem/ApplicationUserDao.cs +++ b/Swift.DAL/BL/SwiftSystem/ApplicationUserDao.cs @@ -362,5 +362,62 @@ namespace Swift.DAL.BL.System.UserManagement } #endregion + + + #region Inbound API + + public UserApiKeysModel GetApiCredentials(string userId, string userName) + { + UserApiKeysModel response = new UserApiKeysModel(); + string sql = "EXEC PROC_USER_API_KEY"; + sql += " @flag = 'GET-SECRET-KEYS'"; + sql += ", @User = " + FilterString(userName); + sql += ", @userId = " + FilterString(userId); + + DataRow dr = ExecuteDataRow(sql); + if (dr == null) + { + response.responseCode = "1"; + response.responseMessage = "API auth keys not set"; + + return response; + } + response.responseCode = "0"; + response.responseMessage = "Success"; + response.UserId = Convert.ToString(dr["UserId"]); + response.APISecretKey = Convert.ToString(dr["APISecretKey"]); + response.AppId = Convert.ToString(dr["AppId"]); + + return response; + } + + public UserApiKeysModel GenerateCredentials(string userId, string userName, ApiSecretKeys apiCredentials) + { + UserApiKeysModel response = new UserApiKeysModel(); + string sql = "EXEC PROC_USER_API_KEY"; + sql += " @flag = 'REGENERATE'"; + sql += ", @User = " + FilterString(userName); + sql += ", @userId = " + FilterString(userId); + sql += ", @ApiKey = " + FilterString(apiCredentials.ApiKey); + sql += ", @AppId = " + FilterString(apiCredentials.AppId); + + DataRow dr = ExecuteDataRow(sql); + if (dr == null) + { + response.responseCode = "1"; + response.responseMessage = "API auth keys not set"; + + return response; + } + response.responseCode = "0"; + response.responseMessage = "Success"; + response.UserId = Convert.ToString(dr["UserId"]); + response.APISecretKey = Convert.ToString(dr["APISecretKey"]); + response.AppId = Convert.ToString(dr["AppId"]); + + return response; + } + + #endregion } } \ No newline at end of file diff --git a/Swift.DAL/MobileDao/MobileConfigDao.cs b/Swift.DAL/MobileDao/MobileConfigDao.cs index ba7722a..a6fa41d 100644 --- a/Swift.DAL/MobileDao/MobileConfigDao.cs +++ b/Swift.DAL/MobileDao/MobileConfigDao.cs @@ -78,7 +78,7 @@ namespace Swift.DAL.MobileDao return ParseDbResult(sql); } - public DbResult SaveBroadCastCustomer(string user, string rowId, string customerId, string msgType, string body, string customerType , string nativeCountry) + public DbResult SaveBroadCastCustomer(string user, string rowId, string customerId, string msgType, string body, string customerType , string nativeCountry, string postCode) { var sql = "EXEC ProcMobileConfig @flag = '" + (string.IsNullOrEmpty(rowId) ? "IN-BROADCAST" : "UN-BROADCAST") + "'"; sql += ", @User = " + FilterString(user); @@ -88,6 +88,7 @@ namespace Swift.DAL.MobileDao sql += ", @msgType = " + FilterString(msgType); sql += ", @customerType = " + FilterString(customerType); sql += ", @nativeCountry = " + FilterString(nativeCountry); + sql += ", @postCode = " + FilterString(postCode); return ParseDbResult(sql); } diff --git a/Swift.DAL/SwiftDAL/DbResult.cs b/Swift.DAL/SwiftDAL/DbResult.cs index 3867236..24d6b19 100644 --- a/Swift.DAL/SwiftDAL/DbResult.cs +++ b/Swift.DAL/SwiftDAL/DbResult.cs @@ -70,4 +70,20 @@ Data = data; } } + + + public class UserApiKeysModel + { + public string responseCode { get; set; } + public string responseMessage { get; set; } + public string AppId { get; set; } + public string APISecretKey { get; set; } + public string UserId { get; set; } + } + + public class ApiSecretKeys + { + public string ApiKey { get; set; } + public string AppId { get; set; } + } } diff --git a/Swift.web/Library/GetStatic.cs b/Swift.web/Library/GetStatic.cs index 3d4a0f5..b1d49c3 100644 --- a/Swift.web/Library/GetStatic.cs +++ b/Swift.web/Library/GetStatic.cs @@ -21,6 +21,7 @@ using System.IO; using System.Xml.Serialization; using SelectPdf; using Newtonsoft.Json; +using System.Security.Cryptography; //using SelectPdf; @@ -2660,6 +2661,23 @@ namespace Swift.web.Library return MimeTypes.MimeTypeMap.GetExtension(contentType); } + public static ApiSecretKeys GetKeys() + { + using (var cryptoProvider = new RNGCryptoServiceProvider()) + { + ApiSecretKeys model = new ApiSecretKeys(); + var APPID = Guid.NewGuid(); + + byte[] secretKeyByteArray = new byte[32]; //256 bit + cryptoProvider.GetBytes(secretKeyByteArray); + var APIKey = Convert.ToBase64String(secretKeyByteArray); + model.ApiKey = APIKey; + model.AppId = Convert.ToString(APPID); + + return (model); + } + } + } } \ No newline at end of file diff --git a/Swift.web/MobileRemit/Admin/PushNotification/ManageBroadCast.aspx b/Swift.web/MobileRemit/Admin/PushNotification/ManageBroadCast.aspx index c951835..78e4d38 100644 --- a/Swift.web/MobileRemit/Admin/PushNotification/ManageBroadCast.aspx +++ b/Swift.web/MobileRemit/Admin/PushNotification/ManageBroadCast.aspx @@ -29,27 +29,26 @@ diff --git a/Swift.web/SwiftSystem/UserManagement/AgentUserSetup/List.aspx.cs b/Swift.web/SwiftSystem/UserManagement/AgentUserSetup/List.aspx.cs index a32a37f..7903caa 100644 --- a/Swift.web/SwiftSystem/UserManagement/AgentUserSetup/List.aspx.cs +++ b/Swift.web/SwiftSystem/UserManagement/AgentUserSetup/List.aspx.cs @@ -26,6 +26,9 @@ namespace Swift.web.SwiftSystem.UserManagement.AgentUserSetup private const string LockUser = "10101180"; private const string SendQRCode = "10101140"; + + private const string ViewEditAuthKey = "10101190"; + private readonly SwiftGrid _grid = new SwiftGrid(); private GoogleAuthenticatorAPI _auth = new GoogleAuthenticatorAPI(); private readonly ApplicationUserDao _obj = new ApplicationUserDao(); @@ -34,18 +37,45 @@ namespace Swift.web.SwiftSystem.UserManagement.AgentUserSetup protected void Page_Load(object sender, EventArgs e) { Authenticate(); + string methodName = Request.Form["MethodName"]; if (!IsPostBack) { + if (methodName == "GetApiCredentials") + GetApiCredentials(); + + if (methodName == "GenerateCredentials") + GenerateCredentials(); + if (GetMode() == 1) GetStatic.AlertMessage(Page); else GetStatic.PrintMessage(Page); LoadTab(); } + DeleteRow(); LoadGrid(); } + + + private void GetApiCredentials() + { + string userId = Request.Form["UserId"]; + var apiDetails = _obj.GetApiCredentials(userId, GetStatic.GetUser()); + + GetStatic.JsonResponse(apiDetails, this.Page); + } + + private void GenerateCredentials() + { + string userId = Request.Form["UserId"]; + var apiCredentials = GetStatic.GetKeys(); + var apiDetails = _obj.GenerateCredentials(userId, GetStatic.GetUser(), apiCredentials); + + GetStatic.JsonResponse(apiDetails, this.Page); + } + protected void LoadTab() { switch (GetMode()) @@ -162,6 +192,10 @@ namespace Swift.web.SwiftSystem.UserManagement.AgentUserSetup if (_sl.HasRight(SendQRCode)) customLinkText.Append(""); + + if (_sl.HasRight(ViewEditAuthKey)) + customLinkText.Append(""); + _grid.CustomLinkText = customLinkText.ToString(); _grid.CustomLinkVariables = "userName,userId,agentId";