public PreTransferOM PreTransfer(UserAccount account, PreTransferIM im) { var toAccount = new UserAccountDAC().GetByCountryIdAndCellphone(im.ToCountryId, im.ToCellphone); if (toAccount == null) { throw new CommonException(ReasonCode.ACCOUNT_NOT_EXISTS, MessageResources.AccountNotExist); } if (account.Id == toAccount.Id) { throw new CommonException(ReasonCode.TRANSFER_TO_SELF, MessageResources.TransferToSelf); } var country = new CountryComponent().GetById(im.ToCountryId); var profile = new UserProfileAgent().GetUserProfile(toAccount.Id); var cryptoCurrency = new CryptocurrencyDAC().GetById(im.CoinId); var fromWallet = new UserWalletComponent().GetUserWallet(account.Id, im.CoinId); return(new PreTransferOM { ToAvatar = toAccount.Photo ?? Guid.Empty, ToAccountName = country.PhoneCode + " " + toAccount.Cellphone, ToFullname = profile == null ? "" : ("* " + profile.LastName), IsTransferAbled = !toAccount.IsAllowTransfer.HasValue || toAccount.IsAllowTransfer.Value, IsProfileVerified = toAccount.L1VerifyStatus == VerifyStatus.Certified, CoinId = cryptoCurrency.Id, CoinCode = cryptoCurrency.Code, MinCount = ((decimal)Math.Pow(10, -cryptoCurrency.DecimalPlace)).ToString("G"), CoinDecimalPlace = cryptoCurrency.DecimalPlace.ToString(), CoinBalance = (fromWallet == null ? "0" : fromWallet.Balance.ToString(cryptoCurrency.DecimalPlace)), FiatCurrency = account.FiatCurrency, Price = (GetExchangeRate(account.CountryId, account.FiatCurrency, cryptoCurrency.Code)).ToString(), ChargeFee = "0" }); }
/// <summary> /// 使用UserId获得KYC服务器地址 /// </summary> /// <param name="id"></param> /// <returns></returns> private ProfileRouter QueryKYCRouter(Guid?id) { var dac = new UserAccountDAC(); var userAccount = dac.GetById(id.Value); return(ProfileFactory.GetByCountryId(userAccount.CountryId)); }
public string TransferInto(Guid openId, string pin, string coinCode, decimal amount) { var coin = new CryptocurrencyDAC().GetByCode(coinCode); if (coin == null) { throw new CommonException(ReasonCode.CRYPTO_NOT_EXISTS, R.ErrorCryptoCode); } var openAccountDac = new OpenAccountDAC(); var openAccount = openAccountDac.GetOpenAccount(openId); if (openAccount == null) { throw new CommonException(ReasonCode.ACCOUNT_NOT_EXISTS, R.AccountNotExist); } switch (openAccount.FiiiType) { case FiiiType.FiiiPay: var accountDac = new UserAccountDAC(); var userAccount = accountDac.GetById(openAccount.AccountId); new SecurityComponent().VerifyPin(userAccount, pin); return(this.FiiiPayTransferInto(userAccount, coin, amount)); case FiiiType.FiiiPOS: MerchantAccount merchantAccount = new MerchantAccountDAC().GetById(openAccount.AccountId); new SecurityComponent().FiiiPOSVerifyPin(merchantAccount, pin); return(this.FiiiPOSTransferInto(merchantAccount, coin, amount)); default: throw new CommonException(ReasonCode.ACCOUNT_NOT_EXISTS, R.AccountNotExist); } }
public bool H5Register(H5RegisterIM im) { if (im.Cellphone.StartsWith("170") || im.Cellphone.StartsWith("171")) { throw new CommonException(ReasonCode.PhoneNumber_Invalid, MessageResources.InvalidCellphone); } var verifier = new RegisterCellphoneVerifier(); SecurityVerify.Verify(verifier, SystemPlatform.FiiiPay, $"{im.CountryId}:{im.Cellphone}", im.SMSCode, true); var accountDAC = new UserAccountDAC(); if (!IsNullOrEmpty(im.InviterCode) && !accountDAC.ExistInviterCode(im.InviterCode)) { throw new CommonException(ReasonCode.INVITORCODE_NOT_EXISTS, MessageResources.InvalidInvitation); } if (!AccountUseable(im.CountryId, im.Cellphone)) { throw new CommonException(ReasonCode.ACCOUNT_EXISTS, Format(MessageResources.AccountAlreadyExist, im.Cellphone)); } bool result = Register(im.CountryId, im.Cellphone, im.Password, im.InviterCode); if (result) { SecurityVerify.InvalidateCode(verifier, SystemPlatform.FiiiPay, $"{im.CountryId}:{im.Cellphone}"); } return(result); }
public void VerifyWithdrawCombine(Guid accountId, string smsCode, string googleCode, string divisionCode) { UserAccount user = new UserAccountDAC().GetById(accountId); List <CombinedVerifyOption> options = new List <CombinedVerifyOption> { new CombinedVerifyOption { AuthType = (byte)ValidationFlag.Cellphone, Code = smsCode }, new CombinedVerifyOption { AuthType = (byte)ValidationFlag.GooogleAuthenticator, Code = googleCode } }; UserSecrets userSecrets = new UserSecrets { ValidationFlag = user.ValidationFlag, GoogleAuthSecretKey = user.AuthSecretKey }; SecurityVerify.CombinedVerify(SystemPlatform.FiiiPay, user.Id.ToString(), userSecrets, options, divisionCode); var model = SecurityVerify.GetModel <WithdrawVerify>(new CustomVerifier("UserWithdraw"), SystemPlatform.FiiiPay, user.Id.ToString()); model.CombinedVerified = true; SecurityVerify.SetModel(new CustomVerifier("UserWithdraw"), SystemPlatform.FiiiPay, user.Id.ToString(), model); }
public UserAccount TokenValidate(string authHeader) { var accessToken = AccessTokenGenerator.DecryptToken(authHeader); var cacheKeyPrefix = "FiiiShop:Token:"; var cacheKey = $"{cacheKeyPrefix}{accessToken.Identity}"; var cacheToken = RedisHelper.StringGet(Constant.REDIS_TOKEN_DBINDEX, cacheKey); if (string.IsNullOrEmpty(cacheToken)) { throw new AccessTokenExpireException(); } if (authHeader != cacheToken) { throw new UnauthorizedException(); } var id = Guid.Parse(accessToken.Identity); var account = new UserAccountDAC().GetById(id); if (account == null) { throw new UnauthorizedException(); } if (account.Status == 0) { //已经禁用的用户,删除token RedisHelper.KeyDelete(Constant.REDIS_TOKEN_DBINDEX, cacheKey); throw new CommonException(ReasonCode.ACCOUNT_DISABLED, "Invalid user"); } RedisHelper.StringSet(Constant.REDIS_TOKEN_DBINDEX, cacheKey, cacheToken, TimeSpan.FromSeconds(AccessTokenGenerator.DefaultExpiryTime)); return(account); }
public TargetAccountDTO GetTargetAccount(int countryId, string cellphone) { CountryDAC countryDac = new CountryDAC(); UserAccountDAC userAccountDac = new UserAccountDAC(); Country country = countryDac.GetById(countryId); if (country == null) { throw new CommonException(ReasonCode.GENERAL_ERROR, R.AccountNotExist); } UserAccount userAccount = userAccountDac.GetByCountryIdAndCellphone(countryId, cellphone); if (userAccount == null) { throw new CommonException(ReasonCode.GENERAL_ERROR, R.AccountNotExist); } var profile = new UserProfileAgent().GetUserProfile(userAccount.Id); return(new TargetAccountDTO { Cellphone = GetMaskedCellphone(country.PhoneCode, userAccount.Cellphone), FullName = profile == null ? "" : ((string.IsNullOrEmpty(profile.FirstName) ? "" : "* ") + profile.LastName), Avatar = userAccount.Photo }); }
public bool CheckPin(Guid accountId, string pin) { var user = new UserAccountDAC().GetById(accountId); SecurityVerify.Verify(new PinVerifier(), SystemPlatform.FiiiShop, accountId.ToString(), user.Pin, pin); return(true); }
public async Task <StoreConsumeDetail> GetConsumeDetailAsync(Guid accountId, Guid orderId, bool isZH) { var storeOrder = await new StoreOrderDAC().GetByIdAsync(orderId); var storeUserAccount = new UserAccountDAC().GetById(storeOrder.UserAccountId); if (storeUserAccount.Id != accountId) { throw new ApplicationException(); } var coin = new CryptocurrencyDAC().GetById(storeOrder.CryptoId); var priceInfo = new PriceInfoDAC().GetPriceByName(storeOrder.FiatCurrency, storeOrder.CryptoCode); var iRate = ((priceInfo - storeOrder.ExchangeRate) / storeOrder.ExchangeRate) * 100; return(new StoreConsumeDetail { Id = storeOrder.Id, Type = Resources.Payment, CryptoActualAmount = storeOrder.CryptoAmount.ToString(coin.DecimalPlace), CryptoCode = storeOrder.CryptoCode, Status = new UserStatementComponent().GetStatusStr(2, (int)storeOrder.Status, isZH), MerchantName = storeOrder.MerchantInfoName, FiatCurrency = storeOrder.FiatCurrency, FiatAmount = storeOrder.FiatAmount.ToString(2), MarkUp = $"{(storeOrder.Markup * 100).ToString(2)}%", ExchangeRate = $"1 {coin.Code} = {storeOrder.ExchangeRate.ToString(4)} {storeOrder.FiatCurrency}", CurrentExchangeRate = coin.Enable == 1 ? $"1 {coin.Code} = {priceInfo.ToString(4)} {storeOrder.FiatCurrency}" : "--", IncreaseRate = coin.Enable == 1 ? (iRate > 0 ? $"+{iRate.ToString(2)}" : iRate.ToString(2)) : "--", Timestamp = storeOrder.Timestamp.ToUnixTime().ToString(), OrderNo = storeOrder.OrderNo }); }
private string GetUserMastMaskedCellphone(Guid userAccountId) { var user = new UserAccountDAC().GetById(userAccountId); var country = new CountryComponent().GetById(user.CountryId); return(CellphoneExtension.GetMaskedCellphone(country.PhoneCode, user.Cellphone)); }
private bool AccountUseable(int countryId, string cellphone) { var readUserAccountDAC = new UserAccountDAC(); var existedUserAccount = readUserAccountDAC.GetByCountryIdAndCellphone(countryId, cellphone); if (existedUserAccount != null) { return(false); } return(true); }
public void VerifyWithdrawPIN(Guid accountId, string pin) { UserAccount user = new UserAccountDAC().GetById(accountId); SecurityVerify.Verify(new PinVerifier(), SystemPlatform.FiiiPay, accountId.ToString(), user.Pin, pin); var model = new WithdrawVerify { PinVerified = true }; SecurityVerify.SetModel(new CustomVerifier("UserWithdraw"), SystemPlatform.FiiiPay, accountId.ToString(), model); }
public void CloseUserAccount(UserAccount user) { SecurityVerify.Verify <CloseGoogleAuth>(new CustomVerifier("CloseGoogleAuth"), SystemPlatform.FiiiPay, user.Id.ToString(), (model) => { return(model.PinVerified && model.CombinedVerified); }); var userDAC = new UserAccountDAC(); var oldFlag = user.ValidationFlag; var newFlag = ValidationFlagComponent.ReduceValidationFlag(oldFlag, ValidationFlag.GooogleAuthenticator); userDAC.UpdateGoogleAuthencator(user.Id, newFlag); }
/// <summary> /// /// </summary> /// <param name="im">邀请码</param> public CellPhoneOM GetCellPhoneInfo(string im) { var account = new UserAccountDAC().GetUserAccountByInviteCode(im); if (account == null) { throw new CommonException(ReasonCode.INVITORCODE_NOT_EXISTS, MessageResources.InvalidInvitation); } return(new CellPhoneOM() { PhoneRegion = account.PhoneCode, CellPhone = account.Cellphone }); }
private UserAccount CheckUser(int countryId, string cellphone) { var user = new UserAccountDAC().GetByCountryIdAndCellphone(countryId, cellphone); if (user == null) { throw new CommonException(ReasonCode.ACCOUNT_NOT_EXISTS, MessageResources.AccountNotFound); } if (user.Status == 0) { throw new CommonException(ReasonCode.ACCOUNT_DISABLED, MessageResources.AccountDisabled); } return(user); }
public override Account GetById(Guid id) { var baseAccount = new UserAccountDAC().GetById(id); if (baseAccount == null) { return(null); } return(new Account { Id = baseAccount.Id, Email = baseAccount.Email }); }
public async Task <LoginDto> Login(LoginVo vo, string ip) { var user = new UserAccountDAC().GetByFullPhoneCode(vo.CountryPhoneCode, vo.Cellphone); SecurityVerify.Verify(new LoginCellphoneVerifier(), SystemPlatform.FiiiShop, $"{user.CountryId}:{vo.Cellphone}", vo.SmsCode); if (user == null) { throw new CommonException(ReasonCode.ACCOUNT_NOT_EXISTS, Properties.Resource.MsgAccountNotExist); } if (user.Status == 0) { throw new CommonException(ReasonCode.ACCOUNT_DISABLED, Properties.Resource.MsgAccountDisabled); } return(await IssueAccessToken(user)); }
/// <summary> /// 发送登录验证码 /// </summary> /// <param name="phoneCode"></param> /// <param name="cellphone"></param> public bool SendLoginCode(string phoneCode, string cellphone) { var user = new UserAccountDAC().GetByFullPhoneCode(phoneCode, cellphone); if (user == null) { throw new CommonException(ReasonCode.ACCOUNT_NOT_EXISTS, Properties.Resource.MsgAccountNotExist); } if (user.Status == 0) { throw new CommonException(ReasonCode.ACCOUNT_DISABLED, Properties.Resource.MsgAccountDisabled); } SecurityVerify.SendCode(new LoginCellphoneVerifier(), SystemPlatform.FiiiShop, $"{user.CountryId}:{cellphone}", $"{phoneCode}{cellphone}"); return(true); }
public void ResetPIN(Guid accountId, string pin) { SecurityVerify.Verify <ResetPinVerify>(new CustomVerifier("ResetPin"), SystemPlatform.FiiiPay, accountId.ToString(), (model) => { return(model.CombinedVerified); }); UserAccount user = new UserAccountDAC().GetById(accountId); if (PasswordHasher.VerifyHashedPassword(user.Pin, pin)) { throw new CommonException(ReasonCode.PIN_MUST_BE_DIFFERENT, MessageResources.NewPINOldPINDifferent); } UserAccountDAC mad = new UserAccountDAC(); mad.SetPinById(accountId, PasswordHasher.HashPassword(pin)); SecurityVerify.DeleteErrorCount(new PinVerifier(), SystemPlatform.FiiiPay, accountId.ToString()); }
/// <summary> /// 发送忘记密码验证码 /// </summary> /// <param name="countryId"></param> /// <param name="cellphone"></param> public void SendForgotPasswordCode(int countryId, string cellphone) { var user = new UserAccountDAC().GetByCountryIdAndCellphone(countryId, cellphone); if (user == null) { throw new CommonException(ReasonCode.ACCOUNT_NOT_EXISTS, MessageResources.AccountNotFound); } if (user.Status == 0) { throw new CommonException(ReasonCode.ACCOUNT_DISABLED, MessageResources.AccountDisabled); } var country = new CountryComponent().GetById(countryId); SecurityVerify.SendCode(new ForgetPasswordCellphoneVerifier(), SystemPlatform.FiiiPay, $"{countryId}:{cellphone}", $"{country.PhoneCode}{cellphone}"); }
private string GenerateInvitationCode(string code = null) { if (IsNullOrEmpty(code)) { code = RandomAlphaNumericGenerator.GenerateCode(5); } var accountDAC = new UserAccountDAC(); if (accountDAC.ExistInviterCode(code)) { var newCode = RandomAlphaNumericGenerator.GenerateCode(5); code = GenerateInvitationCode(newCode); return(code); } return(code); }
/// <summary> /// 修改邮箱 /// </summary> /// <param name="user"></param> /// <param name="originalCode">最初的验证码</param> /// <param name="email">新邮箱地址</param> /// <param name="code">新邮箱验证码</param> /// <returns></returns> public void UpdateEmail(UserAccount user, string email) { SecurityVerify.Verify <UpdateEmailVerify>(new CustomVerifier("UpdateEmail"), SystemPlatform.FiiiPay, user.Id.ToString(), (model) => { return(model.PinVerified && model.NewEmailVerified && model.OriginalEmailVerified); }); if (user.Email == email) { throw new CommonException(ReasonCode.ORIGIN_NEW_EMAIL_SAME, MessageResources.NewMailOldSame); } var accountByEmail = new UserAccountDAC().GetByEmail(email); if (accountByEmail != null && accountByEmail.Id != user.Id) { throw new CommonException(ReasonCode.EMAIL_BINDBYOTHER, MessageResources.EmailHasBind); } new UserAccountDAC().SetEmailById(user.Id, email); }
/// <summary> /// 修改邀请码 /// </summary> /// <param name="merchantId"></param> /// <param name="email"></param> /// <returns></returns> public void UpdateInviterCode(Guid merchantId, string inviterCode) { UserAccountDAC uaDac = new UserAccountDAC(); if (!string.IsNullOrEmpty(inviterCode) && !uaDac.ExistInviterCode(inviterCode)) { throw new CommonException(ReasonCode.FiiiPosReasonCode.INVITERCODE_NOT_EXISTS, "邀请码不存在"); } var user = uaDac.GetUserAccountByInviteCode(inviterCode); InviteRecordDAC irDac = new InviteRecordDAC(); InviteRecord model = new InviteRecord(); model.AccountId = merchantId; model.InviterCode = inviterCode; model.Type = InviteType.Fiiipos; model.Timestamp = DateTime.UtcNow; model.InviterAccountId = user.Id; irDac.Insert(model);; }
public void BindUserAccount(BindUserAuthIM im, UserAccount user) { SecurityVerify.Verify <BindGoogleAuth>(new CustomVerifier("BindGoogleAuth"), SystemPlatform.FiiiPay, user.Id.ToString(), (model) => { return(model.PinVerified && model.GoogleVerified && model.CombinedVerified); }); var userDAC = new UserAccountDAC(); if (string.IsNullOrEmpty(user.AuthSecretKey)) { var oldFlag = user.ValidationFlag; var newFlag = ValidationFlagComponent.AddValidationFlag(oldFlag, ValidationFlag.GooogleAuthenticator); userDAC.UpdateGoogleAuthencator(user.Id, im.SecretKey, newFlag); } else { userDAC.SetAuthSecretById(user.Id, im.SecretKey); } }
private PrePayOM GetUserPrePayOM(Guid userAccountId, MerchantInformation merchantInfo) { var userDAC = new UserAccountDAC(); var merchantDAC = new MerchantInformationDAC(); var merchantUserAccount = userDAC.GetById(merchantInfo.MerchantAccountId); var supportList = new MerchantSupportCryptoDAC().GetList(merchantInfo.Id).ToList(); var userWallets = new UserWalletDAC().GetUserWallets(userAccountId); var coins = new CryptocurrencyDAC().GetAllActived(); var priceList = new PriceInfoDAC().GetPrice(merchantUserAccount.FiatCurrency); var whilteLabelCryptoCode = new POSDAC().GetWhiteLabelCryptoCode(); coins.RemoveAll(t => t.Code == whilteLabelCryptoCode); return(new PrePayOM { FiatCurrency = merchantUserAccount.FiatCurrency, MarkupRate = merchantInfo.Markup.ToString(CultureInfo.InvariantCulture), WaletList = coins.Select(a => { var userWallet = userWallets.FirstOrDefault(b => b.CryptoId == a.Id); decimal rate = 0; rate = priceList.Where(t => t.CryptoID == a.Id).Select(t => t.Price).FirstOrDefault(); return GetUserSupportItem(userWallet, a, supportList, rate); }).OrderByDescending(a => a.MerchantSupported).ThenBy(a => a.PayRank).Select(a => new WalletItem { Code = a.Code, NewStatus = a.NewStatus, ExchangeRate = a.ExchangeRate, FrozenBalance = a.FrozenBalance, IconUrl = a.IconUrl, Id = a.Id, MerchantSupported = a.MerchantSupported, Name = a.Name, UseableBalance = a.UseableBalance, FiatBalance = a.FiatBalance, DecimalPlace = a.DecimalPlace, CryptoEnable = a.CryptoEnable }).ToList() }); }
public void ForgotPassword(int countryId, string cellphone, string password) { SecurityVerify.Verify <ResetPasswordVerify>(new CustomVerifier("ForgotPassword"), SystemPlatform.FiiiPay, $"{countryId}:{cellphone}", (model) => { return(model.CellphoneVerified); }); var user = new UserAccountDAC().GetByCountryIdAndCellphone(countryId, cellphone); if (PasswordHasher.VerifyHashedPassword(user.Password, password)) { throw new CommonException(ReasonCode.PWD_MUST_BE_DIFFERENT, MessageResources.NewPasswordHasUse); } new UserAccountComponent().Logout(user); user.Password = PasswordHasher.HashPassword(password); new UserAccountDAC().Update(user); new SecurityVerification(SystemPlatform.FiiiPay).DeleteErrorCount(SecurityMethod.Password, user.Id.ToString()); }
public OrderDetailDTO OrderDetail(long accountId, Guid orderId) { InvestorOrder order = new InvestorOrderDAC().GetById(accountId, orderId); if (order == null) { throw new CommonException(ReasonCode.GENERAL_ERROR, R.订单不存在); } UserAccount userAccount = new UserAccountDAC().GetById(order.UserAccountId); if (userAccount == null) { throw new CommonException(ReasonCode.GENERAL_ERROR, R.用户不存在); } Country country = new CountryDAC().GetById(userAccount.CountryId); if (country == null) { throw new CommonException(ReasonCode.GENERAL_ERROR, R.用户不存在); } var profile = new UserProfileAgent().GetUserProfile(userAccount.Id); Cryptocurrency crypto = new CryptocurrencyDAC().GetById(order.CryptoId); return(new OrderDetailDTO { OrderId = order.Id, OrderNo = order.OrderNo, TransactionType = order.TransactionType, Status = order.Status, CryptoCode = crypto.Code, Amount = order.CryptoAmount.ToString(crypto.DecimalPlace), UserAccount = GetMaskedCellphone(country.PhoneCode, userAccount.Cellphone), Username = profile == null ? "" : ((string.IsNullOrEmpty(profile.FirstName) ? "" : "* ") + profile.LastName), Timestamp = order.Timestamp.ToUnixTime() }); }
public void UpdateCellphone(UserAccount user, string cellphone) { SecurityVerify.Verify <UpdateCellphoneVerify>(new CustomVerifier("UpdateCellphone"), SystemPlatform.FiiiPay, user.Id.ToString(), (model) => { return(model.PinVerified && model.NewCellphoneVerified); }); if (new UserAccountDAC().GetByCountryIdAndCellphone(user.CountryId, cellphone) != null) { throw new ApplicationException(MessageResources.MobilePhoneHasReg); } user.Cellphone = cellphone; var sr = new UserProfileAgent().UpdatePhoneNumber(user.Id, cellphone); if (sr) { UserAccountDAC accountDAC = new UserAccountDAC(); sr = accountDAC.UpdatePhoneNumber(user.Id, cellphone); } new UserAccountComponent().Logout(user); }
public string GenerateNickname(string code = null) { string prevStr = "user_"; if (IsNullOrEmpty(code)) { code = RandomAlphaNumericGenerator.GenerateCode(10); } string nickname = prevStr + code; var accountDAC = new UserAccountDAC(); if (accountDAC.ExistInviterCode(nickname)) { var newCode = RandomAlphaNumericGenerator.GenerateCode(10); nickname = GenerateNickname(newCode); return(nickname); } return(nickname); }
private UserAccount CheckUser(int countryId, string cellphone, string password) { var user = new UserAccountDAC().GetByCountryIdAndCellphone(countryId, cellphone); if (user == null) { throw new CommonException(ReasonCode.ACCOUNT_NOT_EXISTS, MessageResources.AccountNotFound); } var securityVerify = new SecurityVerification(SystemPlatform.FiiiPay); var loginErrorCountsInt = securityVerify.CheckErrorCount(SecurityMethod.Password, user.Id.ToString()); if (user.Status == 0) { throw new CommonException(ReasonCode.ACCOUNT_DISABLED, MessageResources.AccountDisabled); } if (IsNullOrWhiteSpace(user.Password) || IsNullOrWhiteSpace(password) || !PasswordHasher.VerifyHashedPassword(user.Password, password)) { securityVerify.IncreaseErrorCount(SecurityMethod.Password, user.Id.ToString()); } securityVerify.DeleteErrorCount(SecurityMethod.Password, user.Id.ToString()); return(user); }