use of SQLDatabase.SQLDatabaseEntities.CustomersTable in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnection method getSecurityQuestionCustomer.
@Override
public String getSecurityQuestionCustomer(String username) throws CriticalError, ClientNotExist {
log.debug("SQL Public getSecurityQuestionCustomer: Customer: " + username + " get security question.");
if (!isCustomerExist(username)) {
log.debug("SQL Public getSecurityQuestionCustomer: no such customer with username: " + username);
throw new ClientNotExist();
}
try {
//Read part of transaction
String result = getSecurityQuestionForRegisteredClient(new CustomersTable(), username);
log.debug("SQL Public getSecurityQuestionCustomer: the security question of user: " + username + " is: \n" + result);
return result;
} catch (SQLDatabaseException e) {
throw e;
}
}
use of SQLDatabase.SQLDatabaseEntities.CustomersTable in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnection method verifySecurityAnswerCustomer.
@Override
public boolean verifySecurityAnswerCustomer(String username, String givenAnswer) throws CriticalError, ClientNotExist {
log.debug("SQL Public verifySecurityAnswerCustomer: Customer: " + username + " verify security answer.");
if (!isCustomerExist(username)) {
log.debug("SQL Public verifySecurityAnswerCustomer: no such customer with username: " + username);
throw new ClientNotExist();
}
try {
//Read part of transaction
boolean result = verifySecurityAnswerForRegisteredClient(new CustomersTable(), username, givenAnswer);
log.debug("SQL Public verifySecurityAnswerCustomer: result of verification for user: " + username + " is: " + result);
return result;
} catch (SQLDatabaseException e) {
throw e;
}
}
use of SQLDatabase.SQLDatabaseEntities.CustomersTable in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnection method loginAsCustomer.
/**
* login method for customer
*
* @param username
* @param password
* @return new sessionID for connection
* @throws AuthenticationError
* @throws ClientAlreadyConnected
* @throws CriticalError
* @throws NumberOfConnectionsExceeded
*/
private int loginAsCustomer(String username, String password) throws AuthenticationError, ClientAlreadyConnected, CriticalError, NumberOfConnectionsExceeded {
String query = generateSelectQuery1Table(CustomersTable.customertable, BinaryCondition.equalTo(CustomersTable.customerusernameCol, PARAM_MARK), BinaryCondition.equalTo(CustomersTable.customerpasswordCol, 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 customer already connected
if (isCustomerConnected(username))
throw new SQLDatabaseException.ClientAlreadyConnected();
/*
* EVERYTHING OK - initiate new session to customer and create new list for the customer
*/
int $ = generateSessionID();
assignSessionIDToRegisteredClient(new CustomersTable(), username, $);
initiateNewGroceryList($);
return $;
} catch (SQLException e) {
throw new CriticalError();
} finally {
closeResources(statement, result);
}
}
use of SQLDatabase.SQLDatabaseEntities.CustomersTable in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnection method removeCustomer.
@Override
public void removeCustomer(String username) throws CriticalError, ClientNotExist {
log.debug("SQL Public removeCustomer: Remove customer with username: " + username);
if (!isCustomerExist(username)) {
log.debug("SQL Public removeCustomer: no such customer with username: " + username);
throw new ClientNotExist();
}
try {
// START transaction
connectionStartTransaction();
//Read part of transaction
Integer customerSessionID = getSessionByUsernameOfRegisteredClient(new CustomersTable(), username);
//Write part of transaction
if (customerSessionID != null) {
log.debug("SQL Public removeCustomer: user " + username + " connected! doing logout first");
logoutAsCart(customerSessionID);
}
log.debug("SQL Public removeCustomer: remove user " + username + " from customers table and his ingredients");
setIngredientsForCustomer(username, new HashSet<>());
removeRegisteredClient(new CustomersTable(), username);
log.debug("SQL Public removeCustomer: Success removing username: " + username);
// END transaction
connectionCommitTransaction();
} catch (SQLDatabaseException e) {
log.debug("SQL Public removeCustomer: known error occured:" + e.getMessage());
connectionRollbackTransaction();
throw e;
} catch (SQLException e) {
log.fatal("SQL Public removeCustomer: SQL error occured:" + e.getMessage());
connectionRollbackTransaction();
throw new CriticalError();
} finally {
connectionEndTransaction();
}
}
use of SQLDatabase.SQLDatabaseEntities.CustomersTable in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnection method setSecurityQACustomer.
@Override
public void setSecurityQACustomer(String username, ForgotPasswordData d) throws CriticalError, ClientNotExist {
log.debug("SQL Public setSecurityQACustomer: Customer: " + username + " sets security Q&A.");
if (!isCustomerExist(username)) {
log.debug("SQL Public setSecurityQACustomer: no such customer with username: " + username);
throw new ClientNotExist();
}
try {
// START transaction
connectionStartTransaction();
//Write part of transaction
//updating security question and answer
assignSecurityQAToRegisteredClient(new CustomersTable(), username, d);
log.debug("SQL Public setSecurityQACustomer: Success setting ecurity Q&A for username: " + username);
// END transaction
connectionCommitTransaction();
} catch (SQLDatabaseException e) {
connectionRollbackTransaction();
throw e;
} finally {
connectionEndTransaction();
}
}
Aggregations