public async Task <ActionResult> GetSecurity()
        {
            var user = await UserManager.FindValidByIdAsync(User.Identity.GetUserId());

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

            var twofactor = await UserManager.GetUserTwoFactorAsync(user.Id, TwoFactorComponent.Settings);

            if (twofactor == null || twofactor.Type == TwoFactorType.None)
            {
                var withdrawTwofactor = await UserManager.GetUserTwoFactorAsync(User.Identity.GetUserId(), TwoFactorComponent.Withdraw);

                return(PartialView("_Security", new UserSecurityModel
                {
                    ApiModel = new UpdateApiModel
                    {
                        IsApiEnabled = user.IsApiEnabled,
                        IsApiWithdrawEnabled = user.IsApiWithdrawEnabled,
                        IsApiUnsafeWithdrawEnabled = user.IsApiUnsafeWithdrawEnabled,
                        ApiKey = user.ApiKey,
                        ApiSecret = user.ApiSecret
                    },
                    WithdrawModel = new UpdateWithdrawModel
                    {
                        AddressBookOnly = !user.IsUnsafeWithdrawEnabled,
                        DisableConfirmation = user.DisableWithdrawEmailConfirmation,
                        HasWithdrawTfa = withdrawTwofactor != null && withdrawTwofactor.Type != TwoFactorType.None
                    }
                }));
            }

            var model = new UserUnlockSecurityModel {
                Type = twofactor.Type
            };

            if (twofactor.Type == TwoFactorType.Question)
            {
                model.Question1 = twofactor.Data;
                model.Question2 = twofactor.Data3;
            }
            if (twofactor.Type == TwoFactorType.EmailCode)
            {
                var twofactorCode = await UserManager.GenerateUserTwoFactorCodeAsync(TwoFactorType.EmailCode, user.Id);

                if (!await SendTwoFactorCode(user, twofactorCode, twofactor.Data))
                {
                    return(ViewMessage(new ViewMessageModel(ViewMessageType.Warning,
                                                            Resources.User.securityUnlockEmailCodeNotSentErrorTitle,
                                                            String.Format(Resources.User.securityUnlockEmailCodeNotSentError,
                                                                          String.Format("<a href='/Support'>{0}</a>", Cryptopia.Resources.General.CryptopiaSupportLink)))
                                       ));
                }
            }

            return(PartialView("_UnlockSecurity", model));
        }
        public async Task <ActionResult> UnlockSecurity(UserUnlockSecurityModel model)
        {
            var user = await UserManager.FindValidByIdAsync(User.Identity.GetUserId());

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

            if (!await UserManager.VerifyUserTwoFactorCodeAsync(TwoFactorComponent.Settings, user.Id, model.Data, model.Data2))
            {
                ModelState.AddModelError("Data", Resources.User.securityUnlockInvalidCodeError);
                return(PartialView("_UnlockSecurity", model));
            }

            user.SettingsUnlocked = DateTime.UtcNow.AddMinutes(10);
            await UserManager.UpdateAsync(user);

            var withdrawTwofactor = await UserManager.GetUserTwoFactorAsync(User.Identity.GetUserId(), TwoFactorComponent.Withdraw);

            return(PartialView("_Security", new UserSecurityModel
            {
                ApiModel = new UpdateApiModel
                {
                    IsApiEnabled = user.IsApiEnabled,
                    IsApiWithdrawEnabled = user.IsApiWithdrawEnabled,
                    IsApiUnsafeWithdrawEnabled = user.IsApiUnsafeWithdrawEnabled,
                    ApiKey = user.ApiKey,
                    ApiSecret = user.ApiSecret
                },
                WithdrawModel = new UpdateWithdrawModel
                {
                    AddressBookOnly = !user.IsUnsafeWithdrawEnabled,
                    DisableConfirmation = user.DisableWithdrawEmailConfirmation,
                    HasWithdrawTfa = withdrawTwofactor != null && withdrawTwofactor.Type != TwoFactorType.None
                }
            }));
        }