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

            ILoginApplicationService loginApplicationService = (ILoginApplicationService)_applicationContext["LoginApplicationService"];
            ISecurityKeysRepository  securityKeysRepository  = (ISecurityKeysRepository)_applicationContext["SecurityKeysPairRepository"];

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

            loginApplicationService.Login(new LoginCommand(username, password));

            bool accountActivated = userApplicationService.ActivateAccount(new ActivationCommand(activationKey, username, password));

            Assert.IsTrue(accountActivated);
            User userByUserName = userRepository.GetUserByUserName(username);

            Assert.IsNotNull(userByUserName);
            Assert.IsTrue(userByUserName.IsActivationKeyUsed.Value);

            UserValidationEssentials userValidationEssentials = loginApplicationService.Login(new LoginCommand(username, password));

            Assert.IsNotNull(userValidationEssentials);
            SecurityKeysPair securityKeysPair = securityKeysRepository.GetByApiKey(userValidationEssentials.ApiKey);

            Assert.IsNotNull(securityKeysPair);
            User receivedUser = userRepository.GetUserByUserName(username);

            Assert.IsTrue(receivedUser.IsActivationKeyUsed.Value);
        }
        public void LoginMfaAuthorizationTest_ChecksIfMfaAuthorizationIsDoneSuccessfully_VerifiesThroughReturnValue()
        {
            ILoginApplicationService   loginApplicationService   = (ILoginApplicationService)_applicationContext["LoginApplicationService"];
            ILogoutApplicationService  logoutApplicationService  = (ILogoutApplicationService)_applicationContext["LogoutApplicationService"];
            IMfaSubscriptionRepository mfaSubscriptionRepository = (IMfaSubscriptionRepository)_applicationContext["MfaSubscriptionRepository"];
            IMfaCodeGenerationService  mfaCodeGenerationService  = (IMfaCodeGenerationService)ContextRegistry.GetContext()["MfaCodeGenerationService"];

            Assert.IsNotNull(loginApplicationService);
            IRegistrationApplicationService registrationService = (IRegistrationApplicationService)_applicationContext["RegistrationApplicationService"];

            string username      = "******";
            string activationKey = registrationService.CreateAccount(new SignupUserCommand(
                                                                         "*****@*****.**", username, "alice", "Wonderland", TimeZone.CurrentTimeZone, ""));

            Assert.IsNotNull(activationKey);

            IUserApplicationService userApplicationService = (IUserApplicationService)_applicationContext["UserApplicationService"];
            bool accountActivated = userApplicationService.ActivateAccount(new ActivationCommand(activationKey, "Bob", "alice"));

            Assert.IsTrue(accountActivated);

            UserValidationEssentials userValidationEssentials = loginApplicationService.Login(new LoginCommand("Bob", "alice"));

            Assert.IsNotNull(userValidationEssentials);
            Assert.IsNotNull(userValidationEssentials.ApiKey);
            Assert.IsNotNull(userValidationEssentials.SecretKey);
            Assert.IsNotNull(userValidationEssentials.SessionLogoutTime);

            IList <MfaSubscription> allSubscriptions = mfaSubscriptionRepository.GetAllSubscriptions();
            List <Tuple <string, string, bool> > mfaSubscriptions = new List <Tuple <string, string, bool> >();

            foreach (var subscription in allSubscriptions)
            {
                mfaSubscriptions.Add(new Tuple <string, string, bool>(subscription.MfaSubscriptionId, subscription.MfaSubscriptionName,
                                                                      true));
            }
            SubmitMfaSettingsResponse submitMfaSettingsResponse = userApplicationService.SubmitMfaSettings(
                new MfaSettingsCommand(false, null, userValidationEssentials.ApiKey, mfaSubscriptions));

            Assert.IsTrue(submitMfaSettingsResponse.Successful);

            logoutApplicationService.Logout(new LogoutCommand(userValidationEssentials.ApiKey));

            UserValidationEssentials validationEssentials = loginApplicationService.Login(new LoginCommand("Bob", "alice", null));

            Assert.IsFalse(validationEssentials.LoginSuccessful);
            Assert.IsNull(validationEssentials.ApiKey);

            // As we are using the stub implementation for MfaCodeGenerationService, the service returns only the same code every
            // time. So we can use the code in this test case

            validationEssentials = loginApplicationService.Login(new LoginCommand("Bob", "alice", mfaCodeGenerationService.GenerateCode()));
            Assert.IsTrue(validationEssentials.LoginSuccessful);
            Assert.IsNotNull(validationEssentials.ApiKey);
            Assert.IsNotNull(validationEssentials.SecretKey);
        }
        public void LoginSuccessfulTest_TestsifTheLoginisSuccessfulAfterProvidingValidCredentials_VerifiesThroughThereturnedResult()
        {
            ILoginApplicationService loginApplicationService = (ILoginApplicationService)_applicationContext["LoginApplicationService"];

            Assert.IsNotNull(loginApplicationService);
            IRegistrationApplicationService registrationService = (IRegistrationApplicationService)_applicationContext["RegistrationApplicationService"];

            string username      = "******";
            string activationKey = registrationService.CreateAccount(new SignupUserCommand(
                                                                         "*****@*****.**", username, "alice", "Wonderland", TimeZone.CurrentTimeZone, ""));

            Assert.IsNotNull(activationKey);

            IUserApplicationService userApplicationService = (IUserApplicationService)_applicationContext["UserApplicationService"];
            bool accountActivated = userApplicationService.ActivateAccount(new ActivationCommand(activationKey, "Bob", "alice"));

            Assert.IsTrue(accountActivated);

            UserValidationEssentials userValidationEssentials = loginApplicationService.Login(new LoginCommand("Bob", "alice"));

            Assert.IsNotNull(userValidationEssentials);
            Assert.IsNotNull(userValidationEssentials.ApiKey);
            Assert.IsNotNull(userValidationEssentials.SecretKey);
            Assert.IsNotNull(userValidationEssentials.SessionLogoutTime);
        }
        public void ChangePasswordSuccessTest_ChecksIfThePasswordIsChangedSuccessfully_VerifiesThroughTheReturnedValue()
        {
            IUserApplicationService         userApplicationService         = (IUserApplicationService)_applicationContext["UserApplicationService"];
            IRegistrationApplicationService registrationApplicationService = (IRegistrationApplicationService)_applicationContext["RegistrationApplicationService"];
            ILoginApplicationService        loginApplicationService        = (ILoginApplicationService)_applicationContext["LoginApplicationService"];

            IUserRepository userRepository = (IUserRepository)_applicationContext["UserRepository"];

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

            userApplicationService.ActivateAccount(new ActivationCommand(activatioNKey, username, "burnitdown"));
            manualResetEvent.WaitOne(6000);
            UserValidationEssentials validationEssentials = loginApplicationService.Login(new LoginCommand(username, "burnitdown"));

            User   userBeforePasswordChange = userRepository.GetUserByUserName("linkinpark");
            string passwordBeforeChange     = userBeforePasswordChange.Password;

            ChangePasswordResponse changePasswordResponse = userApplicationService.ChangePassword(new ChangePasswordCommand(
                                                                                                      validationEssentials.ApiKey, "burnitdown", "burnitdowntwice"));

            Assert.IsTrue(changePasswordResponse.ChangeSuccessful);
            User   userAfterPasswordChange = userRepository.GetUserByUserName("linkinpark");
            string passwordAfterChange     = userAfterPasswordChange.Password;

            // Verify the old and new password do not match
            Assert.AreNotEqual(passwordBeforeChange, passwordAfterChange);
        }
        public void ChangePasswordFailDueWrongOldPassword_ChecksIfExceptionIsRaisedAfterCheckingOldPassword_VerifiesByExpectingException()
        {
            IUserApplicationService         userApplicationService         = (IUserApplicationService)_applicationContext["UserApplicationService"];
            IRegistrationApplicationService registrationApplicationService =
                (IRegistrationApplicationService)_applicationContext["RegistrationApplicationService"];
            ILoginApplicationService loginApplicationService =
                (ILoginApplicationService)_applicationContext["LoginApplicationService"];
            IIdentityAccessPersistenceRepository persistenceRepository =
                (IIdentityAccessPersistenceRepository)_applicationContext["IdentityAccessPersistenceRepository"];

            IUserRepository userRepository = (IUserRepository)_applicationContext["UserRepository"];

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

            userApplicationService.ActivateAccount(new ActivationCommand(activationKey, username, "burnitdown"));
            manualResetEvent.WaitOne(6000);
            UserValidationEssentials validationEssentials = loginApplicationService.Login(new LoginCommand(username, "burnitdown"));

            User   userBeforePasswordChange = userRepository.GetUserByUserName("linkinpark");
            string passwordBeforeChange     = userBeforePasswordChange.Password;
            User   userByUserName           = userRepository.GetUserByUserName(username);

            // When the User's Logout time and ValidationEssentials Logout time won't match, test will fail
            userByUserName.AutoLogout = new TimeSpan(0, 0, 0, 0, 1);
            persistenceRepository.SaveUpdate(userByUserName);
            // Give the wrong API Key
            userApplicationService.ChangePassword(new ChangePasswordCommand(validationEssentials.ApiKey, "123", "burnitdowntwice"));
            User   userAfterPasswordChange = userRepository.GetUserByUserName("linkinpark");
            string passwordAfterChange     = userAfterPasswordChange.Password;

            // Verify the old and new password do not match
            // Assert.AreEqual(passwordBeforeChange, passwordAfterChange);
        }
        public void ChangePasswordFailDueToInvalidApiKeyTest_ChecksIfExceptionIsRaisedAfterWrongApiKeyIsGiven_VerifiesByExpectingException()
        {
            IUserApplicationService         userApplicationService         = (IUserApplicationService)_applicationContext["UserApplicationService"];
            IRegistrationApplicationService registrationApplicationService =
                (IRegistrationApplicationService)_applicationContext["RegistrationApplicationService"];
            ILoginApplicationService loginApplicationService =
                (ILoginApplicationService)_applicationContext["LoginApplicationService"];

            IUserRepository userRepository = (IUserRepository)_applicationContext["UserRepository"];

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

            userApplicationService.ActivateAccount(new ActivationCommand(activationKey, username, "burnitdown"));
            manualResetEvent.WaitOne(6000);
            UserValidationEssentials validationEssentials = loginApplicationService.Login(new LoginCommand(username, "burnitdown"));

            User   userBeforePasswordChange = userRepository.GetUserByUserName("linkinpark");
            string passwordBeforeChange     = userBeforePasswordChange.Password;

            UserValidationEssentials validationEssentials2 = new UserValidationEssentials(new Tuple <ApiKey, SecretKey, DateTime>(
                                                                                              new ApiKey(validationEssentials.ApiKey + "1"), new SecretKey(validationEssentials.SecretKey), DateTime.Now), validationEssentials.SessionLogoutTime);

            // Give the wrong API Key
            userApplicationService.ChangePassword(new ChangePasswordCommand(validationEssentials.ApiKey + 1, "burnitdown", "burnitdowntwice"));
            User   userAfterPasswordChange = userRepository.GetUserByUserName("linkinpark");
            string passwordAfterChange     = userAfterPasswordChange.Password;

            // Verify the old and new password do not match
            Assert.AreEqual(passwordBeforeChange, passwordAfterChange);
        }
        public void ChangeSettingsSuccessfultTest_ChecksIfTheSettingsForUserChangeSuccessfulyAndValuesInDatabaseChange_VerifiesByReturnedValueAndDatabaseQuerying()
        {
            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 password      = "******";
            string activationKey = registrationApplicationService.CreateAccount(new SignupUserCommand(email, username, password, "USA", TimeZone.CurrentTimeZone, ""));

            User userByUserName = userRepository.GetUserByUserName(username);

            Assert.IsNotNull(userByUserName);
            Assert.AreEqual(email, userByUserName.Email);
            Assert.IsTrue(passwordEncryption.VerifyPassword(password, userByUserName.Password));
            Assert.AreEqual(Language.English, userByUserName.Language);
            Assert.AreEqual(TimeZone.CurrentTimeZone.StandardName, userByUserName.TimeZone.StandardName);
            Assert.AreEqual(new TimeSpan(0, 0, 10, 0), userByUserName.AutoLogout);
            Assert.IsNull(userByUserName.ForgotPasswordCode);
            Assert.IsNull(userByUserName.ForgotPasswordCodeExpiration);
            Assert.AreEqual(0, userByUserName.ForgottenPasswordCodes.Length);

            bool accountActivated = userApplicationService.ActivateAccount(new ActivationCommand(activationKey, username, password));

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

            manualResetEvent.WaitOne(6000);

            ILoginApplicationService loginApplicationService  = (ILoginApplicationService)_applicationContext["LoginApplicationService"];
            UserValidationEssentials userValidationEssentials = loginApplicationService.Login(new LoginCommand(username, password));

            Assert.IsNotNull(userValidationEssentials);
            Assert.IsNotNull(userValidationEssentials.ApiKey);
            Assert.IsNotNull(userValidationEssentials.SecretKey);
            Assert.IsNotNull(userValidationEssentials.SessionLogoutTime);

            string newEmail             = "*****@*****.**";
            var    resetPasswordReponse = userApplicationService.ChangeSettings(new ChangeSettingsCommand(
                                                                                    userValidationEssentials.ApiKey, newEmail, "", Language.Arabic, TimeZone.CurrentTimeZone, false, 67));

            Assert.IsTrue(resetPasswordReponse.ChangeSuccessful);

            userByUserName = userRepository.GetUserByUserName(username);
            Assert.IsNotNull(userByUserName);
            Assert.AreEqual(newEmail, userByUserName.Email);
            Assert.IsTrue(passwordEncryption.VerifyPassword(password, userByUserName.Password));
            Assert.AreEqual(Language.Arabic, userByUserName.Language);
            Assert.AreEqual(TimeZone.CurrentTimeZone.StandardName, userByUserName.TimeZone.StandardName);
            Assert.AreEqual(new TimeSpan(0, 0, 67, 0), userByUserName.AutoLogout);
            Assert.IsNull(userByUserName.ForgotPasswordCode);
            Assert.IsNull(userByUserName.ForgotPasswordCodeExpiration);
            Assert.AreEqual(0, userByUserName.ForgottenPasswordCodes.Length);
        }
        public void LogoutSuccessTest_TestsIfAUserGetsLogoutAsExpected_FailsIfDoesNot()
        {
            ILoginApplicationService loginApplicationService = (ILoginApplicationService)_applicationContext["LoginApplicationService"];

            Assert.IsNotNull(loginApplicationService);
            IRegistrationApplicationService registrationService = (IRegistrationApplicationService)_applicationContext["RegistrationApplicationService"];;

            // Register
            string username      = "******";
            string password      = "******";
            string activationKey = registrationService.CreateAccount(new SignupUserCommand(
                                                                         "*****@*****.**", username, password, "Wonderland", TimeZone.CurrentTimeZone, ""));

            Assert.IsNotNull(activationKey);

            IUserApplicationService userApplicationService = (IUserApplicationService)_applicationContext["UserApplicationService"];
            IUserRepository         userRepository         = (IUserRepository)_applicationContext["UserRepository"];

            // Activate account
            bool accountActivated = userApplicationService.ActivateAccount(new ActivationCommand(activationKey, username, password));

            Assert.IsTrue(accountActivated);
            User userByUserName = userRepository.GetUserByUserName(username);

            Assert.IsNotNull(userByUserName);
            Assert.IsTrue(userByUserName.IsActivationKeyUsed.Value);

            // Login
            UserValidationEssentials userValidationEssentials = loginApplicationService.Login(new LoginCommand(username, password));

            Assert.IsNotNull(userValidationEssentials);
            Assert.IsNotNull(userValidationEssentials.ApiKey);
            Assert.IsNotNull(userValidationEssentials.SecretKey);
            Assert.IsNotNull(userValidationEssentials.SessionLogoutTime);

            // Logout
            ILogoutApplicationService logoutApplicationService =
                (ILogoutApplicationService)_applicationContext["LogoutApplicationService"];

            Assert.IsNotNull(logoutApplicationService);
            bool logout = logoutApplicationService.Logout(new LogoutCommand(userValidationEssentials.ApiKey));

            Assert.IsTrue(logout);

            ISecurityKeysRepository securityKeysRepository = (ISecurityKeysRepository)_applicationContext["SecurityKeysPairRepository"];
            SecurityKeysPair        securityKeysPair       = securityKeysRepository.GetByApiKey(userValidationEssentials.ApiKey);

            Assert.IsNull(securityKeysPair);
        }
        public void ActivateAccountFailTest_ChecksIfUserCannotLoginUntilAccountIsNotActivated_VerifiesByExpectingException()
        {
            IRegistrationApplicationService registrationApplicationService =
                (IRegistrationApplicationService)_applicationContext["RegistrationApplicationService"];

            ILoginApplicationService loginApplicationService =
                (ILoginApplicationService)_applicationContext["LoginApplicationService"];

            string username = "******";
            string email    = "*****@*****.**";
            string password = "******";

            registrationApplicationService.CreateAccount(new SignupUserCommand(email, username, password, "USA", TimeZone.CurrentTimeZone, ""));

            loginApplicationService.Login(new LoginCommand(username, password));
        }
        public void LoginFailTest_TestsifTheLoginisFailsAfterProvidingBlankUsername_VerifiesThroughTheReturnedResult()
        {
            IUserApplicationService  userApplicationService  = (IUserApplicationService)_applicationContext["UserApplicationService"];
            ILoginApplicationService loginApplicationService = (ILoginApplicationService)_applicationContext["LoginApplicationService"];

            Assert.IsNotNull(loginApplicationService);
            IRegistrationApplicationService registrationService = (IRegistrationApplicationService)_applicationContext["RegistrationApplicationService"];;

            string activationKey = registrationService.CreateAccount(new SignupUserCommand(
                                                                         "*****@*****.**", "Bob", "alice", "Wonderland", TimeZone.CurrentTimeZone, ""));

            Assert.IsNotNull(activationKey);
            bool accountActivated = userApplicationService.ActivateAccount(new ActivationCommand(activationKey, "Bob", "alice"));

            Assert.IsTrue(accountActivated);
            loginApplicationService.Login(new LoginCommand("", "alice"));
        }
        public void LoginSuccessfulAndCheckSecurityKeysPairTest_ChecksIfAfterUserLoginSecurityPairsValuesAreAsExpected_ChecksByGettingSecurityKeysFromRepo()
        {
            ILoginApplicationService loginApplicationService = (ILoginApplicationService)_applicationContext["LoginApplicationService"];

            Assert.IsNotNull(loginApplicationService);
            IRegistrationApplicationService registrationService = (IRegistrationApplicationService)_applicationContext["RegistrationApplicationService"];
            IUserRepository         userRepository         = (IUserRepository)_applicationContext["UserRepository"];
            ISecurityKeysRepository securityKeysRepository = (ISecurityKeysRepository)_applicationContext["SecurityKeysPairRepository"];

            string username      = "******";
            string email         = "*****@*****.**";
            string password      = "******";
            string activationKey = registrationService.CreateAccount(new SignupUserCommand(
                                                                         email, username, password, "Wonderland", TimeZone.CurrentTimeZone, ""));

            Assert.IsNotNull(activationKey);

            IUserApplicationService userApplicationService = (IUserApplicationService)_applicationContext["UserApplicationService"];
            bool accountActivated = userApplicationService.ActivateAccount(new ActivationCommand(activationKey, "Bob", "alice"));

            Assert.IsTrue(accountActivated);

            UserValidationEssentials userValidationEssentials = loginApplicationService.Login(new LoginCommand(
                                                                                                  username, password));

            Assert.IsNotNull(userValidationEssentials);
            Assert.IsNotNull(userValidationEssentials.ApiKey);
            Assert.IsNotNull(userValidationEssentials.SecretKey);
            Assert.IsNotNull(userValidationEssentials.SessionLogoutTime);

            User user = userRepository.GetUserByUserName(username);

            Assert.IsNotNull(user);
            // Check that the user logged in this same minute and date, as we cannot check the seconds exactly
            Assert.AreEqual(user.LastLogin.Date, DateTime.Today.Date);
            Assert.AreEqual(user.LastLogin.Hour, DateTime.Now.Hour);
            Assert.AreEqual(user.LastLogin.Minute, DateTime.Now.Minute);
            Assert.AreEqual(userValidationEssentials.SessionLogoutTime, user.AutoLogout);

            SecurityKeysPair securityKeysPair = securityKeysRepository.GetByApiKey(userValidationEssentials.ApiKey);

            Assert.IsNotNull(securityKeysPair);
            Assert.AreEqual(userValidationEssentials.SecretKey, securityKeysPair.SecretKey);
        }
 public IHttpActionResult Login([FromBody] LoginParams param)
 {
     try
     {
         if (log.IsDebugEnabled)
         {
             log.Debug("Login Call Recevied, parameters:" + param);
         }
         return
             (Ok(_loginApplicationService.Login(new LoginCommand(param.UserName, param.Password, param.MfaCode))));
     }
     catch (InvalidOperationException exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("Login Call Exception ", exception);
         }
         return(BadRequest(exception.Message));
     }
     catch (InvalidCredentialException exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("Login Call Exception ", exception);
         }
         return(BadRequest(exception.Message));
     }
     catch (InvalidDataException exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("Login Call Exception ", exception);
         }
         return(BadRequest(exception.Message));
     }
     catch (Exception exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("Login Call Exception ", exception);
         }
         return(InternalServerError());
     }
 }
        public void GetLastLogin_IfTheApiKeyIsValid_LastLoginWillBeReturned()
        {
            IUserApplicationService         userApplicationService         = (IUserApplicationService)_applicationContext["UserApplicationService"];
            IRegistrationApplicationService registrationApplicationService = (IRegistrationApplicationService)_applicationContext["RegistrationApplicationService"];
            ILoginApplicationService        loginApplicationService        = (ILoginApplicationService)_applicationContext["LoginApplicationService"];

            IUserRepository userRepository = (IUserRepository)_applicationContext["UserRepository"];

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

            userApplicationService.ActivateAccount(new ActivationCommand(activatioNKey, username, "burnitdown"));
            manualResetEvent.WaitOne(6000);
            UserValidationEssentials validationEssentials = loginApplicationService.Login(new LoginCommand(username, "burnitdown"));

            DateTime LastLogin = userApplicationService.LastLogin(validationEssentials.ApiKey);

            Assert.AreEqual(LastLogin.ToString(), validationEssentials.LastLogin.ToString());
        }
        public void LoginSuccessfulTest_TestsifTheLoginisSuccessfulAfterProvidingValidCredentials_VerifiesByGettingUserFromRepositoryAndCheckingCredentials()
        {
            ILoginApplicationService loginApplicationService = (ILoginApplicationService)_applicationContext["LoginApplicationService"];

            Assert.IsNotNull(loginApplicationService);
            IRegistrationApplicationService registrationService  = (IRegistrationApplicationService)_applicationContext["RegistrationApplicationService"];
            IUserRepository            userRepository            = (IUserRepository)_applicationContext["UserRepository"];
            IPasswordEncryptionService passwordEncryptionService = (IPasswordEncryptionService)_applicationContext["PasswordEncryptionService"];
            string username      = "******";
            string email         = "*****@*****.**";
            string password      = "******";
            string activationKey = registrationService.CreateAccount(new SignupUserCommand(
                                                                         email, username, password, "Wonderland", TimeZone.CurrentTimeZone, ""));

            Assert.IsNotNull(activationKey);

            IUserApplicationService userApplicationService = (IUserApplicationService)_applicationContext["UserApplicationService"];
            bool accountActivated = userApplicationService.ActivateAccount(new ActivationCommand(activationKey, "Bob", "alice"));

            Assert.IsTrue(accountActivated);

            UserValidationEssentials userValidationEssentials = loginApplicationService.Login(new LoginCommand("Bob", "alice"));

            Assert.IsNotNull(userValidationEssentials);
            Assert.IsNotNull(userValidationEssentials.ApiKey);
            Assert.IsNotNull(userValidationEssentials.SecretKey);
            Assert.IsNotNull(userValidationEssentials.SessionLogoutTime);

            User user = userRepository.GetUserByUserName(username);

            Assert.IsNotNull(user);
            Assert.AreEqual(user.Email, email);
            Assert.AreEqual(user.ActivationKey, activationKey);
            Assert.AreEqual(userValidationEssentials.SessionLogoutTime, user.AutoLogout);
            Assert.IsTrue(passwordEncryptionService.VerifyPassword(password, user.Password));
        }
Esempio n. 15
0
        public async Task <IActionResult> Login(PersonDTO personDTO)
        {
            var  userDTO = Mapper.Map <UserDTO>(personDTO);
            bool isAuthed;

            try
            {
                isAuthed = await _loginApplicationService.Login(userDTO);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Auth API Error!");
                return(BadRequest(new { message = "Login Server Error, Please wait and retry!" }));
            }

            if (isAuthed)
            {
                return(Ok(new { message = "Login Success!" }));
            }
            else
            {
                return(BadRequest(new { message = "Login Failed!" }));
            }
        }