von der Wiege bis zur Bahre, Kommentare, Kommentare
This commit is contained in:
@@ -14,13 +14,14 @@ import java.util.List;
|
||||
|
||||
public class AccountMgr {
|
||||
protected static double price = 5.0;
|
||||
|
||||
/**
|
||||
* creates a user with createUser(...) and adds its id to the 'worker' table
|
||||
* @param userData String[] name, firstname, password, email
|
||||
* @param addressData String[] street, number, plz, city
|
||||
* @return userid or -1
|
||||
*/
|
||||
public static long createWorker(String[] userData, String[] addressData){
|
||||
protected static long createWorker(String[] userData, String[] addressData){
|
||||
long id = createUser(userData, addressData);
|
||||
String sId = String.valueOf(id);
|
||||
Database.insert("worker", new String[]{"userid"}, new String[]{sId});
|
||||
@@ -33,7 +34,7 @@ public class AccountMgr {
|
||||
* @param addressData String[] street, number, plz, city
|
||||
* @return userid or -1
|
||||
*/
|
||||
public static long createParent(String[] userData, String[] addressData){
|
||||
protected static long createParent(String[] userData, String[] addressData){
|
||||
long id = createUser(userData, addressData);
|
||||
String sId = String.valueOf(id);
|
||||
Database.insert("parent", new String[]{"userid"}, new String[]{sId});
|
||||
@@ -46,7 +47,7 @@ public class AccountMgr {
|
||||
* @param addressData String[] street, number, plz, city
|
||||
* @return userid or -1
|
||||
*/
|
||||
private static long createUser(String[] userData, String[] addressData) {
|
||||
protected static long createUser(String[] userData, String[] addressData) {
|
||||
String[] addressH = {"street", "number", "plz", "city"};
|
||||
String[] userH = {"name", "firstname", "addressid", "password", "email"};
|
||||
String name = userData[0];
|
||||
@@ -61,7 +62,14 @@ public class AccountMgr {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static long createChild(String[] childData,String[] allergyData, String[] severityData){
|
||||
/**
|
||||
* adds a child and allergies to the database
|
||||
* @param childData name, firstname, addressid
|
||||
* @param allergyData id of allergies order matching with severityData
|
||||
* @param severityData id of severity order matching with allergyData
|
||||
* @return id of child or -1
|
||||
*/
|
||||
protected static long createChild(String[] childData,String[] allergyData, String[] severityData){
|
||||
String[] childH = {"name","firstname","addressid"};
|
||||
String[] child_allergyH = {"childid","allergyid","severityid"};
|
||||
long id = Database.insert("child", childH, childData);
|
||||
@@ -75,33 +83,60 @@ public class AccountMgr {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static long matchParentChild(String parentId, String childId){
|
||||
/**
|
||||
* creates entries in the database to match parent to child
|
||||
* @param parentId id of parent
|
||||
* @param childId id of child
|
||||
* @return id of parent_child or -1
|
||||
*/
|
||||
protected static long matchParentChild(String parentId, String childId){
|
||||
String[] parent_childH = {"parentuserid","childid"};
|
||||
String[] parent_childD = {parentId,childId};
|
||||
return Database.insert("parent_child", parent_childH,parent_childD);
|
||||
}
|
||||
|
||||
public static long login(String email, String pw){
|
||||
/**
|
||||
* a simple login to check if a given email matches a password
|
||||
* @param email email
|
||||
* @param pw password
|
||||
* @return id or -1
|
||||
*/
|
||||
protected static long login(String email, String pw){
|
||||
String[] userH = {"email","password"};
|
||||
String[] userD = {email,hashAndSalt(pw)};
|
||||
return Database.getSingleId("user",userH,userD);
|
||||
}
|
||||
|
||||
public static boolean isWorker(String id){
|
||||
/**
|
||||
* checks if id is in worker table
|
||||
* @param id userid
|
||||
* @return true if id is in worker table
|
||||
*/
|
||||
protected static boolean isWorker(String id){
|
||||
String[] workerH = {"userid"};
|
||||
String[] workerD = {id};
|
||||
long workerId = Database.getSingleId("worker",workerH,workerD);
|
||||
return workerId > 0;
|
||||
}
|
||||
|
||||
public static boolean isParent(String id){
|
||||
/**
|
||||
* checks if id is in parent table
|
||||
* @param id userid
|
||||
* @return true if id is in parent table
|
||||
*/
|
||||
protected static boolean isParent(String id){
|
||||
String[] parentH = {"userid"};
|
||||
String[] parentD = {id};
|
||||
long parentId = Database.getSingleId("parent",parentH,parentD);
|
||||
return parentId > 0;
|
||||
}
|
||||
|
||||
public static String hashAndSalt(String pw){
|
||||
/**
|
||||
* returns a hashed and salted password
|
||||
* @param pw the password to hash
|
||||
* @return hashed and salted password
|
||||
*/
|
||||
protected static String hashAndSalt(String pw){
|
||||
//todo: find a better way to salt
|
||||
byte[] magicSalt = new byte[]{96, 13, 100, 85, -37, 52, -123, 86, -123, -92, 16, 15, -110, -42, -49, 0};
|
||||
KeySpec spec = new PBEKeySpec(pw.toCharArray(), magicSalt,310001,256);
|
||||
@@ -117,7 +152,13 @@ public class AccountMgr {
|
||||
return hashedPw;
|
||||
}
|
||||
|
||||
public static List<String> getInvoice(String date, String childId){
|
||||
/**
|
||||
* gives the invoice for one month and one child
|
||||
* @param date YYYY-MM the month
|
||||
* @param childId id of child
|
||||
* @return the invoice as a List
|
||||
*/
|
||||
protected static List<String> getInvoice(String date, String childId){
|
||||
List<String> invoice = new ArrayList<>();
|
||||
invoice.add("Monatsabrechnung " + date);
|
||||
List<String> child = Database.getEntryById("child", Long.parseLong(childId));
|
||||
|
||||
Reference in New Issue
Block a user