Skip to content

Commit

Permalink
login fix
Browse files Browse the repository at this point in the history
  • Loading branch information
IdanShp committed Apr 19, 2020
1 parent 2a2bac0 commit 6db11e4
Showing 1 changed file with 69 additions and 65 deletions.
134 changes: 69 additions & 65 deletions src/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,71 @@ public Model() {

}
//##################################################################################################################################################
private static String addQuery(String TableName, String columns[], String data[]) {
String queryA = "INSERT INTO `" + TableName + "` (";
int i, j;
for (i = 0; i < columns.length - 1; i++) {
queryA += columns[i] + ", ";
}
queryA += columns[i] + ") VALUES (";
for (j = 0; j < data.length - 1; j++) {
queryA += "'"+ data[j] + "', ";
}
queryA += "'"+ data[i] + "'";
queryA += ")";
return queryA;
}
//##################################################################################################################################################
private static String editQuery(String TableName,String TableKey, String columns[], String data[], String index) {
String query = "UPDATE `" + TableName + "` SET ";
int i;
for (i = 0; i < data.length - 1; i++) {
query += columns[i] + " = '" + data[i] + "', ";
}
query += columns[i] + " = '" + data[i] + "'" + " WHERE " + TableName +"." + TableKey + " = " + index;
return query;
}
//##################################################################################################################################################
private String[] userToList(Users user) {
String[] data = {"", "", "", "", "", "", "", "", "", ""}; //{"last_name", "first_name", "user_name", "password", "email", "city", "address", "phone", "gender", "privileges"};
Object[] functions = {user.getLastName(), user.getFirstName(), user.getUserName(), user.getPassword(), user.getMail(), user.getCity(), user.getAddress(), user.getPhone(), user.getGender(), user.getPrivileges()};
for (int i = 0; i < data.length; i++) {
data[i] = (String) functions[i];
}
return data;
}
//##################################################################################################################################################
private String[] itemToList(Items item) {
String[] data = {"", "", "", "", "", "", ""}; //{"name", "owner", "category", "item_value", "item_condition", "description", "picture"};
Object[] functions = {item.getName(), item.getOwnerID(), item.getCategory(), item.getItemValue(), item.getCondition(), item.getDecription(), item.getPicture()};
for (int i = 0; i < data.length; i++) {
data[i] = (String) functions[i];
}
return data;
}
//##################################################################################################################################################
private String[] requestToList(Requests request) {
String[] data = {"", "", "", "", "", ""}; //{"itemID", "owner", "borrower", "period", "date", "response"};
Object[] functions = {request.getItemID(), request.getOwnerID(), request.getBorrowerID(), request.getPeriod(), request.getDate(), request.getResponse()};
for (int i = 0; i < data.length; i++) {
data[i] = (String) functions[i];
}
return data;
}
//##################################################################################################################################################
private double scoreByString(String search_query, String str) {
//System.out.println("***********item name is: " + name + "******************");
double score = 1;
String[] words = str.split(" ");
for (int i = 0; i < words.length; i++) {
System.out.println("word " + i + " distance is: " + dist(search_query, words[i]));
if (dist(search_query, words[i]) < score) {
score = dist(search_query, words[i]);
}
}
return score;
}
//##################################################################################################################################################
public List<Items> itemSearch(String search_query) { // main search
Items item = new Items();
String query = "SELECT * FROM items"; // get all data from database
Expand Down Expand Up @@ -92,18 +157,6 @@ public List<Items> smartSearch(String search_query) { // main search
return null;
}
}
private double scoreByString(String search_query, String str) {
//System.out.println("***********item name is: " + name + "******************");
double score = 1;
String[] words = str.split(" ");
for (int i = 0; i < words.length; i++) {
System.out.println("word " + i + " distance is: " + dist(search_query, words[i]));
if (dist(search_query, words[i]) < score) {
score = dist(search_query, words[i]);
}
}
return score;
}
//##################################################################################################################################################
public Users login(String user_name, String password) { // login function with check if user name already exists
Users user = new Users(); // create new empty user and assign data
Expand All @@ -117,7 +170,7 @@ public Users login(String user_name, String password) { // login function with c
user.setLastName(myRs.getString("last_name"));
user.setFirstName(myRs.getString("first_name"));
user.setUserName(myRs.getString("user_name"));
user.setPassword(null);
user.setPassword(myRs.getString("password"));
user.setMail(myRs.getString("email"));
user.setAddress(myRs.getString("address"));
user.setPhone(myRs.getString("phone"));
Expand Down Expand Up @@ -572,58 +625,6 @@ public List<Requests> getSentRequestsByUserID(String userID) {
}
}
//##################################################################################################################################################
private static String addQuery(String TableName, String columns[], String data[]) {
String queryA = "INSERT INTO `" + TableName + "` (";
int i, j;
for (i = 0; i < columns.length - 1; i++) {
queryA += columns[i] + ", ";
}
queryA += columns[i] + ") VALUES (";
for (j = 0; j < data.length - 1; j++) {
queryA += "'"+ data[j] + "', ";
}
queryA += "'"+ data[i] + "'";
queryA += ")";
return queryA;
}
//##################################################################################################################################################
private static String editQuery(String TableName,String TableKey, String columns[], String data[], String index) {
String query = "UPDATE `" + TableName + "` SET ";
int i;
for (i = 0; i < data.length - 1; i++) {
query += columns[i] + " = '" + data[i] + "', ";
}
query += columns[i] + " = '" + data[i] + "'" + " WHERE " + TableName +"." + TableKey + " = " + index;
return query;
}
//##################################################################################################################################################
private String[] userToList(Users user) {
String[] data = {"", "", "", "", "", "", "", "", "", ""}; //{"last_name", "first_name", "user_name", "password", "email", "city", "address", "phone", "gender", "privileges"};
Object[] functions = {user.getLastName(), user.getFirstName(), user.getUserName(), user.getPassword(), user.getMail(), user.getCity(), user.getAddress(), user.getPhone(), user.getGender(), user.getPrivileges()};
for (int i = 0; i < data.length; i++) {
data[i] = (String) functions[i];
}
return data;
}
//##################################################################################################################################################
private String[] itemToList(Items item) {
String[] data = {"", "", "", "", "", "", ""}; //{"name", "owner", "category", "item_value", "item_condition", "description", "picture"};
Object[] functions = {item.getName(), item.getOwnerID(), item.getCategory(), item.getItemValue(), item.getCondition(), item.getDecription(), item.getPicture()};
for (int i = 0; i < data.length; i++) {
data[i] = (String) functions[i];
}
return data;
}
//##################################################################################################################################################
private String[] requestToList(Requests request) {
String[] data = {"", "", "", "", "", ""}; //{"itemID", "owner", "borrower", "period", "date", "response"};
Object[] functions = {request.getItemID(), request.getOwnerID(), request.getBorrowerID(), request.getPeriod(), request.getDate(), request.getResponse()};
for (int i = 0; i < data.length; i++) {
data[i] = (String) functions[i];
}
return data;
}
//##################################################################################################################################################
public double dist(String stringA, String stringB) {

char[] s1 = stringToChars(stringA);
Expand Down Expand Up @@ -658,6 +659,7 @@ public double dist(String stringA, String stringB) {
double normal = ((double)prev[s2.length] / (double) Math.max(stringA.length(), stringB.length()));
return normal;
}
//##################################################################################################################################################
public char[] stringToChars(String str) {

// Creating array of string length
Expand All @@ -668,7 +670,9 @@ public char[] stringToChars(String str) {
}
return ch;
}
//##################################################################################################################################################
public void setGoodscore(double score) {
this.goodScore = score;
}
//##################################################################################################################################################
}

0 comments on commit 6db11e4

Please sign in to comment.