[Test] //+
        public void CheckUserIdIsFalse_Test()
        {
            //Assert
            User user = new User {
                Email = "*****@*****.**", Id = 15689
            };
            ForgotPasswordUserModel checkEmail = new ForgotPasswordUserModel()
            {
                Id = user.Id.ToString(), Email = "*****@*****.**"
            };

            IQueryable <User> users = new List <User>()
            {
                user
            }.AsQueryable <User>();

            worldOfWordsUow.Setup(t => t.UserRepository).Returns(userReposit.Object);
            userReposit.Setup(t => t.GetAll()).Returns(users);
            tokenVaidation.Setup(t => t.GetHashSha256(It.IsAny <string>())).Returns("Hrin");

            //Act
            var result = usServ.CheckUserId(checkEmail);

            //Assert
            uowFactory.Verify(f => f.GetUnitOfWork(), Times.Once);
            worldOfWordsUow.Verify(t => t.UserRepository, Times.Once);
            userReposit.Verify(t => t.GetAll(), Times.Once);
            tokenVaidation.Verify(t => t.GetHashSha256(user.Id.ToString()), Times.Once);
            Assert.IsFalse(result);
        }
        [Test] //Work +
        public void ChangePassword_Test()
        {
            //Arrange
            //PasswordHasher pasHesh = new PasswordHasher();
            //string password = pasHesh.HashPassword("hjkol68");
            ForgotPasswordUserModel model = new ForgotPasswordUserModel {
                Id = "5", Password = "******"
            };
            User user = new User();

            user.Email    = "*****@*****.**";
            user.Id       = 5;
            user.Password = "******";
            IQueryable <User> users = new List <User>()
            {
                user
            }.AsQueryable <User>();

            uowFactory.Setup(t => t.GetUnitOfWork()).Returns(worldOfWordsUow.Object);
            worldOfWordsUow.Setup(t => t.UserRepository).Returns(userReposit.Object);
            userReposit.Setup(t => t.GetAll()).Returns(users);

            //Act
            usServ.ChangePassword(model);

            //Assert
            uowFactory.Verify(f => f.GetUnitOfWork(), Times.Once);
            worldOfWordsUow.Verify(t => t.UserRepository, Times.Once);
            userReposit.Verify(t => t.GetAll(), Times.Once);
            Assert.AreNotEqual(model.Password, user.Password);
            Assert.AreEqual(user.Id.ToString(), model.Id);
        }
Beispiel #3
0
 public bool CheckUserId(ForgotPasswordUserModel checkEmail)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         var users = uow.UserRepository.GetAll();
         foreach (var user in users)
         {
             if (_token.GetHashSha256(user.Id.ToString()) == checkEmail.Id)
             {
                 checkEmail.Id = user.Id.ToString();
                 return(true);
             }
         }
         return(false);
     }
     //using (var context = new WorldOfWordsDatabaseContext())
     //{
     //    var users = context.Users;
     //    foreach (var user in users)
     //    {
     //        if (_token.GetHashSha256(user.Id.ToString()) == checkEmail.Id)
     //        {
     //            checkEmail.Id = user.Id.ToString();
     //            return true;
     //        }
     //    }
     //    return false;
     //}
 }
 public IHttpActionResult ChangePassword(ForgotPasswordUserModel model)
 {
     if (_service.CheckUserId(model))
     {
         _service.ChangePassword(model);
         return(Ok(_tokenModel));
     }
     return(BadRequest());
 }
Beispiel #5
0
 public void ChangePassword(ForgotPasswordUserModel model)
 {
     using (var context = new WorldOfWordsDatabaseContext())
     {
         var targetUser =
             context.Users.First(user => user.Id.ToString() == model.Id);
         targetUser.Password = _passwordHasher.HashPassword(model.Password);
         context.SaveChanges();
     }
 }
Beispiel #6
0
 public void ChangePassword(ForgotPasswordUserModel model)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         var targetUser =
             uow.UserRepository.GetAll().First(user => user.Id.ToString() == model.Id);
         targetUser.Password = _passwordHasher.HashPassword(model.Password);
         uow.Save();
     }
 }
Beispiel #7
0
 public bool CheckUserEmail(ForgotPasswordUserModel checkEmail)
 {
     using (var context = new WorldOfWordsDatabaseContext())
     {
         var user = context.Users.FirstOrDefault(us => us.Email == checkEmail.Email);
         if (user != null)
         {
             checkEmail.Id = user.Id.ToString();
             return(true);
         }
         return(false);
     }
 }
        public async Task <IHttpActionResult> ForgotPassword(ForgotPasswordUserModel model)
        {
            if (_service.CheckUserEmail(model))
            {
                var code = GenerateEmailConfirmationToken(model.Id.ToString(), false);

                await SendEmailConfirmationAsync(code, model.Email, "Password reset at WoW");

                return(Ok(_tokenModel));
            }

            return(BadRequest());
        }
Beispiel #9
0
 public bool CheckUserEmail(ForgotPasswordUserModel checkEmail)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         var user = uow.UserRepository.GetAll().FirstOrDefault(us => us.Email == checkEmail.Email);
         if (user != null)
         {
             checkEmail.Id = user.Id.ToString();
             return(true);
         }
         return(false);
     }
 }
Beispiel #10
0
        public async Task Post_ForgotPassword_Should_Return_Ok_TokenModel()
        {
            //Arrange
            var forgotPasswordUser = new ForgotPasswordUserModel
            {
                Email    = "*****@*****.**",
                Id       = "1",
                Password = "******"
            };

            var message = new IdentityMessage
            {
                Body        = "Reset pasword at test.com",
                Destination = "*****@*****.**",
                Subject     = "Password reset"
            };

            //Action
            GenerateData("1", new[] { "NoRoles" });
            RegisterController registerController = new RegisterController(userService.Object,
                                                                           tokenValidation.Object,
                                                                           incUserMapper.Object,
                                                                           mesService.Object);
            var    tokenModel  = new TokenModel();
            string locationUrl = "http://location/";

            urlHelper.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>()))
            .Returns(locationUrl);
            registerController.Url = urlHelper.Object;

            mesService
            .Setup(x => x.SendAsync(message))
            .Returns(Task.FromResult(0));

            userService.Setup(x => x.CheckUserEmail(forgotPasswordUser))
            .Returns(true);

            tokenValidation.Setup(x => x.GetHashSha256("asdf"))
            .Returns("fdsa");

            var actual = await registerController.ForgotPassword(forgotPasswordUser) as OkNegotiatedContentResult <TokenModel>;

            var contentResult = actual as OkNegotiatedContentResult <TokenModel>;

            //Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(actual.Content.GetType(), tokenModel.GetType());
        }
Beispiel #11
0
 public bool CheckUserId(ForgotPasswordUserModel checkEmail)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         var users = uow.UserRepository.GetAll();
         foreach (var user in users)
         {
             if (_token.GetHashSha256(user.Id.ToString()) == checkEmail.Id)
             {
                 checkEmail.Id = user.Id.ToString();
                 return(true);
             }
         }
         return(false);
     }
 }
Beispiel #12
0
 public bool CheckUserId(ForgotPasswordUserModel checkEmail)
 {
     using (var context = new WorldOfWordsDatabaseContext())
     {
         var users = context.Users;
         foreach (var user in users)
         {
             if (_token.GetHashSha256(user.Id.ToString()) == checkEmail.Id)
             {
                 checkEmail.Id = user.Id.ToString();
                 return(true);
             }
         }
         return(false);
     }
 }
Beispiel #13
0
 public void ChangePassword(ForgotPasswordUserModel model)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         var targetUser =
             uow.UserRepository.GetAll().First(user => user.Id.ToString() == model.Id);
         targetUser.Password = _passwordHasher.HashPassword(model.Password);
         uow.Save();
     }
     //using (var context = new WorldOfWordsDatabaseContext())
     //{
     //    var targetUser =
     //            context.Users.First(user => user.Id.ToString() == model.Id);
     //    targetUser.Password = _passwordHasher.HashPassword(model.Password);
     //    context.SaveChanges();
     //}
 }
Beispiel #14
0
        [Test]//work +
        public void CheckUserEmailIsFalse_Test()
        {
            //Arrange
            User user = new User();

            user.Name  = "Petro";
            user.Id    = 1;
            user.Email = "*****@*****.**";


            var forgotPassword = new ForgotPasswordUserModel();

            forgotPassword.Id    = "5";
            forgotPassword.Email = "*****@*****.**";

            entity.Id = 5;

            var reposit    = new Mock <IRepository <IncomingUser> >();
            var iusReposit = new Mock <IUserRepository>();

            IQueryable <User> Users = new List <User>
            {
                user
            }.AsQueryable <User>();


            worldOfWordsUow.Setup(t => t.UserRepository).Returns(iusReposit.Object);
            iusReposit.Setup(t => t.GetAll()).Returns(Users);

            //Act
            var result = usServ.CheckUserEmail(forgotPassword);

            //Assert
            uowFactory.Verify(t => t.GetUnitOfWork(), Times.Exactly(1));
            worldOfWordsUow.Verify(t => t.UserRepository, Times.Exactly(1));
            iusReposit.Verify(t => t.GetAll(), Times.Exactly(1));
            Assert.IsFalse(result);
        }
Beispiel #15
0
        public async Task <IHttpActionResult> ForgotPassword(ForgotPasswordUserModel model)
        {
            if (_service.CheckUserEmail(model))
            {
                var tokenToHash = model.Id.ToString();
                _tokenModel.ForgotPasswordToken = _token.GetHashSha256(tokenToHash);

                var code = _tokenModel.ForgotPasswordToken;

                var callbackUrl = new Uri(Url.Link("AngularRoute", new { }));

                await(_emailService).SendAsync(new IdentityMessage
                {
                    Body        = String.Format(MessagesContainer.ForgotPasswordMessage + callbackUrl + "#/ChangePassword?id={0}", code),
                    Destination = model.Email,
                    Subject     = "Reset password at at WoW"
                });

                return(Ok(_tokenModel));
            }

            return(BadRequest());
        }
        public async Task <IActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userModel = new ForgotPasswordUserModel {
                    Email = model.Email
                };
                var user = await _userManager.FindByEmailAsync(userModel.Email);

                if (user != null && await _userManager.IsEmailConfirmedAsync(user))
                {
                    //Create Token, URL and Log
                    var token = await _userManager.GeneratePasswordResetTokenAsync(user);

                    var passwordResetLink = Url.Action("ResetPassword", "Account", new { @email = userModel.Email, token = token }, Request.Scheme);
                    _logger.Log(LogLevel.Warning, passwordResetLink);

                    return(View("ForgotPasswordConfirmation"));
                }
                return(View("ForgotPasswordConfirmation"));
            }
            return(View(model));
        }
Beispiel #17
0
 public bool CheckUserEmail(ForgotPasswordUserModel checkEmail)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         var user = uow.UserRepository.GetAll().FirstOrDefault(us => us.Email == checkEmail.Email);
         if (user != null)
         {
             checkEmail.Id = user.Id.ToString();
             return(true);
         }
         return(false);
     }
     //using (var context = new WorldOfWordsDatabaseContext())
     //{
     //    var user = context.Users.FirstOrDefault(us => us.Email == checkEmail.Email);
     //    if (user != null)
     //    {
     //        checkEmail.Id = user.Id.ToString();
     //        return true;
     //    }
     //    return false;
     //}
 }