Ejemplo n.º 1
0
        public async Task <ActionResult> Remove()
        {
            var user = UserManager.FindById(User.Identity.GetId());

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

            if (user.TwoFactorType == TwoFactorType.EmailCode)
            {
                var twofactorCode = await UserManager.GenerateTwoFactorCodeAsync(user.Id);

                if (!await EmailService.SendEmail(EmailTemplateType.TwoFactorRemove, user.Id, user.Email, Request.GetIPAddress(), user.UserName, twofactorCode))
                {
                    return(View("Error", Resources.TwoFactor.ErrorMessageTitleSendEmail, Resources.TwoFactor.ErrorMessageTextSendEmail));
                }
            }

            var model = new RemoveTwoFactorModel
            {
                Type = user.TwoFactorType
            };

            return(View("Remove", model));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Remove(RemoveTwoFactorModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Remove", model));
            }

            var user = UserManager.FindById(User.Identity.GetId());

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

            if (user.TwoFactorType == TwoFactorType.None)
            {
                return(RedirectToAction("Index", "AccountSettings"));
            }

            if (!await UserManager.CheckTwoFactorAsync(user, model.Data))
            {
                // failed to validate last TFA
                ModelState.AddModelError("Data", Resources.TwoFactor.InvalidTwoFactorText);
                return(View("Remove", model));
            }

            // Delete TFA
            user.TwoFactorType = TwoFactorType.None;
            //twofactor.Updated = DateTime.UtcNow;

            await UserManager.UpdateAsync(user);

            return(RedirectToAction("Create"));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Remove(RemoveTwoFactorModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Remove", model));
            }

            var user = UserManager.FindById(User.Identity.GetUserId());

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

            var twofactor = user.TwoFactor.FirstOrDefault(x => x.Component == model.ComponentType && x.Type == model.Type);

            if (twofactor == null)
            {
                return(RedirectToRoute("Security"));
            }

            if (!await UserManager.VerifyUserTwoFactorCodeAsync(model.ComponentType, user.Id, model.Data, model.Data2))
            {
                // failed to validate last TFA
                ModelState.AddModelError("", Resources.Authorization.twoFactorRemoveIncorrectTfaErrorMessage);
                return(View("Remove", model));
            }

            // Delete TFA
            twofactor.ClearData();
            twofactor.Type = TwoFactorType.None;
            //twofactor.Updated = DateTime.UtcNow;

            if (model.ComponentType == TwoFactorComponent.Withdraw)
            {
                user.DisableWithdrawEmailConfirmation = false;
            }

            await UserManager.UpdateAsync(user);

            await UserSyncService.SyncUser(user.Id);

            return(RedirectToRoute("Security"));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Remove(TwoFactorComponent componentType)
        {
            var user = UserManager.FindById(User.Identity.GetUserId());

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

            var twofactor = user.TwoFactor.FirstOrDefault(x => x.Component == componentType) ??
                            new UserTwoFactor {
                Type = TwoFactorType.None
            };

            if (twofactor.Type == TwoFactorType.EmailCode)
            {
                var twofactorCode = await UserManager.GenerateUserTwoFactorCodeAsync(TwoFactorType.EmailCode, user.Id);

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

            var model = new RemoveTwoFactorModel
            {
                Type          = twofactor.Type,
                ComponentType = componentType,
            };

            if (twofactor.Type == TwoFactorType.Question)
            {
                model.Question1 = twofactor.Data;
                model.Question2 = twofactor.Data3;
            }

            return(View("Remove", model));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Remove(RemoveTwoFactorModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Remove", model));
            }

            var user = UserManager.FindById(User.Id());

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

            var twofactor = user.TwoFactor.FirstOrDefault(x => x.Component == model.ComponentType && x.Type == model.Type);

            if (twofactor == null)
            {
                return(RedirectToRoute("Security"));
            }

            if (!await UserManager.VerifyUserTwoFactorCodeAsync(model.ComponentType, user.Id, model.Data))
            {
                // failed to validate last TFA
                ModelState.AddModelError("", "Incorrect TFA code.");
                return(View("Remove", model));
            }

            // Delete TFA
            twofactor.ClearData();
            twofactor.Type    = TwoFactorType.None;
            twofactor.Updated = DateTime.UtcNow;
            await UserManager.UpdateAsync(user);

            return(RedirectToRoute("Security"));
        }