public async Task <IHttpActionResult> ForgotPassword(ForgotPasswordBindingModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(model.Email);

                // If user has to activate his email to confirm his account, the use code listing below
                //if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                //{
                //    return Ok();
                //}
                if (user == null)
                {
                    return(Ok());
                }
                var modelPassword = new SetPasswordBindingModel();
                modelPassword.NewPassword     = PasswordGeneratorService.GeneratePassword(6);
                modelPassword.ConfirmPassword = modelPassword.NewPassword;
                modelPassword.Code            = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                var result = SetPassword(user, modelPassword);
                await UserManager.SendEmailAsync(user.Id, "Сброс пароля", $"Ваш новый пароль::" + modelPassword.NewPassword);

                return(Ok());
            }

            // If we got this far, something failed, redisplay form
            return(BadRequest(ModelState));
        }
        public EditStaffViewModel(INavigationService navigationService, IDataService dataService)
        {
            Messenger.Default.Register <List <object> >(this, OnObjectReceived);
            _dataService       = dataService;
            _navigationService = navigationService;
            _pwGenerator       = new PasswordGeneratorService();
            _mailService       = new EmailService();
            LoadCommands();

            BackCommand = new CustomCommand(GoBack, null);
        }
        public void PasswordGeneration_CheckGeneration_StringShouldNotBeEmpty(int userId, DateTime generationDate)
        {
            //Arrange

            _passwordGuidRepositoryMock.Setup(x => x.StoreGuid(It.IsAny <string>())).Returns(true);
            var passwordGenerator = new PasswordGeneratorService(_passwordGuidRepositoryMock.Object);

            //Act

            var password = passwordGenerator.GenerateOneTimePassword(userId, generationDate);

            //Assert

            Assert.IsNotEmpty(password);
        }
        public void PasswordGeneration_CheckGeneration_DecodedPasswordShouldKeepTheValues(int userId, DateTime generationDate)
        {
            //Arrange

            _passwordGuidRepositoryMock.Setup(x => x.StoreGuid(It.IsAny <string>())).Returns(true);
            var passwordGenerator = new PasswordGeneratorService(_passwordGuidRepositoryMock.Object);

            //Act
            var password        = passwordGenerator.GenerateOneTimePassword(userId, generationDate);
            var decodedPassword = EncodingHelper.Base64Decode(password);
            var passwordModel   = JsonConvert.DeserializeObject <PasswordModel>(EncryptionHelper.Decrypt(decodedPassword));


            //Assert
            Assert.AreEqual(userId, passwordModel.UserId);
            Assert.AreEqual(generationDate, new DateTime(passwordModel.CreationDateTicks));
        }
示例#5
0
        public IActionResult Index()
        {
            var x = new PasswordGeneratorService();

            return(View(x));
        }