Esempio n. 1
0
        public async Task <string> ResetMobileStep2(ResetPwdViewModel model, string number)
        {
            if (!ModelState.IsValid)
            {
                return("error");
            }
            if (number == null)
            {
                return("number-error");
            }
            var user = UserManager.FindByPhoneNumber(number);

            if (user == null)
            {
                return("notfound");
            }
            var result = await UserManager.ResetPasswordAsync(user.Id, model.Code, model.NewPassword);

            if (result.Succeeded)
            {
                return("ok");
            }
            // If we got this far, something failed, redisplay form
            return("error");
        }
Esempio n. 2
0
        public async Task <IActionResult> Reset([FromBody] ResetPwdViewModel viewModel)
        {
            if (CurrentUser.Id == viewModel.Id)
            {
                var loader = new Loader <User>()
                {
                    Id = CurrentUser.Id
                };
                await DataHandler.Execute(loader);

                if (loader.Result != null && loader.Result.EncryptedPwd == EncryptHelper.Encrypt(viewModel.Current))
                {
                    loader.Result.EncryptedPwd = EncryptHelper.Encrypt(viewModel.Replacement);

                    var persist = new Persist <User> {
                        Model = loader.Result
                    };
                    await DataHandler.Execute(persist);

                    if (persist.Confirm.Success)
                    {
                        await DataHandler.Commit();
                    }

                    return(Ok(ConfirmViewModel.CreateFromConfirm(persist.Confirm)));
                }

                return(Ok(ConfirmViewModel.CreateFailure("Password not correct")));
            }

            return(Unauthorized());
        }
Esempio n. 3
0
        public async Task UserControllerResetBadPwd()
        {
            var data  = new UserApiDataHandler();
            var model = UserData.GetFirst();

            data.Result.Setup(m => m.Execute(It.IsAny <Loader <User> >())).Returns(model);
            data.Result.Setup(m => m.Execute(It.IsAny <Persist <User> >())).Returns(model);

            var controller = new UserController(data, Logic)
            {
                CurrentUser = StandardUser
            };
            var viewModel = new ResetPwdViewModel()
            {
                Current = "wrong", Id = UserData.FirstId, Replacement = "bollocks"
            };
            var result = await controller.Reset(viewModel) as OkObjectResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();
            result.Value.Should().NotBeNull();

            var check = result.Value as ConfirmViewModel;

            check.Success.Should().BeFalse();

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <Loader <User> >()), Times.Once);
            data.Result.Verify(s => s.Execute(It.IsAny <Persist <User> >()), Times.Never());
        }
Esempio n. 4
0
        public async Task UserControllerResetUnauth()
        {
            var data  = new UserApiDataHandler();
            var model = UserData.GetFirst();

            data.Result.Setup(m => m.Execute(It.IsAny <Loader <User> >())).Returns(model);
            data.Result.Setup(m => m.Execute(It.IsAny <Persist <User> >())).Returns(model);

            var controller = new UserController(data, Logic)
            {
                CurrentUser = StandardUser
            };
            var viewModel = new ResetPwdViewModel()
            {
                Current = UserData.FirstPwd, Id = UserData.SecondId, Replacement = "bollocks"
            };
            var result = await controller.Reset(viewModel) as UnauthorizedResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <UnauthorizedResult>();

            data.HasExecuted.Should().BeFalse();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <Loader <User> >()), Times.Never);
            data.Result.Verify(s => s.Execute(It.IsAny <Persist <User> >()), Times.Never());
        }
Esempio n. 5
0
        public async Task <IActionResult> ResetPwdConfirmAsync(ResetPwdViewModel pwdModel)
        {
            var services = new ServiceCollection();

            services.AddLogging();
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Startup.ConnectionString));

            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            using (var serviceProvider = services.BuildServiceProvider())
            {
                using (var scope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope())
                {
                    var context = scope.ServiceProvider.GetService <ApplicationDbContext>();

                    var userMgr   = scope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >();
                    var checkUser = userMgr.FindByIdAsync(pwdModel.UserId).Result;
                    var result    = await userMgr.ResetPasswordAsync(checkUser, pwdModel.code, pwdModel.newPwd);

                    var rst = result;
                }
                return(View());
            }
        }// End Class
Esempio n. 6
0
        public async Task <string> ResetEmailStep2(ResetPwdViewModel model, int userid)
        {
            if (!ModelState.IsValid)
            {
                return("error");
            }
            var result = await UserManager.ResetPasswordAsync(userid, model.Code, model.NewPassword);

            if (result.Succeeded)
            {
                return("ok");
            }
            // If we got this far, something failed, redisplay form
            return("error");
        }
Esempio n. 7
0
 public IActionResult ResetPwdForm(ResetPwdViewModel pwdModel)
 {
     ViewBag.id   = pwdModel.UserId;
     ViewBag.code = pwdModel.code;
     return(View());
 }