public void ResetPasswordSuccessfultest_TestsIfPasswordIsResetProperly_VerifiesThroughReturnValues()
        {
            IUserApplicationService         userApplicationService         = (IUserApplicationService)_applicationContext["UserApplicationService"];
            IRegistrationApplicationService registrationApplicationService =
                (IRegistrationApplicationService)_applicationContext["RegistrationApplicationService"];
            IUserRepository            userRepository     = (IUserRepository)_applicationContext["UserRepository"];
            IPasswordEncryptionService passwordEncryption =
                (IPasswordEncryptionService)_applicationContext["PasswordEncryptionService"];

            string username         = "******";
            string email            = "*****@*****.**";
            string activationKey    = registrationApplicationService.CreateAccount(new SignupUserCommand(email, username, "burnitdown", "USA", TimeZone.CurrentTimeZone, ""));
            bool   accountActivated = userApplicationService.ActivateAccount(new ActivationCommand(activationKey, username, "burnitdown"));

            Assert.IsTrue(accountActivated);
            ManualResetEvent manualResetEvent = new ManualResetEvent(false);

            manualResetEvent.WaitOne(6000);
            string returnedPasswordCode = userApplicationService.ForgotPassword(new ForgotPasswordCommand(email, username));

            Assert.IsNotNull(returnedPasswordCode);
            string newPassword = "******";

            bool resetPasswordReponse = userApplicationService.ResetPasswordByEmailLink(new ResetPasswordCommand(username, newPassword, returnedPasswordCode));

            Assert.IsTrue(resetPasswordReponse);

            User userByUserName = userRepository.GetUserByUserName(username);

            Assert.IsNotNull(userByUserName);
            Assert.IsTrue(passwordEncryption.VerifyPassword(newPassword, userByUserName.Password));
        }
        public void ForgotPasswordSuccessfultest_TestsIfForgotPasswordReqeustIsSentSuccessfullyAndForgotPasswordCodeUpdatedInUserProperly_VerifiesThroughReturnValues()
        {
            IUserApplicationService         userApplicationService         = (IUserApplicationService)_applicationContext["UserApplicationService"];
            IRegistrationApplicationService registrationApplicationService =
                (IRegistrationApplicationService)_applicationContext["RegistrationApplicationService"];
            IUserRepository userRepository = (IUserRepository)_applicationContext["UserRepository"];

            ManualResetEvent manualResetEvent = new ManualResetEvent(false);
            string           username         = "******";
            string           email            = "*****@*****.**";
            string           activationKey    = registrationApplicationService.CreateAccount(new SignupUserCommand(email, username, "burnitdown", "USA", TimeZone.CurrentTimeZone, ""));

            userApplicationService.ActivateAccount(new ActivationCommand(activationKey, username, "burnitdown"));
            manualResetEvent.WaitOne(6000);

            string returnedPasswordCode = userApplicationService.ForgotPassword(new ForgotPasswordCommand(email, username));

            // Wait for the email to be sent and operation to be completed
            manualResetEvent.WaitOne(5000);
            Assert.IsNotNull(returnedPasswordCode);

            User userByUserName = userRepository.GetUserByUserName(username);

            Assert.IsNotNull(userByUserName);
            Assert.AreEqual(returnedPasswordCode, userByUserName.ForgotPasswordCode);
            Assert.AreEqual(1, userByUserName.ForgottenPasswordCodes.Length);
            Assert.AreEqual(DateTime.Now.Hour + 2, userByUserName.ForgotPasswordCodeExpiration.Value.Hour);
        }
        public void ForgotPasswordFailDueToInvalidEmailTest_MakesSureOperationIsAbortedWhenEmailIsInvalid_VerifiesByExpectingException()
        {
            IUserApplicationService         userApplicationService         = (IUserApplicationService)_applicationContext["UserApplicationService"];
            IRegistrationApplicationService registrationApplicationService =
                (IRegistrationApplicationService)_applicationContext["RegistrationApplicationService"];

            ManualResetEvent manualResetEvent = new ManualResetEvent(false);
            string           username         = "******";
            string           email            = "*****@*****.**";
            string           activationKey    = registrationApplicationService.CreateAccount(new SignupUserCommand(email, username, "burnitdown", "USA", TimeZone.CurrentTimeZone, ""));

            userApplicationService.ActivateAccount(new ActivationCommand(activationKey, username, "burnitdown"));
            manualResetEvent.WaitOne(6000);

            userApplicationService.ForgotPassword(new ForgotPasswordCommand(email + "1", username));
        }
 public IHttpActionResult ForgotPassword([FromBody] ForgotPasswordParams forgotPasswordParams)
 {
     try
     {
         if (log.IsDebugEnabled)
         {
             log.Debug("ForgotPassword Call Recevied, parameters:" + forgotPasswordParams);
         }
         return
             (Ok(_userApplicationService.ForgotPassword(new ForgotPasswordCommand(forgotPasswordParams.Email,
                                                                                  forgotPasswordParams.Username))));
     }
     catch (InvalidOperationException exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("ForgotPassword Call Exception ", exception);
         }
         return(BadRequest(exception.Message));
     }
     catch (InvalidCredentialException exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("ForgotPassword Call Exception ", exception);
         }
         return(BadRequest(exception.Message));
     }
     catch (Exception exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("ForgotPassword Call Exception ", exception);
         }
         return(InternalServerError());
     }
 }
Ejemplo n.º 5
0
        public async Task <IActionResult> ForgotPassword([FromBody] ForgotUserPasswordCommand command)
        {
            await _userApplicationService.ForgotPassword(command);

            return(CreateResponse());
        }