Beispiel #1
0
        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();
                }
            }
        }
Beispiel #2
0
        public UserConfigurationResponse GetConfiguration()
        {
            var user   = GetValidUser();
            var wallet = WalletBusiness.GetByUser(user.Id);

            return(new UserConfigurationResponse()
            {
                AllowNotifications = user.AllowNotifications,
                Wallet = wallet?.Address
            });
        }
Beispiel #3
0
 private void ValidateUserAddress(User user, string address)
 {
     if (address != null)
     {
         address = WalletBusiness.GetAddressFormatted(address);
         if (user.Wallet.Address != address)
         {
             throw new ArgumentException("Invalid user wallet.");
         }
     }
 }
Beispiel #4
0
        private Wallet SetWalletCreation(int userId, string address)
        {
            address = WalletBusiness.GetAddressFormatted(address);

            User user = Data.GetByWalletAddress(address);

            if (user != null)
            {
                throw new ArgumentException("Address already registered.");
            }

            Wallet wallet = new Wallet();

            wallet.UserId  = userId;
            wallet.Address = address;
            return(wallet);
        }
Beispiel #5
0
        public Login Login(string address, string emailOrUsername, string password)
        {
            BaseEmailOrUsernameValidation(emailOrUsername);
            BasePasswordValidation(password);
            address = WalletBusiness.GetAddressFormatted(address);

            var user = Data.GetByEmailOrUsername(emailOrUsername);

            if (user == null)
            {
                throw new ArgumentException("Email or username is invalid.");
            }
            else if (user.Wallet.Address?.ToUpper() != address?.ToUpper())
            {
                throw new ArgumentException("Wallet is invalid.");
            }
            else if (user.Password != Security.Hash(password))
            {
                throw new ArgumentException("Password is invalid.");
            }

            var result = new Model.Login()
            {
                Address             = user.Wallet.Address,
                Email               = user.Email,
                Username            = user.Username,
                PendingConfirmation = !user.ConfirmationDate.HasValue
            };

            if (!result.PendingConfirmation)
            {
                MemoryCache.Set <User>(user.Email, user);
                var purchases = Task.Factory.StartNew(() => BuyBusiness.ListPurchases(user.Id));
                var advisor   = Task.Factory.StartNew(() => AdvisorBusiness.SimpleGetByOwner(user.Id));

                Task.WaitAll(purchases, advisor);

                result.HumanAdvisorId = advisor.Result?.Id;
                result.HasInvestment  = purchases.Result.Count > 0;
            }

            return(result);
        }
Beispiel #6
0
        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
            });
        }
Beispiel #7
0
 public bool IsValidAddressToRegister(string address)
 {
     return(WalletBusiness.IsValidAddress(address) && Data.GetByWalletAddress(address) == null);
 }