Пример #1
0
        public bool UpdateVerificationStatus(UserBankAccountRequest request)
        {
            if (SimpleAesUtil.DecryptAES(request.AccountNumber, EwalletConstant.keyAES).IndexOf(EwalletConstant.strWord) == -1)
            {
                return(false);
            }
            WalletTransactionUow WalletTransactionUnitOfWork = new WalletTransactionUow(new WalletEntities());

            try
            {
                WalletTransactionUnitOfWork.BeginTransaction();
                var UserBankAcc = WalletTransactionUnitOfWork.GetBankAccByID(request.ID);
                UserBankAcc.Comments    = request.Comments;
                UserBankAcc.Verify      = request.Verify;
                UserBankAcc.Update_date = DateTime.Now;
                WalletTransactionUnitOfWork.DoUpdate(UserBankAcc).SaveAndContinue();
                WalletTransactionUnitOfWork.EndTransaction();
                return(true);
            }
            catch (Exception ex)
            {
                var logWallet = new LogWallet();
                Task.Factory.StartNew(() => logWallet.Log(MethodBase.GetCurrentMethod(), "", ex, ""));
                return(false);
            }
        }
Пример #2
0
        public string BuildCheckSumAvailable2(Wallet_Account CurrenctWalletAcc)
        {
            try
            {
                if (Globals.StampServerKey != "Invalid Key")
                {
                    //var logWallet = new LogWallet();
                    //logWallet.Log(MethodBase.GetCurrentMethod(), CurrenctWalletAcc.ID + "|" + CurrenctWalletAcc.Wallet_ID + "|" + CurrenctWalletAcc.Currency_Code + "|" + CurrenctWalletAcc.User_ID + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.CreateUser) ? "" : CurrenctWalletAcc.CreateUser.Trim()) + "|" + CurrenctWalletAcc.CreateDate + "|" + CurrenctWalletAcc.UpdateDate + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.UpdateUser) ? "" : CurrenctWalletAcc.UpdateUser.Trim()) + "|" + ConvertUtility.RoundToTwoDecimalPlaces(CurrenctWalletAcc.Available_Balance) + "|" + Globals.StampServerKey, null, "BuildCheckSumAvailable2");
                    if (string.IsNullOrEmpty(Globals.StampServerKey))
                    {
                        localhost.EWallet_StampService stampService = new localhost.EWallet_StampService();
                        var EncryptTokenEBW = SimpleAesUtil.Encrypt(EwalletConstant.TokenEBW);
                        Globals.StampServerKey = stampService.Generate_Stamp_Key(EncryptTokenEBW);
                    }

                    return(SecurityLogic.GetSha1Hash(CurrenctWalletAcc.ID + "|" + CurrenctWalletAcc.Wallet_ID + "|" + CurrenctWalletAcc.Currency_Code + "|" + CurrenctWalletAcc.User_ID + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.CreateUser) ? "" : CurrenctWalletAcc.CreateUser.Trim()) + "|" + CurrenctWalletAcc.CreateDate.ToString("yyyy-MM-dd HH:mm:ss") + "|" + CurrenctWalletAcc.UpdateDate.ToString("yyyy-MM-dd HH:mm:ss") + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.UpdateUser) ? "" : CurrenctWalletAcc.UpdateUser.Trim()) + "|" + ConvertUtility.RoundToTwoDecimalPlaces(CurrenctWalletAcc.Available_Balance) + "|" + Globals.StampServerKey));
                }
                else
                {
                    //var logWallet = new LogWallet();
                    //logWallet.Log(MethodBase.GetCurrentMethod(), CurrenctWalletAcc.ID + "|" + CurrenctWalletAcc.Wallet_ID + "|" + CurrenctWalletAcc.Currency_Code + "|" + CurrenctWalletAcc.User_ID + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.CreateUser) ? "" : CurrenctWalletAcc.CreateUser.Trim()) + "|" + CurrenctWalletAcc.CreateDate + "|" + CurrenctWalletAcc.UpdateDate + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.UpdateUser) ? "" : CurrenctWalletAcc.UpdateUser.Trim()) + "|" + ConvertUtility.RoundToTwoDecimalPlaces(CurrenctWalletAcc.Available_Balance) + "|" + Globals.StampServerKey, null, "BuildCheckSumAvailable2");

                    return("");
                }
            }
            catch (Exception ex)
            {
                var logWallet = new LogWallet();
                Task.Factory.StartNew(() => logWallet.Log(MethodBase.GetCurrentMethod(), CurrenctWalletAcc.Wallet_ID, ex, ""));
                return("");
            }
        }
 public WalletInterestLogic(bool genStampKey = false)
 {
     if (genStampKey)
     {
         localhost.EWallet_StampService stampService = new localhost.EWallet_StampService();
         var EncryptTokenEBW = SimpleAesUtil.Encrypt(EwalletConstant.TokenEBW);
         Globals.StampServerKey = stampService.Generate_Stamp_Key(EncryptTokenEBW);
     }
 }
Пример #4
0
        public TokenTownBusResponse GetAccessTokenTownBus(TokenRequestTownBus requestParams)
        {
            TokenTownBusResponse tokenTownBus = new TokenTownBusResponse();
            var  townBusEntity = new TownBusEntities();
            bool isExistToken  = false;
            WalletTransactionUow WalletTransactionUnitOfWork = null;

            try
            {
                var strCredencial = SimpleAesUtil.DecryptAES(requestParams.Credential, EwalletConstant.keyAES).Split(';');
                var isExists      = new WalletUserTownbusQueryBuilder(new TownBusEntities()).GetUserByLoginIdnPassword(strCredencial.First(), strCredencial.Last()).FirstOrDefault();
                if (isExists != null)
                {
                    var branch = new WalletBranchTownBusQueryBuilder(new TownBusEntities()).HasBranchId(isExists.Branch_ID).FirstOrDefault();
                    if (branch != null)
                    {
                        tokenTownBus.CompanyID = branch.Company_ID;
                    }
                    tokenTownBus.AccessToken = SimpleAesUtil.EncryptAES(isExists.User_ID + isExists.Password + DateTime.Now.ToString("yyyy-MM-dd hh:00:00"), EwalletConstant.keyAES);
                    tokenTownBus.UserID      = isExists.User_ID;
                    //save notificateToken to config
                    if (string.IsNullOrWhiteSpace(requestParams.NotificationToken))
                    {
                        isExistToken = new TownBusNotificationQueryBuilder(townBusEntity).HasNotificationUniqueId(requestParams.CarPlate, tokenTownBus.CompanyID, requestParams.NotificationUniqueId.Trim());
                    }
                    else
                    {
                        isExistToken = new TownBusNotificationQueryBuilder(townBusEntity).HasNotifcationToken(requestParams.CarPlate, tokenTownBus.CompanyID, requestParams.NotificationToken.Trim());
                    }

                    if (!isExistToken)
                    {
                        // var busType = new TownBusTypeQueryBuilder(townBusEntity).GetBusIdByCompanyIdnBusNo(tokenTownBus.CompanyID, requestParams.CarPlate).FirstOrDefault();
                        using (WalletTransactionUnitOfWork = new WalletTransactionUow(townBusEntity))
                        {
                            TownBusNotification townBusNotification = new TownBusNotification();
                            townBusNotification.CarPlate  = requestParams.CarPlate;
                            townBusNotification.CompanyID = tokenTownBus.CompanyID;
                            //townBusNotification.BusID = busType.Bus_ID;
                            townBusNotification.NotificationToken    = requestParams.NotificationToken.Trim();
                            townBusNotification.NotificationUniqueId = requestParams.NotificationUniqueId.Trim();
                            WalletTransactionUnitOfWork.BeginTransaction(System.Data.IsolationLevel.RepeatableRead)
                            .DoInsert(townBusNotification)
                            .EndTransaction();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var logWallet = new LogWallet();
                logWallet.Log(MethodBase.GetCurrentMethod(), requestParams.Credential, ex, "");
                return(tokenTownBus);
            }
            return(tokenTownBus);
        }
 public WalletUserLogic(bool genStampKey = false)
 {
     if (genStampKey)
     {
         //localhost.EWallet_StampService stampService = new localhost.EWallet_StampService();
         var EncryptTokenEBW = SimpleAesUtil.Encrypt(EwalletConstant.TokenEBW);
         Globals.StampServerKey = "5tg8ENcfBwP2z8pWsI5lL8Hab0Tr9VZ5";
         //Globals.StampServerKey = stampService.Generate_Stamp_Key(EncryptTokenEBW);
     }
 }
Пример #6
0
 public WalletRewardLogic(bool genStampKey = false)
 {
     try
     {
         if (genStampKey)
         {
             localhost.EWallet_StampService stampService = new localhost.EWallet_StampService();
             var EncryptTokenEBW = SimpleAesUtil.Encrypt(EwalletConstant.TokenEBW);
             Globals.StampServerKey = stampService.Generate_Stamp_Key(EncryptTokenEBW);
         }
     }
     catch (Exception ex)
     {
         Globals.StampServerKey = "5tg8ENcfBwP2z8pWsI5lL8Hab0Tr9VZ5";
     }
 }
Пример #7
0
        public string BuildCheckSumTotal2(Wallet_Account CurrenctWalletAcc)
        {
            if (string.IsNullOrEmpty(Globals.StampServerKey))
            {
                try
                {
                    localhost.EWallet_StampService stampService = new localhost.EWallet_StampService();
                    var EncryptTokenEBW = SimpleAesUtil.Encrypt(EwalletConstant.TokenEBW);
                    Globals.StampServerKey = stampService.Generate_Stamp_Key(EncryptTokenEBW);
                }
                catch (Exception ex)
                {
                    Globals.StampServerKey = "5tg8ENcfBwP2z8pWsI5lL8Hab0Tr9VZ5";
                }
            }

            string checkSumTotal2 = SecurityLogic.GetSha1Hash(CurrenctWalletAcc.ID + "|" + CurrenctWalletAcc.Wallet_ID + "|" + CurrenctWalletAcc.Currency_Code + "|" + CurrenctWalletAcc.User_ID + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.CreateUser) ? "" : CurrenctWalletAcc.CreateUser.Trim()) + "|" + CurrenctWalletAcc.CreateDate.ToString("yyyy-MM-dd HH:mm:ss") + "|" + CurrenctWalletAcc.UpdateDate.ToString("yyyy-MM-dd HH:mm:ss") + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.UpdateUser) ? "" : CurrenctWalletAcc.UpdateUser.Trim()) + "|" + ConvertUtility.RoundToTwoDecimalPlaces(CurrenctWalletAcc.Total_Balance) + "|" + Globals.StampServerKey);

            //var logWallet = new LogWallet();
            //logWallet.Log(MethodBase.GetCurrentMethod(), CurrenctWalletAcc.ID + "|" + CurrenctWalletAcc.Wallet_ID + "|" + CurrenctWalletAcc.Currency_Code + "|" + CurrenctWalletAcc.User_ID + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.CreateUser) ? "" : CurrenctWalletAcc.CreateUser.Trim()) + "|" + CurrenctWalletAcc.CreateDate + "|" + CurrenctWalletAcc.UpdateDate + "|" + (string.IsNullOrEmpty(CurrenctWalletAcc.UpdateUser) ? "" : CurrenctWalletAcc.UpdateUser.Trim()) + "|" + ConvertUtility.RoundToTwoDecimalPlaces(CurrenctWalletAcc.Total_Balance) + "|" + Globals.StampServerKey, null, "BuildCheckSumTotal2");

            return(checkSumTotal2);
        }
Пример #8
0
        public bool InsertVerificationStatus(UserBankAccountRequest request)
        {
            try
            {
                var BankAcc = SimpleAesUtil.DecryptAES(request.AccountNumber, EwalletConstant.keyAES);
                BankAcc = BankAcc.Replace(EwalletConstant.strWord, "").Replace(" ", "").Replace("-", "");
                double Num;
                bool   isNum = double.TryParse(BankAcc, out Num);

                if (!isNum || BankAcc.Length < 8 || BankAcc.Length > 20)
                {
                    var logWallet = new LogWallet();
                    logWallet.Log(MethodBase.GetCurrentMethod(), "BankAcc: " + BankAcc, null, "Issue for BankACC");
                    return(false);
                }

                byte[] bytes = Convert.FromBase64String(request.urlBankAcc);
                request.FileNameBankAcc = "BankAcc_" + DateTime.Now.Ticks + request.FileNameBankAcc.Substring(request.FileNameBankAcc.LastIndexOf('.'), 4);
                var pathFileNameBankAcc = Path.Combine(EwalletConstant.EWalletPathPictureUpload, request.FileNameBankAcc);
                using (Image image = Image.FromStream(new MemoryStream(bytes)))
                {
                    image.Save(pathFileNameBankAcc);
                }

                bytes = Convert.FromBase64String(request.urlPassIC);
                request.FileNamePasIC = "BankPasIC_" + DateTime.Now.Ticks + request.FileNamePasIC.Substring(request.FileNamePasIC.LastIndexOf('.'), 4);
                var pathFileNamePasIC = Path.Combine(EwalletConstant.EWalletPathPictureUpload, request.FileNamePasIC);
                using (Image image = Image.FromStream(new MemoryStream(bytes)))
                {
                    image.Save(pathFileNamePasIC);
                }

                var userBankAccount = new User_Bank_Account
                {
                    ID            = SecurityLogic.GenerateKey(30),
                    BankCurrency  = request.BankCurrency,
                    CountryBank   = request.CountryBank,
                    BankName      = request.BankName,
                    AccountName   = request.AccountName,
                    AccountNumber = request.AccountNumber,
                    Verify        = "Pending",
                    urlBankAcc    = pathFileNameBankAcc,
                    urlPassIC     = pathFileNamePasIC,
                    User_ID       = request.User_ID,
                    BankCity      = request.BankCity,
                    BranchCode    = request.BranchCode,
                    BranchName    = request.BranchName,
                    Comments      = request.Comments,
                    Create_date   = DateTime.Now,
                    Update_date   = DateTime.Now,
                };


                WalletTransactionUow WalletTransactionUnitOfWork = new WalletTransactionUow(new WalletEntities());

                WalletTransactionUnitOfWork.BeginTransaction();
                WalletTransactionUnitOfWork.DoInsert(userBankAccount).SaveAndContinue();
                WalletTransactionUnitOfWork.EndTransaction();
                return(true);
            }
            catch (Exception ex)
            {
                var logWallet = new LogWallet();
                Task.Factory.StartNew(() => logWallet.Log(MethodBase.GetCurrentMethod(), request, ex, ""));
                return(false);
            }
        }
 public static string GetSignature(string app_id, string campaign_name, string api_secret)
 {
     return(SimpleAesUtil.ComputeSha256Hash(app_id + "|" + campaign_name + "|" + api_secret));
 }
Пример #10
0
        /// <summary>
        /// Register new member if not exists
        /// </summary>
        /// <param name="email"></param>
        /// <param name="phoneCountryCode"></param>
        /// <param name="contact"></param>
        /// <param name="name"></param>
        /// <param name="countryId"></param>
        /// <param name="product"></param>
        /// <param name="RecheckUser"></param>
        /// <returns></returns>
        protected string GetAspNetUserId(string email, string phoneCountryCode, string contact, string name, int countryId = 1, ProductEnum product = ProductEnum.Default, bool RecheckUser = true)
        {
            try
            {
                var    isUserLoggedIn = User.Identity.GetUserId() != null;
                string error;
                string nationalNumber = string.Empty;
                int?   phonePrefixId;
                string dialCode;
                string regionCode = phoneCountryCode.ToUpper();


                var isValidPhoneNumber = new PhoneLogic().IsValidPhone(
                    contact, regionCode, out error, out phonePrefixId, out nationalNumber, out dialCode);

                // To find existing member using email.
                var user = UserManager.FindByEmailAsync(email).Result;

                if (isUserLoggedIn && !RecheckUser)
                {
                    if (user != null && User.Identity.GetUserId() == user.Id)
                    {
                        UpdateNecessaryInformation(countryId, product, nationalNumber, isValidPhoneNumber, user);
                    }
                    else
                    {
                        TrackingAspNetUser(email, "APIBaseController-GetAspNetUserId");
                    }

                    return(User.Identity.GetUserId());
                }

                var isExistingMember = user != null;

                if (isExistingMember)
                {
                    UpdateNecessaryInformation(countryId, product, nationalNumber, isValidPhoneNumber, user);

                    return(user.Id);
                }
                // Cannot validate phone number anymore because not compulsory from front end!!!

                //validate Phone
                //if (!isValidPhoneNumber)
                //{
                //    ModelState.AddModelError(ModelStateConstant.VALIDATION, error);
                //    return null;
                //}

                var password = SimpleAesUtil.RandomPassword(); ////"A1gv@d2^w3";//System.Web.Security.Membership.GeneratePassword(10,1);
                _password = password;
                var identityUser = new IdentityUser
                {
                    UserName             = email,
                    Email                = email,
                    CountryPhonePrefixId = phonePrefixId,
                    PhoneNumber          = nationalNumber,
                    FirstName            = name,
                    //LastName = model.LastName,
                    //FromCompanyId = GlobalVariables.WebsiteCompanyID,
                    CountryId = countryId
                };
                var createResult = UserManager.CreateAsync(identityUser, password).Result;

                if (createResult.Succeeded)
                {
                    return(GetNewlyCreatedAspNetUserIdByEmail(email));
                }

                // Try creating again
                createResult = UserManager.CreateAsync(identityUser, password).Result;

                if (createResult.Succeeded)
                {
                    return(GetNewlyCreatedAspNetUserIdByEmail(email));
                }

                //LogUtil.ErrorWithConditionalEmail(new Exception($"Unable to create AspNetUser with email: {email}."), $"[Desktop-BaseController-GetAspNetUserId]", EmailAddress.MemberLogRecipient);
                throw new Exception($"Unable to create AspNetUser with email: {email}.");
            }
            catch (Exception ex)
            {
                //ModelState.AddModelError(ModelStateConstant.EXCEPTION, ex.Message);
                //LogUtil.Error(ex, "[Desktop-Exception-BaseController-GetAspNetUserId]");
                //return null;
                //LogUtil.ErrorWithConditionalEmail(ex, $"[Desktop-Exception-BaseController-GetAspNetUserId]", EmailAddress.MemberLogRecipient);
                //LogUtil.Error(ex, "[Desktop-Exception-BaseController-GetAspNetUserId]");
                throw;
            }
        }
Пример #11
0
        /// <summary>
        /// Called when a request to the Token endpoint arrives with a "grant_type" of "password". This occurs when the user has provided name and password
        ///             credentials directly into the client application's user interface, and the client application is using those to acquire an "access_token" and
        ///             optional "refresh_token". If the web application supports the
        ///             resource owner credentials grant type it must validate the context.Username and context.Password as appropriate. To issue an
        ///             access token the context.Validated must be called with a new ticket containing the claims about the resource owner which should be associated
        ///             with the access token. The application should take appropriate measures to ensure that the endpoint isn’t abused by malicious callers.
        ///             The default behavior is to reject this grant type.
        ///             See also http://tools.ietf.org/html/rfc6749#section-4.3.2
        /// </summary>
        /// <param name="context">The context of the event carries information in and results out.</param>
        /// <returns>
        /// Task to enable asynchronous execution
        /// </returns>
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            string userName    = "";
            string memberEmail = "";
            var    logWallet   = new LogWallet();

            try
            {
                var aesPassword = ApiCommonConstant.AESPassword;
                var data        = await context.Request.ReadFormAsync();

                memberEmail = data["memberEmail"] != null?SimpleAesUtil.DecryptAES(data["memberEmail"], aesPassword) : string.Empty;

                var memberPassword = data["memberPassword"] != null?SimpleAesUtil.DecryptAES(data["memberPassword"], aesPassword) : string.Empty;

                userName = data["mobileapi"] != null && data["mobileapi"] == "1" ? SimpleAesUtil.DecryptAES(context.UserName, aesPassword) : context.UserName;
                var password = data["mobileapi"] != null && data["mobileapi"] == "1" ? SimpleAesUtil.DecryptAES(context.Password, aesPassword) : context.Password;

                var            type              = "apiuser";
                string         errorMessage      = "";
                bool           failedMemberLogin = false;
                ClaimsIdentity oAuthIdentity     = null;
                //ClaimsIdentity cookiesIdentity = null;

                if (data["memberEmail"] != null && data["memberPassword"] != null)
                {
                    //var memberUserManager =
                    //    new ApplicationUserManager(new UserStore<IdentityUser>());
                    //var memberUser = memberUserManager.FindByEmail(memberEmail);
                    //if (memberUser != null && memberUserManager.CheckPassword(memberUser, memberPassword))
                    //{
                    //    oAuthIdentity = await memberUserManager.CreateIdentityAsync(memberUser, context.Options.AuthenticationType);
                    //    cookiesIdentity = await memberUserManager.CreateIdentityAsync(memberUser, CookieAuthenticationDefaults.AuthenticationType);
                    //    type = "memberuser";
                    //}
                    //else
                    //{
                    //    errorMessage = "Invalid member email and/or password";
                    //    failedMemberLogin = true;
                    //}
                }
                using (UserManager <User> userManager = _userManagerFactory())
                {
                    var user = await userManager.FindAsync(userName, password);

                    if (user == null)
                    {
                        logWallet.Log(MethodBase.GetCurrentMethod(), "The user name or password is incorrect.", null, "");
                        context.SetError("invalid_grant", "The user name or password is incorrect.");
                        return;
                    }
                    if (oAuthIdentity == null)
                    {
                        oAuthIdentity = await userManager.CreateIdentityAsync(user,
                                                                              context.Options.AuthenticationType);
                    }
                    oAuthIdentity.AddClaim(new Claim("clientId", userName));
                    oAuthIdentity.AddClaim(new Claim("permission", user.Permission));
                    oAuthIdentity.AddClaim(new Claim("role", user.Role));
                    oAuthIdentity.AddClaim(new Claim("password", password));
                    oAuthIdentity.AddClaim(new Claim("secretkey", user.ApiSecretkey));
                    oAuthIdentity.AddClaim(new Claim("type", type));
                    oAuthIdentity.AddClaim(new Claim("environment", "staging"));
                    // For logging purposes. Accessed by User.Identity.Name in this project ONLY.
                    oAuthIdentity.AddClaim(new Claim(ClaimTypes.Name, userName));

                    //if (cookiesIdentity == null)
                    //{
                    //    cookiesIdentity = await userManager.CreateIdentityAsync(user,
                    //        CookieAuthenticationDefaults.AuthenticationType);
                    //}
                    //cookiesIdentity.AddClaim(new Claim("clientId", userName));
                    //cookiesIdentity.AddClaim(new Claim("permission", user.Permission));
                    //cookiesIdentity.AddClaim(new Claim("role", user.Role));
                    //cookiesIdentity.AddClaim(new Claim("password", password));
                    //cookiesIdentity.AddClaim(new Claim("secretkey", user.ApiSecretkey));
                    //cookiesIdentity.AddClaim(new Claim("type", type));
                    //cookiesIdentity.AddClaim(new Claim("environment", "staging" ));

                    AuthenticationProperties properties = CreateProperties(user.UserName);
                    properties.Dictionary.Add("type", type);
                    properties.Dictionary.Add("error_message", errorMessage);

                    if (failedMemberLogin)
                    {
                        properties.Dictionary.Add("failed_member_login", "1");
                    }
                    AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);

                    context.Validated(ticket);
                    //context.Request.Context.Authentication.SignIn(cookiesIdentity);
                }
            }
            catch (Exception ex)
            {
                logWallet.Log(MethodBase.GetCurrentMethod(), "userName: "******". memberEmail: " + memberEmail, ex, "");
                EmailUtil.SendEmail("[Exception]-[OAUTH]", ex.StackTrace);
                throw;
            }
        }