Search in sources :

Example 1 with WorkersTable

use of SQLDatabase.SQLDatabaseEntities.WorkersTable in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnection method getSecurityQuestionWorker.

@Override
public String getSecurityQuestionWorker(String username) throws CriticalError, ClientNotExist {
    log.debug("SQL Public getSecurityQuestionWorker: Worker: " + username + " get security question.");
    if (!isWorkerExist(username)) {
        log.debug("SQL Public getSecurityQuestionWorker: no such worker with username: " + username);
        throw new ClientNotExist();
    }
    try {
        //Read part of transaction
        String result = getSecurityQuestionForRegisteredClient(new WorkersTable(), username);
        log.debug("SQL Public getSecurityQuestionWorker: the security question of user: " + username + " is: \n" + result);
        return result;
    } catch (SQLDatabaseException e) {
        throw e;
    }
}
Also used : WorkersTable(SQLDatabase.SQLDatabaseEntities.WorkersTable) SQLDatabaseException(SQLDatabase.SQLDatabaseException)

Example 2 with WorkersTable

use of SQLDatabase.SQLDatabaseEntities.WorkersTable in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnection method verifySecurityAnswerWorker.

@Override
public boolean verifySecurityAnswerWorker(String username, String givenAnswer) throws CriticalError, ClientNotExist {
    log.debug("SQL Public verifySecurityAnswerWorker: Worker: " + username + " verify security answer.");
    if (!isWorkerExist(username)) {
        log.debug("SQL Public verifySecurityAnswerWorker: no such worker with username: " + username);
        throw new ClientNotExist();
    }
    try {
        //Read part of transaction
        boolean result = verifySecurityAnswerForRegisteredClient(new WorkersTable(), username, givenAnswer);
        log.debug("SQL Public verifySecurityAnswerWorker: result of verification for user: " + username + " is: " + result);
        return result;
    } catch (SQLDatabaseException e) {
        throw e;
    }
}
Also used : WorkersTable(SQLDatabase.SQLDatabaseEntities.WorkersTable) SQLDatabaseException(SQLDatabase.SQLDatabaseException)

Example 3 with WorkersTable

use of SQLDatabase.SQLDatabaseEntities.WorkersTable in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnection method setPasswordWorker.

@Override
public void setPasswordWorker(String username, String newPassword) throws CriticalError, ClientNotExist {
    log.debug("SQL Public setPasswordWorker: Worker: " + username + " sets password.");
    if (!isWorkerExist(username)) {
        log.debug("SQL Public setPasswordWorker: no such worker with username: " + username);
        throw new ClientNotExist();
    }
    try {
        // START transaction
        connectionStartTransaction();
        //Write part of transaction
        //updating password
        assignPasswordToRegisteredClient(new WorkersTable(), username, newPassword);
        log.debug("SQL Public setPasswordWorker: Success setting password for username: " + username);
        // END transaction
        connectionCommitTransaction();
    } catch (SQLDatabaseException e) {
        connectionRollbackTransaction();
        throw e;
    } finally {
        connectionEndTransaction();
    }
}
Also used : WorkersTable(SQLDatabase.SQLDatabaseEntities.WorkersTable) SQLDatabaseException(SQLDatabase.SQLDatabaseException)

Example 4 with WorkersTable

use of SQLDatabase.SQLDatabaseEntities.WorkersTable in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnection method setSecurityQAWorker.

@Override
public void setSecurityQAWorker(String username, ForgotPasswordData d) throws CriticalError, ClientNotExist {
    log.debug("SQL Public setSecurityQAWorker: Worker: " + username + " sets security Q&A.");
    if (!isWorkerExist(username)) {
        log.debug("SQL Public setSecurityQAWorker: no such worker with username: " + username);
        throw new ClientNotExist();
    }
    try {
        // START transaction
        connectionStartTransaction();
        //Write part of transaction
        //updating security question and answer
        assignSecurityQAToRegisteredClient(new WorkersTable(), username, d);
        log.debug("SQL Public setSecurityQAWorker: Success setting ecurity Q&A for username: " + username);
        // END transaction
        connectionCommitTransaction();
    } catch (SQLDatabaseException e) {
        connectionRollbackTransaction();
        throw e;
    } finally {
        connectionEndTransaction();
    }
}
Also used : WorkersTable(SQLDatabase.SQLDatabaseEntities.WorkersTable) SQLDatabaseException(SQLDatabase.SQLDatabaseException)

Example 5 with WorkersTable

use of SQLDatabase.SQLDatabaseEntities.WorkersTable in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnection method loginAsWorker.

/**
	 * login method for worker/manager
	 * 
	 * @param username
	 * @param password
	 * @return new sessionID for connection
	 * @throws AuthenticationError
	 * @throws ClientAlreadyConnected
	 * @throws CriticalError
	 * @throws NumberOfConnectionsExceeded
	 */
private int loginAsWorker(String username, String password) throws AuthenticationError, ClientAlreadyConnected, CriticalError, NumberOfConnectionsExceeded {
    String query = generateSelectQuery1Table(WorkersTable.workertable, BinaryCondition.equalTo(WorkersTable.workerusernameCol, PARAM_MARK), BinaryCondition.equalTo(WorkersTable.workerpasswordCol, PARAM_MARK));
    PreparedStatement statement = getParameterizedQuery(query, username, password);
    ResultSet result = null;
    try {
        result = statement.executeQuery();
        // check if no results or more than one - throw exception user not exist
        if (getResultSetRowCount(result) != 1)
            throw new SQLDatabaseException.AuthenticationError();
        // check if worker already connected
        if (isWorkerConnected(username))
            throw new SQLDatabaseException.ClientAlreadyConnected();
        /*
			 * EVERYTHING OK - initiate new session to worker
			 */
        int $ = generateSessionID();
        assignSessionIDToRegisteredClient(new WorkersTable(), username, $);
        return $;
    } catch (SQLException e) {
        throw new CriticalError();
    } finally {
        closeResources(statement, result);
    }
}
Also used : SQLException(java.sql.SQLException) WorkersTable(SQLDatabase.SQLDatabaseEntities.WorkersTable) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLDatabaseException(SQLDatabase.SQLDatabaseException)

Aggregations

WorkersTable (SQLDatabase.SQLDatabaseEntities.WorkersTable)6 SQLDatabaseException (SQLDatabase.SQLDatabaseException)6 SQLException (java.sql.SQLException)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1