예제 #1
0
        public async Task <IWriterResult> UpdateWithdrawSettings(string userId, UpdateWithdrawModel model)
        {
            try
            {
                using (var context = DataContextFactory.CreateContext())
                {
                    var user = await context.Users.FirstOrDefaultAsync(u => u.Id == userId).ConfigureAwait(false);

                    if (user == null)
                    {
                        return(new WriterResult(false, "User not found."));
                    }

                    user.DisableWithdrawEmailConfirmation = model.DisableConfirmation;
                    user.IsUnsafeWithdrawEnabled          = !model.AddressBookOnly;
                    await context.SaveChangesWithAuditAsync().ConfigureAwait(false);

                    await UserSyncService.SyncUser(user.Id).ConfigureAwait(false);

                    return(new WriterResult(true, "Successfully updated withdrawal settings."));
                }
            }
            catch (Exception)
            {
                return(new WriterResult(false));
            }
        }
        public async Task <ActionResult> UpdateWithdrawSettings(UpdateWithdrawModel model)
        {
            if (!await IsSettingsUnlocked())
            {
                return(JsonError());
            }

            if (model.DisableConfirmation)
            {
                var twofactor = await UserManager.GetUserTwoFactorAsync(User.Identity.GetUserId(), TwoFactorComponent.Withdraw);

                if (twofactor == null || twofactor.Type == TwoFactorType.None)
                {
                    return(JsonError(Resources.User.securityTfaEmailErrorMessage));
                }
            }

            var result = await UserSecurityWriter.UpdateWithdrawSettings(User.Identity.GetUserId(), model);

            if (!result.Success)
            {
                return(Json(result));
            }

            await UserSyncService.SyncUser(User.Identity.GetUserId());

            return(Json(result));
        }