Ejemplo n.º 1
0
        public LoginResponse ConfirmEmail(string code)
        {
            var user = Data.GetByConfirmationCode(code);

            if (user == null)
            {
                throw new BusinessException("Invalid confirmation code.");
            }
            else if (user.ConfirmationDate.HasValue)
            {
                throw new BusinessException("Email already confirmed.");
            }

            user.ConfirmationDate = Data.GetDateTimeNow();
            Data.Update(user);

            return(new LoginResponse()
            {
                Id = user.Id,
                Email = user.Email,
                PendingConfirmation = false,
                IsAdvisor = IsValidAdvisor(user),
                AdvisorName = UserBusiness.GetAdvisorName(user),
                ProfileUrlGuid = UserBusiness.GetProfileUrlGuid(user),
                HasInvestment = GetUserHasInvestment(user)
            });
        }
Ejemplo n.º 2
0
        public async Task <LoginResponse> ResendEmailConfirmationAsync()
        {
            var email = LoggedEmail;

            BaseEmailValidation(email);
            EmailValidation(email);

            var user = GetForLoginByEmail(email);

            if (user == null)
            {
                throw new NotFoundException("User cannot be found.");
            }

            if (!user.ConfirmationDate.HasValue)
            {
                await SendEmailConfirmationAsync(email, user.ConfirmationCode);
            }

            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 = GetUserHasInvestment(user)
            });
        }
Ejemplo n.º 3
0
        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
            });
        }
Ejemplo n.º 4
0
        public LoginResponse RecoverPassword(string code, string password)
        {
            var recovery = Data.Get(code);

            if (recovery == null)
            {
                throw new BusinessException("There is no request for recover password.");
            }
            if (Data.GetDateTimeNow() > recovery.CreationDate.AddMinutes(60))
            {
                throw new BusinessException("Recover password code is expired.");
            }

            var user = UserBusiness.GetForLoginById(recovery.UserId);

            UserBusiness.UpdatePassword(user, password);

            bool hasInvestment = UserBusiness.GetUserHasInvestment(user);

            return(new LoginResponse()
            {
                Id = user.Id,
                Email = user.Email,
                PendingConfirmation = !user.ConfirmationDate.HasValue,
                IsAdvisor = UserBusiness.IsValidAdvisor(user),
                AdvisorName = UserBusiness.GetAdvisorName(user),
                ProfileUrlGuid = UserBusiness.GetProfileUrlGuid(user),
                HasInvestment = hasInvestment
            });
        }
Ejemplo n.º 5
0
        public LoginResponse GetLoginResponse()
        {
            var user = GetForLoginByEmail(LoggedEmail);

            if (user == null)
            {
                throw new NotFoundException("User not found.");
            }

            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 = GetUserHasInvestment(user)
            });
        }
Ejemplo n.º 6
0
        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
            });
        }
Ejemplo n.º 7
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
            });
        }