public void SetUsersAucSituation() { var users = Data.ListForAucSituation(Admins.Where(c => !string.IsNullOrEmpty(c))); foreach (var user in users) { var start = user.Wallets.OrderBy(c => c.CreationDate).First().CreationDate; var currentWallet = user.Wallets.OrderByDescending(c => c.CreationDate).First(); currentWallet.AUCBalance = WalletBusiness.GetAucAmount(currentWallet.Address); ActionBusiness.InsertJobAucVerification(user.Id, currentWallet.AUCBalance.Value); using (var transaction = TransactionalDapperCommand) { transaction.Update(currentWallet); if (currentWallet.AUCBalance < GetMinimumAucAmountForUser(user)) { user.ReferralStatus = ReferralStatusType.Interrupted.Value; transaction.Update(user); } else if (Data.GetDateTimeNow().Subtract(start).TotalDays >= MinimumDaysToKeepAuc) { user.ReferralStatus = ReferralStatusType.Finished.Value; transaction.Update(user); } transaction.Commit(); } } }
public LoginResponse Login(string email, string password) { BaseEmailValidation(email); EmailValidation(email); BasePasswordValidation(password); var user = GetForLoginByEmail(email); if (user == null || user.Password != GetHashedPassword(password, user.Email, user.CreationDate)) { throw new BusinessException("Invalid credentials."); } bool hasInvestment = GetUserHasInvestment(user); ActionBusiness.InsertNewLogin(user.Id, null, null); return(new LoginResponse() { Id = user.Id, Email = user.Email, PendingConfirmation = !user.ConfirmationDate.HasValue, IsAdvisor = IsValidAdvisor(user), AdvisorName = UserBusiness.GetAdvisorName(user), ProfileUrlGuid = UserBusiness.GetProfileUrlGuid(user), HasInvestment = hasInvestment }); }
private LoginResponse SocialRegister(string email, bool requestedToBeAdvisor, SocialNetworkType socialNetworkType) { var user = SetNewUser(email, null, null, true); Data.Insert(user); ActionBusiness.InsertNewLogin(user.Id, null, socialNetworkType); return(new LoginResponse() { Id = user.Id, Email = user.Email, HasInvestment = false, PendingConfirmation = false, IsAdvisor = false, RequestedToBeAdvisor = requestedToBeAdvisor }); }
public void ValidateUserWallet(User user) { var cacheKey = user.Email + "validated"; var validated = MemoryCache.Get <object>(cacheKey); if (validated == null) { var wallet = Data.GetByUser(user.Id); if (wallet == null) { throw new NotFoundException("Wallet was not defined."); } wallet.AUCBalance = GetAucAmount(wallet.Address); ActionBusiness.InsertNewAucVerification(user.Id, wallet.AUCBalance.Value); Data.Update(wallet); ValidateAucAmount(wallet.AUCBalance.Value, UserBusiness.GetMinimumAucAmountForUser(user)); MemoryCache.Set <object>(cacheKey, true, 20); } }
private LoginResponse SocialLogin(User user, SocialNetworkType socialNetworkType) { if (!user.ConfirmationDate.HasValue) { user.ConfirmationDate = Data.GetDateTimeNow(); Data.Update(user); } bool hasInvestment = GetUserHasInvestment(user); ActionBusiness.InsertNewLogin(user.Id, null, socialNetworkType); return(new LoginResponse() { Id = user.Id, Email = user.Email, PendingConfirmation = !user.ConfirmationDate.HasValue, IsAdvisor = IsValidAdvisor(user), AdvisorName = UserBusiness.GetAdvisorName(user), ProfileUrlGuid = UserBusiness.GetProfileUrlGuid(user), HasInvestment = hasInvestment }); }
public LoginResponse ValidateSignature(string address, string signature) { BaseEmailValidation(LoggedEmail); var user = Data.GetForNewWallet(LoggedEmail); if (user == null) { throw new NotFoundException("User cannot be found."); } if (string.IsNullOrWhiteSpace(signature)) { throw new BusinessException("Signature cannot be empty."); } address = WalletBusiness.GetAddressFormatted(address); var wallet = WalletBusiness.GetByAddress(address); if (wallet != null) { if (wallet.UserId == user.Id) { throw new BusinessException("The wallet is already linked to your account."); } else { throw new BusinessException("The wallet is already on used."); } } var message = $"I accept the Privacy Policy and Terms of Use."; var recoveryAddress = Signature.HashAndEcRecover(message, signature)?.ToLower(); if (address != recoveryAddress) { throw new BusinessException("Invalid signature."); } decimal?aucAmount = null; if (!IsValidAdvisor(user)) { aucAmount = WalletBusiness.GetAucAmount(address); WalletBusiness.ValidateAucAmount(aucAmount.Value, GetMinimumAucAmountForUser(user)); } var creationDate = Data.GetDateTimeNow(); using (var transaction = TransactionalDapperCommand) { transaction.Insert(WalletBusiness.CreateNew(creationDate, user.Id, address, aucAmount)); if (user.ReferredId.HasValue) { user.ReferralStatus = ReferralStatusType.InProgress.Value; transaction.Update(user); } transaction.Commit(); } ActionBusiness.InsertNewWallet(creationDate, user.Id, $"Message: {message} --- Signature: {signature}", aucAmount ?? null); return(new LoginResponse() { Id = user.Id, Email = user.Email, HasInvestment = false, IsAdvisor = IsValidAdvisor(user), AdvisorName = UserBusiness.GetAdvisorName(user), ProfileUrlGuid = UserBusiness.GetProfileUrlGuid(user), PendingConfirmation = !user.ConfirmationDate.HasValue }); }