Search in sources :

Example 6 with ForgotPasswordData

use of BasicCommonClasses.ForgotPasswordData in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testCantAddWorkerAlreadyExisted.

@Test
public void testCantAddWorkerAlreadyExisted() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    String result = null;
    //test add worker
    try {
        sqlConnection.addWorker(null, new Login(workerName, workerName), new ForgotPasswordData("", ""));
        result = sqlConnection.getWorkersList(null);
    } catch (CriticalError | ClientNotConnected | ClientAlreadyExist e) {
        fail();
    }
    assert result != null;
    HashMap<String, Boolean> map = Serialization.deserializeWorkersHashMap(result);
    assert map != null;
    assert map.containsKey(workerName);
    assertEquals(false, map.get(workerName));
    //test add again the same worker
    try {
        sqlConnection.addWorker(null, new Login(workerName, workerName), new ForgotPasswordData("", ""));
        fail();
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    } catch (ClientAlreadyExist e) {
    }
    //remove worker
    try {
        sqlConnection.removeWorker(null, workerName);
        result = sqlConnection.getWorkersList(null);
    } catch (CriticalError | ClientNotConnected | ClientNotExist e) {
        fail();
    }
    assert result != null;
    map = Serialization.deserializeWorkersHashMap(result);
    assert map != null;
    assert !map.containsKey(workerName);
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) Login(BasicCommonClasses.Login) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) Test(org.junit.Test)

Example 7 with ForgotPasswordData

use of BasicCommonClasses.ForgotPasswordData in project SmartCity-Market by TechnionYP5777.

the class ForgotPasswordHandler method sendAnswerWithNewPassword.

public boolean sendAnswerWithNewPassword(String ans, String newPass) throws CriticalError, WrongAnswer, NoSuchUserName {
    CommandWrapper cmdwrppr = null;
    log.info("Creating 'send answer and password' command wrapper for username: " + username);
    ForgotPasswordData forgotPassData = new ForgotPasswordData(question, ans);
    Login ansAndPassContainer = new Login(username, newPass, forgotPassData);
    String serverResponse = sendRequestWithRespondToServer(new CommandWrapper(senderId, CommandDescriptor.FORGOT_PASSWORD_SEND_ANSWER_WITH_NEW_PASSWORD, Serialization.serialize(ansAndPassContainer)).serialize());
    cmdwrppr = getCommandWrapper(serverResponse);
    resultDescriptorHandler(cmdwrppr.getResultDescriptor());
    log.info("Successfully recovered forgotten password for username: " + username);
    return Serialization.deserialize(cmdwrppr.getData(), Boolean.class);
}
Also used : ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) CommandWrapper(ClientServerApi.CommandWrapper) Login(BasicCommonClasses.Login)

Example 8 with ForgotPasswordData

use of BasicCommonClasses.ForgotPasswordData in project SmartCity-Market by TechnionYP5777.

the class ForgotPasswordTest method sendCorrectAnswerWithNewPassword.

@Test
public void sendCorrectAnswerWithNewPassword() {
    ForgotPasswordData forgotPassData = new ForgotPasswordData(null, authQuestionAnswer);
    Login ansAndPassContainer = new Login(worker.getUsername(), newPass, forgotPassData);
    try {
        Mockito.when(clientRequestHandler.sendRequestWithRespond(new CommandWrapper(WorkerDefs.loginCommandSenderId, CommandDescriptor.FORGOT_PASSWORD_SEND_ANSWER_WITH_NEW_PASSWORD, Serialization.serialize(ansAndPassContainer)).serialize())).thenReturn(new CommandWrapper(ResultDescriptor.SM_OK, Serialization.serialize(true)).serialize());
    } catch (IOException ยข) {
        fail();
    }
    try {
        ((IForgotPasswordHandler) worker).sendAnswerAndNewPassword(authQuestionAnswer, newPass);
    } catch (NoSuchUserName | WrongAnswer e) {
        fail();
    }
}
Also used : WrongAnswer(UtilsImplementations.ForgotPasswordHandler.WrongAnswer) IForgotPasswordHandler(UtilsContracts.IForgotPasswordHandler) NoSuchUserName(UtilsImplementations.ForgotPasswordHandler.NoSuchUserName) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) CommandWrapper(ClientServerApi.CommandWrapper) Login(BasicCommonClasses.Login) IOException(java.io.IOException) Test(org.junit.Test)

Example 9 with ForgotPasswordData

use of BasicCommonClasses.ForgotPasswordData in project SmartCity-Market by TechnionYP5777.

the class ManageEmployeesTab method finishBtnPressed.

@FXML
void finishBtnPressed(ActionEvent __) {
    try {
        manager.registerNewWorker(new Login(userTxt.getText(), passTxt.getText(), new ForgotPasswordData(securityCombo.getSelectionModel().getSelectedItem(), securityAnswerTxt.getText())));
    } catch (InvalidParameter | CriticalError | EmployeeNotConnected | ConnectionFailure | WorkerAlreadyExists e) {
        log.fatal(e);
        log.debug(StackTraceUtil.getStackTrace(e));
        e.showInfoToUser();
    }
    createEmployeesList();
    enableRemoveButton();
}
Also used : InvalidParameter(EmployeeDefs.AEmployeeException.InvalidParameter) CriticalError(SMExceptions.CommonExceptions.CriticalError) ConnectionFailure(EmployeeDefs.AEmployeeException.ConnectionFailure) WorkerAlreadyExists(EmployeeDefs.AEmployeeException.WorkerAlreadyExists) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) Login(BasicCommonClasses.Login) EmployeeNotConnected(EmployeeDefs.AEmployeeException.EmployeeNotConnected) FXML(javafx.fxml.FXML)

Example 10 with ForgotPasswordData

use of BasicCommonClasses.ForgotPasswordData in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testCustomerCanSetProfile.

@Test
public void testCustomerCanSetProfile() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    CustomerProfile p = new CustomerProfile(customerName, customerName, "name", "last", "number", "email", "city", "street", date112000, new HashSet<>(), new ForgotPasswordData("question", "answer"));
    CustomerProfile result = null;
    try {
        sqlConnection.registerCustomer(customerName, customerName);
    } catch (CriticalError | ClientAlreadyExist e) {
        fail();
    }
    try {
        sqlConnection.setCustomerProfile(customerName, p);
        result = Serialization.deserialize(sqlConnection.getCustomerProfile(customerName), CustomerProfile.class);
    } catch (CriticalError | ClientNotExist | IngredientNotExist e1) {
        fail();
    } finally {
        try {
            sqlConnection.removeCustomer(customerName);
        } catch (CriticalError | ClientNotExist e) {
            e.printStackTrace();
        }
    }
    assertEquals(p.getBirthdate(), result.getBirthdate());
    assertEquals(p.getCity(), result.getCity());
    assertEquals(p.getEmailAddress(), result.getEmailAddress());
    assertEquals(p.getFirstName(), result.getFirstName());
    assertEquals(p.getLastName(), result.getLastName());
    assertEquals(p.getPhoneNumber(), result.getPhoneNumber());
    assertEquals(p.getStreet(), result.getStreet());
    assertEquals(p.getUserName(), result.getUserName());
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) CustomerProfile(BasicCommonClasses.CustomerProfile) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Aggregations

ForgotPasswordData (BasicCommonClasses.ForgotPasswordData)14 Test (org.junit.Test)11 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)9 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)9 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)9 Login (BasicCommonClasses.Login)8 ClientAlreadyExist (SQLDatabase.SQLDatabaseException.ClientAlreadyExist)6 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)4 CustomerProfile (BasicCommonClasses.CustomerProfile)3 CommandWrapper (ClientServerApi.CommandWrapper)3 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)2 IForgotPasswordHandler (UtilsContracts.IForgotPasswordHandler)2 NoSuchUserName (UtilsImplementations.ForgotPasswordHandler.NoSuchUserName)2 WrongAnswer (UtilsImplementations.ForgotPasswordHandler.WrongAnswer)2 IOException (java.io.IOException)2 FXML (javafx.fxml.FXML)2 ICustomerProfile (BasicCommonClasses.ICustomerProfile)1 ICustomer (CustomerContracts.ICustomer)1 ConnectionFailure (EmployeeDefs.AEmployeeException.ConnectionFailure)1 EmployeeNotConnected (EmployeeDefs.AEmployeeException.EmployeeNotConnected)1