コード例 #1
0
        public async Task <ActionResult> ResendWithdrawConfirmation(int withdrawid)
        {
            var user = await UserManager.FindValidByIdAsync(User.Identity.GetUserId());

            if (user == null)
            {
                return(JsonError("Unauthorized"));
            }

            var twoFactortoken = await GenerateUserTwoFactorTokenAsync(TwoFactorTokenType.WithdrawConfirm, user.Id);

            var model = new UpdateTwoFactorTokenModel
            {
                WithdrawId     = withdrawid,
                TwoFactorToken = twoFactortoken
            };

            var response = await WithdrawWriter.UpdateTwoFactorToken(User.Identity.GetUserId(), model);

            if (!response.Success)
            {
                return(JsonError(response.Message));
            }

            if (!await SendConfirmationEmail(user, model.Symbol, model.Amount, model.Address, withdrawid, twoFactortoken, model.AddressType))
            {
                return(JsonError("Failed to send email, if problem persists please contact Cryptopia support."));
            }

            return(JsonSuccess($"Successfully sent. Please check {user.Email} for a secure link to confirm this withdrawal."));
        }
コード例 #2
0
        public async Task <IWriterResult> UpdateTwoFactorToken(string userId, UpdateTwoFactorTokenModel model)
        {
            var currentUser = new Guid(userId);

            using (var context = ExchangeDataContextFactory.CreateContext())
            {
                var user = await context.Users.FirstOrDefaultAsync(x => x.Id == currentUser).ConfigureAwait(false);

                if (user == null)
                {
                    return(new WriterResult <int>(false, "Unauthorized"));
                }

                var withdraw = await context.Withdraw
                               .Include(x => x.Currency.Settings)
                               .FirstOrDefaultAsync(w => w.UserId == user.Id && w.Id == model.WithdrawId && w.Status == WithdrawStatus.Unconfirmed)
                               .ConfigureAwait(false);

                if (withdraw == null)
                {
                    return(new WriterResult(false, $"Withdraw #{model.WithdrawId} not found or is already confirmed."));
                }

                withdraw.TwoFactorToken = model.TwoFactorToken;
                await context.SaveChangesAsync().ConfigureAwait(false);

                model.Amount      = withdraw.Amount - withdraw.Fee;
                model.Address     = withdraw.Address;
                model.Symbol      = withdraw.Currency.Symbol;
                model.AddressType = withdraw.Currency.Settings.AddressType;
                return(new WriterResult(true));
            }
        }