commit dc380ff73c204816ec1277b495fa91456ed4d21a Author: lu2019` <1Lovecoleman!> Date: Mon Jun 6 19:39:26 2022 -0700 removed test email server diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..3f70bec --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib.xml b/.idea/libraries/lib.xml new file mode 100644 index 0000000..fa8838a --- /dev/null +++ b/.idea/libraries/lib.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0e05be0 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..9f69b9a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Project_One_Server.iml b/Project_One_Server.iml new file mode 100644 index 0000000..be394e2 --- /dev/null +++ b/Project_One_Server.iml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/activation.jar b/lib/activation.jar new file mode 100644 index 0000000..5f37ea4 Binary files /dev/null and b/lib/activation.jar differ diff --git a/lib/javax.mail-1.6.2.jar b/lib/javax.mail-1.6.2.jar new file mode 100644 index 0000000..0cd0528 Binary files /dev/null and b/lib/javax.mail-1.6.2.jar differ diff --git a/out/production/Project_One/data/Email_Config.txt b/out/production/Project_One/data/Email_Config.txt new file mode 100644 index 0000000..3b07e82 --- /dev/null +++ b/out/production/Project_One/data/Email_Config.txt @@ -0,0 +1 @@ +smtp.zoho.com,cofan.tech,donotreply@cofan.tech,U9ppT6CH0hzW # Enter the server ip / hostname, domain name, username, password. respectively with ',' in between. No spaces \ No newline at end of file diff --git a/out/production/Project_One/data/EncryptionKeyFile b/out/production/Project_One/data/EncryptionKeyFile new file mode 100644 index 0000000..68a02ab Binary files /dev/null and b/out/production/Project_One/data/EncryptionKeyFile differ diff --git a/out/production/Project_One/data/Frames b/out/production/Project_One/data/Frames new file mode 100644 index 0000000..e69de29 diff --git a/out/production/Project_One/data/Networking_Config.txt b/out/production/Project_One/data/Networking_Config.txt new file mode 100644 index 0000000..3b8fb7e --- /dev/null +++ b/out/production/Project_One/data/Networking_Config.txt @@ -0,0 +1 @@ +localhost,11140 # Enter the server ip / hostname and port number with ',' in between. No spaces (In this case the server ip / hostname is not needed, insert a dummy hostname) \ No newline at end of file diff --git a/out/production/Project_One/data/Operators b/out/production/Project_One/data/Operators new file mode 100644 index 0000000..eabcc3b Binary files /dev/null and b/out/production/Project_One/data/Operators differ diff --git a/out/production/Project_One/data/Server_Private_Key b/out/production/Project_One/data/Server_Private_Key new file mode 100644 index 0000000..8ab9f3d Binary files /dev/null and b/out/production/Project_One/data/Server_Private_Key differ diff --git a/out/production/Project_One/data/Server_Public_Key b/out/production/Project_One/data/Server_Public_Key new file mode 100644 index 0000000..16dc261 Binary files /dev/null and b/out/production/Project_One/data/Server_Public_Key differ diff --git a/out/production/Project_One_Server/data/Email_Config.txt b/out/production/Project_One_Server/data/Email_Config.txt new file mode 100644 index 0000000..3b07e82 --- /dev/null +++ b/out/production/Project_One_Server/data/Email_Config.txt @@ -0,0 +1 @@ +smtp.zoho.com,cofan.tech,donotreply@cofan.tech,U9ppT6CH0hzW # Enter the server ip / hostname, domain name, username, password. respectively with ',' in between. No spaces \ No newline at end of file diff --git a/out/production/Project_One_Server/data/EncryptionKeyFile b/out/production/Project_One_Server/data/EncryptionKeyFile new file mode 100644 index 0000000..68a02ab Binary files /dev/null and b/out/production/Project_One_Server/data/EncryptionKeyFile differ diff --git a/out/production/Project_One_Server/data/Frames b/out/production/Project_One_Server/data/Frames new file mode 100644 index 0000000..e69de29 diff --git a/out/production/Project_One_Server/data/Networking_Config.txt b/out/production/Project_One_Server/data/Networking_Config.txt new file mode 100644 index 0000000..3b8fb7e --- /dev/null +++ b/out/production/Project_One_Server/data/Networking_Config.txt @@ -0,0 +1 @@ +localhost,11140 # Enter the server ip / hostname and port number with ',' in between. No spaces (In this case the server ip / hostname is not needed, insert a dummy hostname) \ No newline at end of file diff --git a/out/production/Project_One_Server/data/Operators b/out/production/Project_One_Server/data/Operators new file mode 100644 index 0000000..e442351 Binary files /dev/null and b/out/production/Project_One_Server/data/Operators differ diff --git a/out/production/Project_One_Server/data/Server_Private_Key b/out/production/Project_One_Server/data/Server_Private_Key new file mode 100644 index 0000000..8ab9f3d Binary files /dev/null and b/out/production/Project_One_Server/data/Server_Private_Key differ diff --git a/out/production/Project_One_Server/data/Server_Public_Key b/out/production/Project_One_Server/data/Server_Public_Key new file mode 100644 index 0000000..16dc261 Binary files /dev/null and b/out/production/Project_One_Server/data/Server_Public_Key differ diff --git a/out/production/Project_One_Server/main/Hashing.class b/out/production/Project_One_Server/main/Hashing.class new file mode 100644 index 0000000..f623747 Binary files /dev/null and b/out/production/Project_One_Server/main/Hashing.class differ diff --git a/out/production/Project_One_Server/main/Login_Profile.class b/out/production/Project_One_Server/main/Login_Profile.class new file mode 100644 index 0000000..399e07a Binary files /dev/null and b/out/production/Project_One_Server/main/Login_Profile.class differ diff --git a/out/production/Project_One_Server/main/Operator.class b/out/production/Project_One_Server/main/Operator.class new file mode 100644 index 0000000..931cb0a Binary files /dev/null and b/out/production/Project_One_Server/main/Operator.class differ diff --git a/out/production/Project_One_Server/main/Operator_Profile.class b/out/production/Project_One_Server/main/Operator_Profile.class new file mode 100644 index 0000000..8397cce Binary files /dev/null and b/out/production/Project_One_Server/main/Operator_Profile.class differ diff --git a/out/production/Project_One_Server/main/Operators.class b/out/production/Project_One_Server/main/Operators.class new file mode 100644 index 0000000..d4fc8a3 Binary files /dev/null and b/out/production/Project_One_Server/main/Operators.class differ diff --git a/out/production/Project_One_Server/main/Operators_Login_Control.class b/out/production/Project_One_Server/main/Operators_Login_Control.class new file mode 100644 index 0000000..462fad6 Binary files /dev/null and b/out/production/Project_One_Server/main/Operators_Login_Control.class differ diff --git a/out/production/Project_One_Server/main/Reset_Password_Count_Down.class b/out/production/Project_One_Server/main/Reset_Password_Count_Down.class new file mode 100644 index 0000000..ac15f15 Binary files /dev/null and b/out/production/Project_One_Server/main/Reset_Password_Count_Down.class differ diff --git a/out/production/Project_One_Server/main/Server_Main.class b/out/production/Project_One_Server/main/Server_Main.class new file mode 100644 index 0000000..56e3c74 Binary files /dev/null and b/out/production/Project_One_Server/main/Server_Main.class differ diff --git a/out/production/Project_One_Server/main/config/Communication_Rules.class b/out/production/Project_One_Server/main/config/Communication_Rules.class new file mode 100644 index 0000000..b2d089c Binary files /dev/null and b/out/production/Project_One_Server/main/config/Communication_Rules.class differ diff --git a/out/production/Project_One_Server/main/config/File_Path.class b/out/production/Project_One_Server/main/config/File_Path.class new file mode 100644 index 0000000..efe2ce7 Binary files /dev/null and b/out/production/Project_One_Server/main/config/File_Path.class differ diff --git a/out/production/Project_One_Server/main/config/requests/Check_Logged_In_Request.class b/out/production/Project_One_Server/main/config/requests/Check_Logged_In_Request.class new file mode 100644 index 0000000..27f830c Binary files /dev/null and b/out/production/Project_One_Server/main/config/requests/Check_Logged_In_Request.class differ diff --git a/out/production/Project_One_Server/main/config/requests/Get_Customer_Request.class b/out/production/Project_One_Server/main/config/requests/Get_Customer_Request.class new file mode 100644 index 0000000..42ab873 Binary files /dev/null and b/out/production/Project_One_Server/main/config/requests/Get_Customer_Request.class differ diff --git a/out/production/Project_One_Server/main/config/requests/LogIn_Request.class b/out/production/Project_One_Server/main/config/requests/LogIn_Request.class new file mode 100644 index 0000000..3e5dd6f Binary files /dev/null and b/out/production/Project_One_Server/main/config/requests/LogIn_Request.class differ diff --git a/out/production/Project_One_Server/main/config/requests/Log_Out_Request.class b/out/production/Project_One_Server/main/config/requests/Log_Out_Request.class new file mode 100644 index 0000000..932b756 Binary files /dev/null and b/out/production/Project_One_Server/main/config/requests/Log_Out_Request.class differ diff --git a/out/production/Project_One_Server/main/config/requests/Reset_Password_Request.class b/out/production/Project_One_Server/main/config/requests/Reset_Password_Request.class new file mode 100644 index 0000000..5c18152 Binary files /dev/null and b/out/production/Project_One_Server/main/config/requests/Reset_Password_Request.class differ diff --git a/out/production/Project_One_Server/main/config/requests/Search_Customer_Request.class b/out/production/Project_One_Server/main/config/requests/Search_Customer_Request.class new file mode 100644 index 0000000..1f017f2 Binary files /dev/null and b/out/production/Project_One_Server/main/config/requests/Search_Customer_Request.class differ diff --git a/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Add_Operator_Request.class b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Add_Operator_Request.class new file mode 100644 index 0000000..2f481dc Binary files /dev/null and b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Add_Operator_Request.class differ diff --git a/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Birthday_Request.class b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Birthday_Request.class new file mode 100644 index 0000000..02b56a6 Binary files /dev/null and b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Birthday_Request.class differ diff --git a/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Email_Request.class b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Email_Request.class new file mode 100644 index 0000000..a0008d7 Binary files /dev/null and b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Email_Request.class differ diff --git a/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Name_Request.class b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Name_Request.class new file mode 100644 index 0000000..f876766 Binary files /dev/null and b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Name_Request.class differ diff --git a/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Password_Request.class b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Password_Request.class new file mode 100644 index 0000000..1a27bc8 Binary files /dev/null and b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Password_Request.class differ diff --git a/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Phone_Request.class b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Phone_Request.class new file mode 100644 index 0000000..6db3ce6 Binary files /dev/null and b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Phone_Request.class differ diff --git a/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Profile_Request.class b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Profile_Request.class new file mode 100644 index 0000000..60f67ad Binary files /dev/null and b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Profile_Request.class differ diff --git a/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Secure_Level_Request.class b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Secure_Level_Request.class new file mode 100644 index 0000000..0487e15 Binary files /dev/null and b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Secure_Level_Request.class differ diff --git a/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Username_Request.class b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Username_Request.class new file mode 100644 index 0000000..98617ce Binary files /dev/null and b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Change_Username_Request.class differ diff --git a/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Delete_Operator_Request.class b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Delete_Operator_Request.class new file mode 100644 index 0000000..aea7c08 Binary files /dev/null and b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Delete_Operator_Request.class differ diff --git a/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Get_Operator_Profiles_Request.class b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Get_Operator_Profiles_Request.class new file mode 100644 index 0000000..6b3d118 Binary files /dev/null and b/out/production/Project_One_Server/main/config/requests/operator_profile_requests/Get_Operator_Profiles_Request.class differ diff --git a/out/production/Project_One_Server/main/customer/Common_Rule.class b/out/production/Project_One_Server/main/customer/Common_Rule.class new file mode 100644 index 0000000..f743672 Binary files /dev/null and b/out/production/Project_One_Server/main/customer/Common_Rule.class differ diff --git a/out/production/Project_One_Server/main/customer/Customer.class b/out/production/Project_One_Server/main/customer/Customer.class new file mode 100644 index 0000000..32a4d55 Binary files /dev/null and b/out/production/Project_One_Server/main/customer/Customer.class differ diff --git a/out/production/Project_One_Server/main/customer/Customer_Profile.class b/out/production/Project_One_Server/main/customer/Customer_Profile.class new file mode 100644 index 0000000..36de489 Binary files /dev/null and b/out/production/Project_One_Server/main/customer/Customer_Profile.class differ diff --git a/out/production/Project_One_Server/main/customer/Customers.class b/out/production/Project_One_Server/main/customer/Customers.class new file mode 100644 index 0000000..5f52e29 Binary files /dev/null and b/out/production/Project_One_Server/main/customer/Customers.class differ diff --git a/out/production/Project_One_Server/main/customer/Default_Customer.class b/out/production/Project_One_Server/main/customer/Default_Customer.class new file mode 100644 index 0000000..d43255f Binary files /dev/null and b/out/production/Project_One_Server/main/customer/Default_Customer.class differ diff --git a/out/production/Project_One_Server/main/exception/AccessDeniedException.class b/out/production/Project_One_Server/main/exception/AccessDeniedException.class new file mode 100644 index 0000000..a6c6e64 Binary files /dev/null and b/out/production/Project_One_Server/main/exception/AccessDeniedException.class differ diff --git a/out/production/Project_One_Server/main/exception/Account_Does_Not_Exit_Exception.class b/out/production/Project_One_Server/main/exception/Account_Does_Not_Exit_Exception.class new file mode 100644 index 0000000..2faa4bd Binary files /dev/null and b/out/production/Project_One_Server/main/exception/Account_Does_Not_Exit_Exception.class differ diff --git a/out/production/Project_One_Server/main/exception/Card_Number_Taken_Exception.class b/out/production/Project_One_Server/main/exception/Card_Number_Taken_Exception.class new file mode 100644 index 0000000..1c10c69 Binary files /dev/null and b/out/production/Project_One_Server/main/exception/Card_Number_Taken_Exception.class differ diff --git a/out/production/Project_One_Server/main/exception/Customer_Does_Not_Exit_Exception.class b/out/production/Project_One_Server/main/exception/Customer_Does_Not_Exit_Exception.class new file mode 100644 index 0000000..5553d79 Binary files /dev/null and b/out/production/Project_One_Server/main/exception/Customer_Does_Not_Exit_Exception.class differ diff --git a/out/production/Project_One_Server/main/exception/DataNotFoundException.class b/out/production/Project_One_Server/main/exception/DataNotFoundException.class new file mode 100644 index 0000000..e30cf7d Binary files /dev/null and b/out/production/Project_One_Server/main/exception/DataNotFoundException.class differ diff --git a/out/production/Project_One_Server/main/exception/Email_Does_Not_Exist_Exception.class b/out/production/Project_One_Server/main/exception/Email_Does_Not_Exist_Exception.class new file mode 100644 index 0000000..0ac4220 Binary files /dev/null and b/out/production/Project_One_Server/main/exception/Email_Does_Not_Exist_Exception.class differ diff --git a/out/production/Project_One_Server/main/exception/IncorrectPasswordException.class b/out/production/Project_One_Server/main/exception/IncorrectPasswordException.class new file mode 100644 index 0000000..87312ab Binary files /dev/null and b/out/production/Project_One_Server/main/exception/IncorrectPasswordException.class differ diff --git a/out/production/Project_One_Server/main/exception/ItemNotFoundException.class b/out/production/Project_One_Server/main/exception/ItemNotFoundException.class new file mode 100644 index 0000000..eba2de5 Binary files /dev/null and b/out/production/Project_One_Server/main/exception/ItemNotFoundException.class differ diff --git a/out/production/Project_One_Server/main/exception/Item_Does_Not_Exit_Exception.class b/out/production/Project_One_Server/main/exception/Item_Does_Not_Exit_Exception.class new file mode 100644 index 0000000..ba3ccd2 Binary files /dev/null and b/out/production/Project_One_Server/main/exception/Item_Does_Not_Exit_Exception.class differ diff --git a/out/production/Project_One_Server/main/exception/UsernameTakenException.class b/out/production/Project_One_Server/main/exception/UsernameTakenException.class new file mode 100644 index 0000000..bdd507d Binary files /dev/null and b/out/production/Project_One_Server/main/exception/UsernameTakenException.class differ diff --git a/out/production/Project_One_Server/main/request_handler/Check_Logged_In_Request_Handler.class b/out/production/Project_One_Server/main/request_handler/Check_Logged_In_Request_Handler.class new file mode 100644 index 0000000..0d54735 Binary files /dev/null and b/out/production/Project_One_Server/main/request_handler/Check_Logged_In_Request_Handler.class differ diff --git a/out/production/Project_One_Server/main/request_handler/Client_Handler.class b/out/production/Project_One_Server/main/request_handler/Client_Handler.class new file mode 100644 index 0000000..ebb7bfa Binary files /dev/null and b/out/production/Project_One_Server/main/request_handler/Client_Handler.class differ diff --git a/out/production/Project_One_Server/main/request_handler/LogOut_Handler.class b/out/production/Project_One_Server/main/request_handler/LogOut_Handler.class new file mode 100644 index 0000000..397feee Binary files /dev/null and b/out/production/Project_One_Server/main/request_handler/LogOut_Handler.class differ diff --git a/out/production/Project_One_Server/main/request_handler/Login_Handler.class b/out/production/Project_One_Server/main/request_handler/Login_Handler.class new file mode 100644 index 0000000..fe18c79 Binary files /dev/null and b/out/production/Project_One_Server/main/request_handler/Login_Handler.class differ diff --git a/out/production/Project_One_Server/main/request_handler/Password_Reset_Verification_Code_Handler.class b/out/production/Project_One_Server/main/request_handler/Password_Reset_Verification_Code_Handler.class new file mode 100644 index 0000000..3c15fa7 Binary files /dev/null and b/out/production/Project_One_Server/main/request_handler/Password_Reset_Verification_Code_Handler.class differ diff --git a/out/production/Project_One_Server/main/request_handler/Password_Reset_Verification_Code_Manager.class b/out/production/Project_One_Server/main/request_handler/Password_Reset_Verification_Code_Manager.class new file mode 100644 index 0000000..3a5ce93 Binary files /dev/null and b/out/production/Project_One_Server/main/request_handler/Password_Reset_Verification_Code_Manager.class differ diff --git a/out/production/Project_One_Server/main/request_handler/Password_Verification_Handler.class b/out/production/Project_One_Server/main/request_handler/Password_Verification_Handler.class new file mode 100644 index 0000000..1ebb83d Binary files /dev/null and b/out/production/Project_One_Server/main/request_handler/Password_Verification_Handler.class differ diff --git a/out/production/Project_One_Server/main/request_handler/Reset_Password_Handler.class b/out/production/Project_One_Server/main/request_handler/Reset_Password_Handler.class new file mode 100644 index 0000000..b0db7fe Binary files /dev/null and b/out/production/Project_One_Server/main/request_handler/Reset_Password_Handler.class differ diff --git a/out/production/Project_One_Server/main/request_handler/customer_request_handler/Get_Customer_Request_handler.class b/out/production/Project_One_Server/main/request_handler/customer_request_handler/Get_Customer_Request_handler.class new file mode 100644 index 0000000..2bb3e0f Binary files /dev/null and b/out/production/Project_One_Server/main/request_handler/customer_request_handler/Get_Customer_Request_handler.class differ diff --git a/out/production/Project_One_Server/main/request_handler/customer_request_handler/Search_Customer_Request_handler.class b/out/production/Project_One_Server/main/request_handler/customer_request_handler/Search_Customer_Request_handler.class new file mode 100644 index 0000000..9b2ba00 Binary files /dev/null and b/out/production/Project_One_Server/main/request_handler/customer_request_handler/Search_Customer_Request_handler.class differ diff --git a/out/production/Project_One_Server/main/request_handler/operator_profile_request_handler/Add_Operator_Handler.class b/out/production/Project_One_Server/main/request_handler/operator_profile_request_handler/Add_Operator_Handler.class new file mode 100644 index 0000000..f02cc9a Binary files /dev/null and b/out/production/Project_One_Server/main/request_handler/operator_profile_request_handler/Add_Operator_Handler.class differ diff --git a/out/production/Project_One_Server/main/request_handler/operator_profile_request_handler/Change_Profile_Handler.class b/out/production/Project_One_Server/main/request_handler/operator_profile_request_handler/Change_Profile_Handler.class new file mode 100644 index 0000000..26afe74 Binary files /dev/null and b/out/production/Project_One_Server/main/request_handler/operator_profile_request_handler/Change_Profile_Handler.class differ diff --git a/out/production/Project_One_Server/main/request_handler/operator_profile_request_handler/Delete_Operator_Handler.class b/out/production/Project_One_Server/main/request_handler/operator_profile_request_handler/Delete_Operator_Handler.class new file mode 100644 index 0000000..7042c1f Binary files /dev/null and b/out/production/Project_One_Server/main/request_handler/operator_profile_request_handler/Delete_Operator_Handler.class differ diff --git a/out/production/Project_One_Server/main/request_handler/operator_profile_request_handler/Get_Operator_Profiles_Handler.class b/out/production/Project_One_Server/main/request_handler/operator_profile_request_handler/Get_Operator_Profiles_Handler.class new file mode 100644 index 0000000..a839bb7 Binary files /dev/null and b/out/production/Project_One_Server/main/request_handler/operator_profile_request_handler/Get_Operator_Profiles_Handler.class differ diff --git a/out/production/Project_One_Server/main/ui/Server_Command_Line_Handler.class b/out/production/Project_One_Server/main/ui/Server_Command_Line_Handler.class new file mode 100644 index 0000000..abdefb7 Binary files /dev/null and b/out/production/Project_One_Server/main/ui/Server_Command_Line_Handler.class differ diff --git a/out/production/Project_One_Server/main/utility/EmailSender$1.class b/out/production/Project_One_Server/main/utility/EmailSender$1.class new file mode 100644 index 0000000..042eb17 Binary files /dev/null and b/out/production/Project_One_Server/main/utility/EmailSender$1.class differ diff --git a/out/production/Project_One_Server/main/utility/EmailSender.class b/out/production/Project_One_Server/main/utility/EmailSender.class new file mode 100644 index 0000000..7e126ca Binary files /dev/null and b/out/production/Project_One_Server/main/utility/EmailSender.class differ diff --git a/out/production/Project_One_Server/main/utility/Networking_Config.class b/out/production/Project_One_Server/main/utility/Networking_Config.class new file mode 100644 index 0000000..08297a3 Binary files /dev/null and b/out/production/Project_One_Server/main/utility/Networking_Config.class differ diff --git a/out/production/Project_One_Server/main/utility/Random_String_Generator.class b/out/production/Project_One_Server/main/utility/Random_String_Generator.class new file mode 100644 index 0000000..38e1696 Binary files /dev/null and b/out/production/Project_One_Server/main/utility/Random_String_Generator.class differ diff --git a/src/data/Email_Config.txt b/src/data/Email_Config.txt new file mode 100644 index 0000000..3b07e82 --- /dev/null +++ b/src/data/Email_Config.txt @@ -0,0 +1 @@ +smtp.zoho.com,cofan.tech,donotreply@cofan.tech,U9ppT6CH0hzW # Enter the server ip / hostname, domain name, username, password. respectively with ',' in between. No spaces \ No newline at end of file diff --git a/src/data/EncryptionKeyFile b/src/data/EncryptionKeyFile new file mode 100644 index 0000000..68a02ab Binary files /dev/null and b/src/data/EncryptionKeyFile differ diff --git a/src/data/Frames b/src/data/Frames new file mode 100644 index 0000000..e69de29 diff --git a/src/data/Networking_Config.txt b/src/data/Networking_Config.txt new file mode 100644 index 0000000..3b8fb7e --- /dev/null +++ b/src/data/Networking_Config.txt @@ -0,0 +1 @@ +localhost,11140 # Enter the server ip / hostname and port number with ',' in between. No spaces (In this case the server ip / hostname is not needed, insert a dummy hostname) \ No newline at end of file diff --git a/src/data/Operators b/src/data/Operators new file mode 100644 index 0000000..bd4eaa4 Binary files /dev/null and b/src/data/Operators differ diff --git a/src/data/Server_Private_Key b/src/data/Server_Private_Key new file mode 100644 index 0000000..8ab9f3d Binary files /dev/null and b/src/data/Server_Private_Key differ diff --git a/src/data/Server_Public_Key b/src/data/Server_Public_Key new file mode 100644 index 0000000..16dc261 Binary files /dev/null and b/src/data/Server_Public_Key differ diff --git a/src/main/Hashing.java b/src/main/Hashing.java new file mode 100644 index 0000000..66f2e68 --- /dev/null +++ b/src/main/Hashing.java @@ -0,0 +1,24 @@ +package main; + + +import main.utility.Random_String_Generator; + +import java.util.Base64; + +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class Hashing { + public static String hash (String original) { + final MessageDigest digest; + try { + digest = MessageDigest.getInstance("SHA-256"); + byte[] hash = digest.digest(original.getBytes(StandardCharsets.UTF_8)); + return new String (Base64.getEncoder().encodeToString(hash)); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + return Random_String_Generator.get_random_string(12); + } + } +} diff --git a/src/main/Login_Profile.java b/src/main/Login_Profile.java new file mode 100644 index 0000000..b195f7d --- /dev/null +++ b/src/main/Login_Profile.java @@ -0,0 +1,52 @@ +package main; + +import java.security.PublicKey; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +public class Login_Profile { + private Operator operator; + private String login_session_key_string; + private String verification_key_string; + private boolean verification_key_valid; + private ReadWriteLock lock; + + public Login_Profile(Operator operator,String login_session_key_string) { + this.operator = operator; + this.login_session_key_string = login_session_key_string; + this.verification_key_string = ""; + this.verification_key_valid = false; + this.lock = new ReentrantReadWriteLock(); + } + + public Operator get_operator() { + return this.operator; + } + + public String get_login_session_key_string() { + return this.login_session_key_string; + } + + public void set_verification_key(String verification_key_string) { + try { + lock.writeLock().lock(); + this.verification_key_string = verification_key_string; + this.verification_key_valid = true; + } finally { + lock.writeLock().unlock(); + } + } + + public boolean check_verification_key(String verification_key_string) { + try { + lock.writeLock().lock(); + if (this.verification_key_valid && this.verification_key_string.equals(verification_key_string)) { + this.verification_key_valid = false; + return true; + } + return false; + } finally { + lock.writeLock().unlock(); + } + } +} diff --git a/src/main/Operator.java b/src/main/Operator.java new file mode 100644 index 0000000..4f755f8 --- /dev/null +++ b/src/main/Operator.java @@ -0,0 +1,90 @@ +package main; + + +import java.io.Serializable; + +public class Operator extends Operator_Profile implements Serializable { + private String hashed_password; + + public Operator(String name, String username, String password, int secure_level, String email, String phone, String birthday) { + super(name,username,secure_level,email,phone, birthday); + this.hashed_password = Hashing.hash(password); + } + + public void set_name(String name) { + try { + this.lock.writeLock().lock(); + this.name = name; + } finally { + this.lock.writeLock().unlock(); + } + } + + public void set_username(String username) { + try { + this.lock.writeLock().lock(); + this.username = username; + } finally { + this.lock.writeLock().unlock(); + } + } + + public void set_password(String password) { + try { + this.lock.writeLock().lock(); + this.hashed_password = Hashing.hash(password); + } finally { + this.lock.writeLock().unlock(); + } + } + + public void set_secure_level(int new_level) { + try { + this.lock.writeLock().lock(); + secure_level = new_level; + } finally { + this.lock.writeLock().unlock(); + } + } + + public void set_email(String email) { + try { + this.lock.writeLock().lock(); + this.email = email; + } finally { + this.lock.writeLock().unlock(); + } + } + + public void set_phone(String phone) { + try { + this.lock.writeLock().lock(); + this.phone = phone; + } finally { + this.lock.writeLock().unlock(); + } + } + + public void set_birthday(String birthday) { + try { + this.lock.writeLock().lock(); + this.birthday = birthday; + } finally { + this.lock.writeLock().unlock(); + } + } + + public boolean check_password(String input) { + try { + String hashed_input = Hashing.hash(input); + this.lock.readLock().lock(); + if (hashed_input.equals(this.hashed_password)) + return true; + else + return false; + } finally { + this.lock.readLock().unlock(); + } + } + +} diff --git a/src/main/Operator_Profile.java b/src/main/Operator_Profile.java new file mode 100644 index 0000000..51a9f98 --- /dev/null +++ b/src/main/Operator_Profile.java @@ -0,0 +1,93 @@ +package main; + +import java.io.Serializable; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +public class Operator_Profile implements Serializable { + protected String name; + protected String username; + protected String email; + protected String phone; + protected String birthday; + protected int secure_level; + protected ReadWriteLock lock; + + public Operator_Profile(String name, String username, int secure_level, String email, String phone,String birthday) { + this.name = name; + this.username = username; + this.secure_level = secure_level; + this.email = email; + this.phone = phone; + this.birthday = birthday; + this.lock = new ReentrantReadWriteLock(); + } + + public Operator_Profile get_operator_profile() { + try { + this.lock.readLock().lock(); + return new Operator_Profile(name,username,secure_level,email,phone,birthday); + } finally { + this.lock.readLock().unlock(); + } + } + + public String get_name() { + try { + this.lock.readLock().lock(); + return name; + } finally { + this.lock.readLock().unlock(); + } + } + + public String get_username() { + try { + this.lock.readLock().lock(); + return username; + } finally { + this.lock.readLock().unlock(); + } + } + + public String get_email() { + try { + this.lock.readLock().lock(); + return email; + } finally { + this.lock.readLock().unlock(); + } + } + + public String get_phone() { + try { + this.lock.readLock().lock(); + return phone; + } finally { + this.lock.readLock().unlock(); + } + } + + public String get_birthday() { + try { + this.lock.readLock().lock(); + return birthday; + } finally { + this.lock.readLock().unlock(); + } + } + + public int get_secure_level() { + try { + this.lock.readLock().lock(); + return secure_level; + } finally { + this.lock.readLock().unlock(); + } + } + + @Override + public String toString() { + return name + '\n' + username + System.lineSeparator() + email + System.lineSeparator() + phone + System.lineSeparator() + birthday + System.lineSeparator() + secure_level; + } +} diff --git a/src/main/Operators.java b/src/main/Operators.java new file mode 100644 index 0000000..44a9f43 --- /dev/null +++ b/src/main/Operators.java @@ -0,0 +1,220 @@ +package main; + +import main.config.File_Path; +import main.exception.*; + +import java.io.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +public class Operators { + private static final String FILE_NAME = File_Path.getPATH() + "Operators"; + private static ArrayList list = new ArrayList(); + private static ReadWriteLock lock = new ReentrantReadWriteLock(); + + public static void add_operator(String name, String username, String password, int secure_level, String email, String phone, String birthday) throws UsernameTakenException { + try { + lock.writeLock().lock(); + if (!check_username(username)) { + Operator temp = new Operator(name, username, password, secure_level, email, phone,birthday); + list.add(temp); + } else { + throw new UsernameTakenException(); + } + } finally { + lock.writeLock().unlock(); + } + } + + public static void delete_operator(String username) throws Account_Does_Not_Exit_Exception { + Operator operator = get_operator(username); + try { + lock.writeLock().lock(); + list.remove(operator); + } finally { + lock.writeLock().unlock(); + } + } + + public static void change_password(String username, String new_password) throws Account_Does_Not_Exit_Exception { + get_operator(username).set_password(new_password); + } + + public static void change_birthday(String username, String new_birthday) throws Account_Does_Not_Exit_Exception { + get_operator(username).set_birthday(new_birthday); + + } + + public static void change_email(String username, String new_email) throws Account_Does_Not_Exit_Exception { + get_operator(username).set_email(new_email); + } + + public static void change_phone(String username, String new_phone) throws Account_Does_Not_Exit_Exception { + get_operator(username).set_phone(new_phone); + } + + public static void change_name(String username, String new_name) throws Account_Does_Not_Exit_Exception { + get_operator(username).set_name(new_name); + } + + public static void change_secure_level(String username, int new_secure_level) throws Account_Does_Not_Exit_Exception{ + get_operator(username).set_secure_level(new_secure_level); + } + + protected static void change_username(String username, String new_username) throws Account_Does_Not_Exit_Exception, UsernameTakenException { + if (check_username(new_username)) { + throw new UsernameTakenException(); + } + get_operator(username).set_username(new_username); + } + + + // returns false if no there is no user with this username, true otherwise. + public static boolean check_username(String username) { + try { + lock.readLock().lock(); + boolean flag = false; + for (Operator o : list) { + if (o.get_username().equals(username)) + flag = true; + } + return flag; + } finally { + lock.readLock().unlock(); + } + } + + public static Operator get_operator(String username) throws Account_Does_Not_Exit_Exception { + try { + lock.readLock().lock(); + for (Operator o : list) { + String o_username = o.get_username(); + if (o_username.equals(username)) + return o; + } + throw new Account_Does_Not_Exit_Exception(); + } finally { + lock.readLock().unlock(); + } + } + + public static Operator get_operator_by_email(String email) throws Email_Does_Not_Exist_Exception { + try { + lock.readLock().lock(); + for (Operator o : list) { + String o_email = o.get_email(); + if (o_email.equals(email)) + return o; + } + throw new Email_Does_Not_Exist_Exception(); + } finally { + lock.readLock().unlock(); + } + } + + public static int get_secure_level(String username) { + try { + lock.readLock().lock(); + int temp = 0; + for (Operator o : list) { + if (o.get_username().equals(username)) + temp = o.get_secure_level(); + } + return temp; + } finally { + lock.readLock().unlock(); + } + } + + public static HashMap get_operator_profiles(String username) throws Account_Does_Not_Exit_Exception { + HashMap operator_profiles = new HashMap(); + Operator requesting_operator = Operators.get_operator(username); + try { + lock.readLock().lock(); + for (Operator operator : list) { + if (requesting_operator.get_secure_level() > 0 && operator.get_secure_level() <= requesting_operator.get_secure_level()) { + operator_profiles.put(operator.get_username(),operator.get_operator_profile()); + } + } + return operator_profiles; + } finally { + lock.readLock().unlock(); + } + } + + public static HashMap get_all_operator_profiles_cmd() { + HashMap operator_profiles = new HashMap(); + try { + lock.readLock().lock(); + for (Operator operator : list) { + operator_profiles.put(operator.get_username(),operator.get_operator_profile()); + } + return operator_profiles; + } finally { + lock.readLock().unlock(); + } + } + + public static boolean check_password(String username, String password) throws IncorrectPasswordException, Account_Does_Not_Exit_Exception { + try { + lock.readLock().lock(); + for (Operator o : list) { + if (o.get_username().equals(username)) { + if (o.check_password(password)) { + return true; + } else { + throw new IncorrectPasswordException(); + } + } + } + throw new Account_Does_Not_Exit_Exception(); + } finally { + lock.readLock().unlock(); + } + } + + public static void save() { + try { + lock.readLock().lock(); + FileOutputStream f = new FileOutputStream(new File(FILE_NAME)); + ObjectOutputStream o = new ObjectOutputStream(f); + + // Write objects to file + o.writeObject(list); + + o.close(); + f.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + lock.readLock().unlock(); + } + } + + public static void load(){ + try { + lock.writeLock().lock(); + FileInputStream fi = new FileInputStream(new File(FILE_NAME)); + ObjectInputStream oi = new ObjectInputStream(fi); + + // Read objects + list = (ArrayList) oi.readObject(); + + oi.close(); + fi.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } finally { + lock.writeLock().unlock(); + } + } + +} diff --git a/src/main/Operators_Login_Control.java b/src/main/Operators_Login_Control.java new file mode 100644 index 0000000..8a27103 --- /dev/null +++ b/src/main/Operators_Login_Control.java @@ -0,0 +1,101 @@ +package main; + +import main.config.requests.LogIn_Request; +import main.exception.AccessDeniedException; +import main.exception.Account_Does_Not_Exit_Exception; +import main.exception.IncorrectPasswordException; +import main.exception.UsernameTakenException; + +import java.security.PublicKey; +import java.util.HashMap; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +public class Operators_Login_Control { + private static HashMap logged_in = new HashMap<>(); + private static ReadWriteLock lock = new ReentrantReadWriteLock(); + + public static Operator login(LogIn_Request logIn_request) throws Account_Does_Not_Exit_Exception, IncorrectPasswordException { + Operator operator = Operators.get_operator(logIn_request.get_username()); + Operators.check_password(logIn_request.get_username(),logIn_request.get_password()); + + boolean already_logged_in = Operators_Login_Control.is_logged_in(logIn_request.get_username()); + if (already_logged_in) { + logout(logIn_request.get_username()); + } + try { + lock.writeLock().lock(); + Operators_Login_Control.logged_in.put(operator.get_username(),new Login_Profile(operator,logIn_request.get_login_session_key_string())); + System.err.println(operator.get_name() + " logged in"); + return operator; + } finally { + lock.writeLock().unlock(); + } + } + + public static boolean is_logged_in (String username) { + try { + lock.readLock().lock(); + return Operators_Login_Control.logged_in.containsKey(username); + } finally { + lock.readLock().unlock(); + } + } + + public static Login_Profile get_login_profile(String username){ + try { + lock.readLock().lock(); + return logged_in.get(username); + } finally { + lock.readLock().unlock(); + } + } + + public static boolean session_key_string_verification(String username, String login_session_key_string) { + Login_Profile login_profile = Operators_Login_Control.get_login_profile(username); + if (login_profile != null) { + return login_profile.get_login_session_key_string().equals(login_session_key_string); + } + return false; + } + + public static void change_username_while_logged_In (String username, String new_username) throws Account_Does_Not_Exit_Exception, UsernameTakenException, AccessDeniedException { + Operators.change_username(username,new_username); + change_username_in_logged_in_list(username,new_username); + } + + public static void change_username_in_logged_in_list (String username, String new_username) { + Login_Profile login_profile = null; + try { + lock.writeLock().lock(); + login_profile = logged_in.remove(username); + if (login_profile != null) { + logged_in.put(new_username,login_profile); + } + } finally { + lock.writeLock().unlock(); + } + + + } + + public static boolean enhanced_verification(String username, String login_session_key_string, String verification_key_string) { + return Operators_Login_Control.session_key_string_verification(username,login_session_key_string) && + Operators_Login_Control.get_login_profile(username).check_verification_key(verification_key_string); + } + + public static void logout(String username) { + Login_Profile login_profile = null; + try { + lock.writeLock().lock(); + login_profile = logged_in.remove(username); + } finally { + lock.writeLock().unlock(); + } + if (login_profile != null) { + System.err.println(login_profile.get_operator().get_name() + " logged out"); + } else { + System.err.println("Username to be logged out doesn't exit"); + } + } +} diff --git a/src/main/Reset_Password_Count_Down.java b/src/main/Reset_Password_Count_Down.java new file mode 100644 index 0000000..711d8a4 --- /dev/null +++ b/src/main/Reset_Password_Count_Down.java @@ -0,0 +1,35 @@ +package main; + +import main.request_handler.Password_Reset_Verification_Code_Manager; + +public class Reset_Password_Count_Down implements Runnable{ + private String verification_code; + private boolean stop; + + public Reset_Password_Count_Down (String verification_code) { + this.verification_code = verification_code; + this.stop = false; + } + + public void terminates () { + this.stop = true; + } + + @Override + public void run() { + long start_time = System.currentTimeMillis(); + boolean flag = true; + while (flag && (!stop)) { + flag = (System.currentTimeMillis() - start_time) < 300000; + if (flag) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } else { + Password_Reset_Verification_Code_Manager.invalidate_verification_code(this.verification_code); + } + } + } +} diff --git a/src/main/Server_Main.java b/src/main/Server_Main.java new file mode 100644 index 0000000..02047bf --- /dev/null +++ b/src/main/Server_Main.java @@ -0,0 +1,82 @@ +package main; + +import main.customer.Customers; +import main.exception.Card_Number_Taken_Exception; +import main.exception.Customer_Does_Not_Exit_Exception; + +import main.config.File_Path; +import main.exception.UsernameTakenException; +import main.utility.EmailSender; +import main.utility.Networking_Config; +import main.request_handler.Client_Handler; +import main.ui.Server_Command_Line_Handler; + +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.ArrayList; +import java.util.Calendar; + +public class Server_Main { + private ServerSocket serverSocket; + private Socket connection_socket; + + public Server_Main() { + new File_Path(); + Networking_Config.init(); + EmailSender.init(); + + Operators.load(); + + temp_create_customers(); + + Thread cmd = new Thread(new Server_Command_Line_Handler()); + cmd.start(); + try { + this.serverSocket = new ServerSocket(Networking_Config.PORT); + while(true) { + this.connection_socket = serverSocket.accept(); + Thread thread = new Thread(new Client_Handler(this.connection_socket)); + thread.start(); + } + } catch (IOException e) { + e.printStackTrace(); + System.exit(-1); + } + + } + + private void temp_create_customers() { + try { +// Customers.add_customer("901572","吴帆","15995487439",Calendar.getInstance().get(Calendar.YEAR)); +// Customers.search_customer_by_card_number("901572").add_sale(new Sale(100,"1",new ArrayList(),500.00,500.00,500.00,500.00)); + Customers.add_customer("6085591205345361814","Cochrane","6044010078", Calendar.getInstance().get(Calendar.YEAR)); + Customers.add_customer("410313900384","Cochrane","6044010078",Calendar.getInstance().get(Calendar.YEAR)); + Customers.add_customer("410315478515","Fan Wu","7783210949",Calendar.getInstance().get(Calendar.YEAR)); + Customers.add_customer("6085592214289652286","Fan Wu","7783210949",Calendar.getInstance().get(Calendar.YEAR)); + } catch (Card_Number_Taken_Exception e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) { + new Server_Main(); +// try { +// Operators.add_operator("Fan Wu","realfanwu","123456",2,"realfanwu@gmail.com","1234567890","1970/01/01"); +// Operators.add_operator("Cochrane","cochrane","123456",2,"ljc20000118@hotmail.com","1234567890","1970/01/01"); +// Operators.add_operator("CHU","chu","123456",2,"chukayingyuki@gmail.com","1234567890","1970/01/01"); +// Operators.add_operator("GotFrom Server","","",2,"","1234567890","1970/01/01"); +// Operators.add_operator("CoFan","username","password",3,"CoFan@cofan.tech","1234567890","1970/01/01"); +// Operators.add_operator("Root","root","ed25519",3,"","1234567890","1970/01/01"); +// +// Operators.add_operator("Test 0","test0","123456",0,"test0@cofan.tech","1234567890","1970/01/01"); +// Operators.add_operator("Test 1","test1","123456",1,"test1@cofan.tech","1234567890","1970/01/01"); +// Operators.add_operator("Test 2","test2","123456",2,"test2@cofan.tech","1234567890","1970/01/01"); +// Operators.add_operator("Test 3","test3","123456",3,"test3@cofan.tech","1234567890","1970/01/01"); +// +// Operators.save(); +// } catch (UsernameTakenException e) { +// e.printStackTrace(); +// } + } +} diff --git a/src/main/config/Communication_Rules.java b/src/main/config/Communication_Rules.java new file mode 100644 index 0000000..89c95d8 --- /dev/null +++ b/src/main/config/Communication_Rules.java @@ -0,0 +1,37 @@ +package main.config; + +public class Communication_Rules { + public static final int OPERATION_SUCCESSFUL = 1; + public static final int OPERATION_FAILED = 2; + + public static final int SUCCESSFUL_LOGIN = 10; + public static final int USERNAME_DOES_NOT_EXIST = 11; + public static final int PASSWORD_INCORRECT = 12; + public static final int PASSWORD_CORRECT = 13; + public static final int USERNAME_ALREADY_EXIST = 14; + public static final int ACCESS_DENIED = 15; + public static final int CHECK_LOGGED_IN_REQUEST = 16; + + public static final int LOGIN_REQUEST = 20; + public static final int LOGOUT_REQUEST = 21; + public static final int VERIFY_PASSWORD_REQUEST = 22; + public static final int CHANGE_PASSWORD_REQUEST = 23; + public static final int CHANGE_BIRTHDAY_REQUEST = 24; + public static final int CHANGE_PHONE_REQUEST = 25; + public static final int CHANGE_EMAIL_REQUEST = 26; + public static final int CHANGE_SECURE_LEVEL_REQUEST = 27; + public static final int CHANGE_USERNAME_REQUEST = 28; + public static final int CHANGE_NAME_REQUEST = 29; + public static final int GET_OPERATOR_PROFILES_REQUEST = 30; + public static final int DELETE_OPERATOR_REQUEST = 31; + public static final int ADD_OPERATOR_REQUEST = 32; + public static final int RESET_PASSWORD_REQUEST = 33; + public static final int SEND_VERIFICATION_CODE = 34; + + public static final int EMAIL_NOT_FOUND_ERROR = 40; + + public static final int GET_SALABLE_REQUEST = 50; + public static final int GET_CUSTOMER_REQUEST = 51; + public static final int SEARCH_CUSTOMER_REQUEST = 52; + public static final int SEARCH_SALABLE_REQUEST = 53; +} diff --git a/src/main/config/File_Path.java b/src/main/config/File_Path.java new file mode 100644 index 0000000..25b39c9 --- /dev/null +++ b/src/main/config/File_Path.java @@ -0,0 +1,29 @@ +package main.config; + +import java.util.Objects; + +public class File_Path { + private static String PATH = ""; + + public File_Path() { + check_if_jar(); + } + + // Code from https://stackoverflow.com/questions/482560/can-you-tell-on-runtime-if-youre-running-java-from-within-a-jar By "IT man" + public boolean check_if_jar() { + String protocol = this.getClass().getResource("").getProtocol(); + if(Objects.equals(protocol, "jar")){ + // run in jar + PATH = "data/"; + return true; + } else if(Objects.equals(protocol, "file")) { + // run in ide + PATH = "src/data/"; + } + return false; + } + + public static String getPATH() { + return PATH; + } +} diff --git a/src/main/config/requests/Check_Logged_In_Request.java b/src/main/config/requests/Check_Logged_In_Request.java new file mode 100644 index 0000000..85d2620 --- /dev/null +++ b/src/main/config/requests/Check_Logged_In_Request.java @@ -0,0 +1,29 @@ +package main.config.requests; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Serializable; +import java.security.PublicKey; + +public class Check_Logged_In_Request implements Serializable { + private final String logged_In_username; + private final String login_session_key_string; + + public Check_Logged_In_Request(BufferedReader bufferedReader) throws IOException { + this.logged_In_username = bufferedReader.readLine(); + this.login_session_key_string = bufferedReader.readLine(); + } + + public Check_Logged_In_Request(String logged_In_username, String login_session_key_string) { + this.logged_In_username = logged_In_username; + this.login_session_key_string = login_session_key_string; + } + + public String get_logged_In_username() { + return this.logged_In_username; + } + + public String get_login_session_key_string() { + return this.login_session_key_string; + } +} diff --git a/src/main/config/requests/Get_Customer_Request.java b/src/main/config/requests/Get_Customer_Request.java new file mode 100644 index 0000000..6b7cd40 --- /dev/null +++ b/src/main/config/requests/Get_Customer_Request.java @@ -0,0 +1,36 @@ +package main.config.requests; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Serializable; +import java.security.PublicKey; + +public class Get_Customer_Request implements Serializable { + private final String logged_In_username; + private final String login_session_key_string; + private final String card_number; + + public Get_Customer_Request(String logged_In_username, String login_session_key_string, String card_number) { + this.logged_In_username = logged_In_username; + this.login_session_key_string = login_session_key_string; + this.card_number = card_number; + } + + public Get_Customer_Request(BufferedReader bufferedReader) throws IOException { + this.logged_In_username = bufferedReader.readLine(); + this.login_session_key_string = bufferedReader.readLine(); + this.card_number = bufferedReader.readLine(); + } + + public String get_logged_In_username() { + return this.logged_In_username; + } + + public String get_login_session_key_string() { + return this.login_session_key_string; + } + + public String get_card_number() { + return this.card_number; + } +} diff --git a/src/main/config/requests/LogIn_Request.java b/src/main/config/requests/LogIn_Request.java new file mode 100644 index 0000000..d97e2f4 --- /dev/null +++ b/src/main/config/requests/LogIn_Request.java @@ -0,0 +1,35 @@ +package main.config.requests; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Serializable; + +public class LogIn_Request implements Serializable { + private final String username; + private final String password; + private final String login_session_key_string; + + public LogIn_Request(BufferedReader bufferedReader) throws IOException { + this.username = bufferedReader.readLine(); + this.password = bufferedReader.readLine(); + this.login_session_key_string = bufferedReader.readLine(); + } + + public LogIn_Request(String username, String password, String login_session_key_string) { + this.username = username; + this.password = password; + this.login_session_key_string = login_session_key_string; + } + + public String get_username() { + return this.username; + } + + public String get_password() { + return this.password; + } + + public String get_login_session_key_string() { + return this.login_session_key_string; + } +} diff --git a/src/main/config/requests/Log_Out_Request.java b/src/main/config/requests/Log_Out_Request.java new file mode 100644 index 0000000..1c9c445 --- /dev/null +++ b/src/main/config/requests/Log_Out_Request.java @@ -0,0 +1,29 @@ +package main.config.requests; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Serializable; +import java.security.PublicKey; + +public class Log_Out_Request implements Serializable { + private final String logged_In_username; + private final String login_session_key_string; + + public Log_Out_Request(BufferedReader bufferedReader) throws IOException { + this.logged_In_username = bufferedReader.readLine(); + this.login_session_key_string = bufferedReader.readLine(); + } + + public Log_Out_Request(String logged_In_username, String login_session_key_string) { + this.logged_In_username = logged_In_username; + this.login_session_key_string = login_session_key_string; + } + + public String get_logged_In_username() { + return this.logged_In_username; + } + + public String get_login_session_key_string() { + return this.login_session_key_string; + } +} diff --git a/src/main/config/requests/Reset_Password_Request.java b/src/main/config/requests/Reset_Password_Request.java new file mode 100644 index 0000000..046fc10 --- /dev/null +++ b/src/main/config/requests/Reset_Password_Request.java @@ -0,0 +1,15 @@ +package main.config.requests; + +import java.io.Serializable; + +public class Reset_Password_Request implements Serializable { + private String email; + + public Reset_Password_Request (String email) { + this.email = email; + } + + public String get_email () { + return this.email; + } +} diff --git a/src/main/config/requests/Search_Customer_Request.java b/src/main/config/requests/Search_Customer_Request.java new file mode 100644 index 0000000..d666041 --- /dev/null +++ b/src/main/config/requests/Search_Customer_Request.java @@ -0,0 +1,36 @@ +package main.config.requests; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Serializable; +import java.security.PublicKey; + +public class Search_Customer_Request implements Serializable { + private final String logged_In_username; + private final String login_session_key_string; + private final String search_string; + + public Search_Customer_Request(String logged_In_username, String login_session_key_string, String search_string) { + this.logged_In_username = logged_In_username; + this.login_session_key_string = login_session_key_string; + this.search_string = search_string; + } + + public Search_Customer_Request(BufferedReader bufferedReader) throws IOException { + this.logged_In_username = bufferedReader.readLine(); + this.login_session_key_string = bufferedReader.readLine(); + this.search_string = bufferedReader.readLine(); + } + + public String get_logged_In_username() { + return this.logged_In_username; + } + + public String get_login_session_key_string() { + return this.login_session_key_string; + } + + public String get_search_string() { + return this.search_string; + } +} diff --git a/src/main/config/requests/operator_profile_requests/Add_Operator_Request.java b/src/main/config/requests/operator_profile_requests/Add_Operator_Request.java new file mode 100644 index 0000000..3969615 --- /dev/null +++ b/src/main/config/requests/operator_profile_requests/Add_Operator_Request.java @@ -0,0 +1,86 @@ +package main.config.requests.operator_profile_requests; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Serializable; +import java.security.PublicKey; + +public class Add_Operator_Request implements Serializable { + private final String logged_In_username; + private final String verification_key_string; + private final String login_session_key_string; + private final String name; + private final String username; + private final String password; + private final String email; + private final String phone; + private final String birthday; + private final int secure_level; + + public Add_Operator_Request(String logged_In_username, String verification_key_string, String login_session_key_string, + String name, String username, String password, int secure_level, String email, String phone,String birthday){ + this.logged_In_username = logged_In_username; + this.verification_key_string = verification_key_string; + this.login_session_key_string = login_session_key_string; + this.name = name; + this.username = username; + this.email = email; + this.phone = phone; + this.birthday = birthday; + this.secure_level = secure_level; + this.password = password; + } + + public Add_Operator_Request(BufferedReader bufferedReader) throws IOException { + this.logged_In_username = bufferedReader.readLine(); + this.verification_key_string = bufferedReader.readLine(); + this.login_session_key_string = bufferedReader.readLine(); + this.name = bufferedReader.readLine(); + this.username = bufferedReader.readLine(); + this.email = bufferedReader.readLine(); + this.phone = bufferedReader.readLine(); + this.birthday = bufferedReader.readLine(); + this.secure_level = Integer.parseInt(bufferedReader.readLine()); + this.password = bufferedReader.readLine(); + } + + public String get_logged_In_username() { + return this.logged_In_username; + } + + public String get_verification_key() { + return this.verification_key_string; + } + + public String get_login_session_key_string() { + return this.login_session_key_string; + } + + public String get_name() { + return name; + } + + public String get_username() { + return username; + } + + public String get_password() { + return this.password; + } + + public String get_email() { + return email; + } + + public String get_phone() { + return phone; + } + + public String get_birthday() { + return birthday; + } + + public int get_secure_level() { + return secure_level; + } +} diff --git a/src/main/config/requests/operator_profile_requests/Change_Birthday_Request.java b/src/main/config/requests/operator_profile_requests/Change_Birthday_Request.java new file mode 100644 index 0000000..199640f --- /dev/null +++ b/src/main/config/requests/operator_profile_requests/Change_Birthday_Request.java @@ -0,0 +1,16 @@ +package main.config.requests.operator_profile_requests; + +import java.security.PublicKey; + +public class Change_Birthday_Request extends Change_Profile_Request{ + private final String new_birthday; + + public Change_Birthday_Request(String logged_In_username, String username, String new_birthday, String verification_key_string, String login_session_key_string) { + super(logged_In_username,username, verification_key_string, login_session_key_string); + this.new_birthday = new_birthday; + } + + public String get_new_birthday() { + return this.new_birthday; + } +} diff --git a/src/main/config/requests/operator_profile_requests/Change_Email_Request.java b/src/main/config/requests/operator_profile_requests/Change_Email_Request.java new file mode 100644 index 0000000..fbe5cee --- /dev/null +++ b/src/main/config/requests/operator_profile_requests/Change_Email_Request.java @@ -0,0 +1,16 @@ +package main.config.requests.operator_profile_requests; + +import java.security.PublicKey; + +public class Change_Email_Request extends Change_Profile_Request{ + private String new_email; + + public Change_Email_Request(String logged_In_username, String username, String new_email, String verification_key_string, String login_session_key_string) { + super(logged_In_username,username, verification_key_string, login_session_key_string); + this.new_email = new_email; + } + + public String get_new_email() { + return this.new_email; + } +} diff --git a/src/main/config/requests/operator_profile_requests/Change_Name_Request.java b/src/main/config/requests/operator_profile_requests/Change_Name_Request.java new file mode 100644 index 0000000..277c33d --- /dev/null +++ b/src/main/config/requests/operator_profile_requests/Change_Name_Request.java @@ -0,0 +1,16 @@ +package main.config.requests.operator_profile_requests; + +import java.security.PublicKey; + +public class Change_Name_Request extends Change_Profile_Request{ + private String new_name; + + public Change_Name_Request(String logged_In_username, String username, String new_name, String verification_key_string, String login_session_key_string) { + super(logged_In_username,username, verification_key_string, login_session_key_string); + this.new_name = new_name; + } + + public String get_new_name() { + return this.new_name; + } +} diff --git a/src/main/config/requests/operator_profile_requests/Change_Password_Request.java b/src/main/config/requests/operator_profile_requests/Change_Password_Request.java new file mode 100644 index 0000000..3be46b5 --- /dev/null +++ b/src/main/config/requests/operator_profile_requests/Change_Password_Request.java @@ -0,0 +1,17 @@ +package main.config.requests.operator_profile_requests; + +import java.io.Serializable; +import java.security.PublicKey; + +public class Change_Password_Request extends Change_Profile_Request implements Serializable { + private final String new_password; + + public Change_Password_Request(String logged_In_username, String username,String verification_key_string, String new_password, String login_session_key_string) { + super(logged_In_username,username,verification_key_string,login_session_key_string); + this.new_password = new_password; + } + + public String get_new_password() { + return this.new_password; + } +} diff --git a/src/main/config/requests/operator_profile_requests/Change_Phone_Request.java b/src/main/config/requests/operator_profile_requests/Change_Phone_Request.java new file mode 100644 index 0000000..fb7a5c7 --- /dev/null +++ b/src/main/config/requests/operator_profile_requests/Change_Phone_Request.java @@ -0,0 +1,16 @@ +package main.config.requests.operator_profile_requests; + +import java.security.PublicKey; + +public class Change_Phone_Request extends Change_Profile_Request{ + private String new_phone; + + public Change_Phone_Request(String logged_In_username, String username, String new_phone, String verification_key_string, String login_session_key_string) { + super(logged_In_username,username, verification_key_string, login_session_key_string); + this.new_phone = new_phone; + } + + public String get_new_phone() { + return this.new_phone; + } +} diff --git a/src/main/config/requests/operator_profile_requests/Change_Profile_Request.java b/src/main/config/requests/operator_profile_requests/Change_Profile_Request.java new file mode 100644 index 0000000..8c96c3b --- /dev/null +++ b/src/main/config/requests/operator_profile_requests/Change_Profile_Request.java @@ -0,0 +1,51 @@ +package main.config.requests.operator_profile_requests; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Serializable; +import java.security.PublicKey; + +public class Change_Profile_Request implements Serializable { + private final String logged_In_username; + private final String username; + private final String verification_key_string; + private final String login_session_key_string; + private final boolean change_self_profile; + + public Change_Profile_Request(String logged_In_username, String username, String verification_key_string, String login_session_key_string) { + this.logged_In_username = logged_In_username; + this.username = username; + this.verification_key_string = verification_key_string; + this.login_session_key_string = login_session_key_string; + this.change_self_profile = this.logged_In_username.equals(this.username); + } + + public Change_Profile_Request(BufferedReader bufferedReader) throws IOException { + this.logged_In_username = bufferedReader.readLine(); + this.username = bufferedReader.readLine(); + this.verification_key_string = bufferedReader.readLine(); + this.login_session_key_string = bufferedReader.readLine(); + this.change_self_profile = this.logged_In_username.equals(this.username); + } + + public String get_logged_In_username() { + return this.logged_In_username; + } + + public String get_username() { + return this.username; + } + + public String get_verification_key() { + return this.verification_key_string; + } + + public String get_login_session_key_string() { + return this.login_session_key_string; + } + + public boolean is_change_self_profile() { + return this.change_self_profile; + } + +} diff --git a/src/main/config/requests/operator_profile_requests/Change_Secure_Level_Request.java b/src/main/config/requests/operator_profile_requests/Change_Secure_Level_Request.java new file mode 100644 index 0000000..a70e4fc --- /dev/null +++ b/src/main/config/requests/operator_profile_requests/Change_Secure_Level_Request.java @@ -0,0 +1,16 @@ +package main.config.requests.operator_profile_requests; + +import java.security.PublicKey; + +public class Change_Secure_Level_Request extends Change_Profile_Request{ + private String new_secure_level; + + public Change_Secure_Level_Request(String logged_In_username, String username, String new_secure_level, String verification_key_string, String login_session_key_string) { + super(logged_In_username,username, verification_key_string, login_session_key_string); + this.new_secure_level = new_secure_level; + } + + public String get_new_secure_level() { + return this.new_secure_level; + } +} diff --git a/src/main/config/requests/operator_profile_requests/Change_Username_Request.java b/src/main/config/requests/operator_profile_requests/Change_Username_Request.java new file mode 100644 index 0000000..709bf37 --- /dev/null +++ b/src/main/config/requests/operator_profile_requests/Change_Username_Request.java @@ -0,0 +1,16 @@ +package main.config.requests.operator_profile_requests; + +import java.security.PublicKey; + +public class Change_Username_Request extends Change_Profile_Request{ + private String new_username; + + public Change_Username_Request(String logged_In_username, String username, String new_username, String verification_key_string, String login_session_key_string) { + super(logged_In_username,username, verification_key_string, login_session_key_string); + this.new_username = new_username; + } + + public String get_new_username() { + return this.new_username; + } +} diff --git a/src/main/config/requests/operator_profile_requests/Delete_Operator_Request.java b/src/main/config/requests/operator_profile_requests/Delete_Operator_Request.java new file mode 100644 index 0000000..bc1e405 --- /dev/null +++ b/src/main/config/requests/operator_profile_requests/Delete_Operator_Request.java @@ -0,0 +1,44 @@ +package main.config.requests.operator_profile_requests; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Serializable; +import java.security.PublicKey; + +public class Delete_Operator_Request implements Serializable { + private final String logged_In_username; + private final String username; + private final String verification_key_string; + private final String login_session_key_string; + + + public Delete_Operator_Request(BufferedReader bufferedReader) throws IOException { + this.logged_In_username = bufferedReader.readLine(); + this.username = bufferedReader.readLine(); + this.verification_key_string = bufferedReader.readLine(); + this.login_session_key_string = bufferedReader.readLine(); + } + + public Delete_Operator_Request(String logged_In_username, String username, String verification_key_string, String login_session_key_string) { + this.logged_In_username = logged_In_username; + this.username = username; + this.verification_key_string = verification_key_string; + this.login_session_key_string = login_session_key_string; + } + + public String get_logged_In_username() { + return this.logged_In_username; + } + + public String get_username() { + return this.username; + } + + public String get_verification_key() { + return this.verification_key_string; + } + + public String get_login_session_key_string() { + return this.login_session_key_string; + } +} diff --git a/src/main/config/requests/operator_profile_requests/Get_Operator_Profiles_Request.java b/src/main/config/requests/operator_profile_requests/Get_Operator_Profiles_Request.java new file mode 100644 index 0000000..3a44a87 --- /dev/null +++ b/src/main/config/requests/operator_profile_requests/Get_Operator_Profiles_Request.java @@ -0,0 +1,30 @@ +package main.config.requests.operator_profile_requests; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Serializable; +import java.security.PublicKey; + +public class Get_Operator_Profiles_Request implements Serializable { + private final String logged_In_username; + private final String login_session_key_string; + + public Get_Operator_Profiles_Request(BufferedReader bufferedReader) throws IOException { + this.logged_In_username = bufferedReader.readLine(); + this.login_session_key_string = bufferedReader.readLine(); + } + + public Get_Operator_Profiles_Request(String logged_In_username, String login_session_key_string) { + this.logged_In_username = logged_In_username; + this.login_session_key_string = login_session_key_string; + } + + public String get_logged_In_username() { + return this.logged_In_username; + } + + public String get_login_session_key_string() { + return this.login_session_key_string; + } + +} diff --git a/src/main/customer/Common_Rule.java b/src/main/customer/Common_Rule.java new file mode 100644 index 0000000..169a643 --- /dev/null +++ b/src/main/customer/Common_Rule.java @@ -0,0 +1,6 @@ +package main.customer; + +public class Common_Rule { + public static int DOLLARS_PER_POINT = 20; + +} diff --git a/src/main/customer/Customer.java b/src/main/customer/Customer.java new file mode 100644 index 0000000..acc3e0b --- /dev/null +++ b/src/main/customer/Customer.java @@ -0,0 +1,77 @@ +package main.customer; + +public class Customer extends Customer_Profile{ + + public Customer(String card_number, String name,String phone,int year){ + super(card_number,name,phone,year); + } + + public void set_name(String name){ + try { + lock.writeLock().lock(); + this.name = name; + } finally { + lock.writeLock().unlock(); + } + } + + public void set_phone(String phone) { + try { + lock.writeLock().lock(); + this.phone = phone; + } finally { + lock.writeLock().unlock(); + } + } + + public void set_card_number(String card_number){ + try { + lock.writeLock().lock(); + this.card_number = card_number; + } finally { + lock.writeLock().unlock(); + } + } + + private void add_points(int points){ + try { + lock.writeLock().lock(); + this.points += points; + } finally { + lock.writeLock().unlock(); + } + } + + public boolean redeem_points(int points){ + try { + lock.writeLock().lock(); + if(this.points < points){ + return false; + } + this.points -= points; + return true; + } finally { + lock.writeLock().unlock(); + } + } + +// public void add_sale(Sale sale){ +// try { +// lock.writeLock().lock(); +// sales.add(sale); +// total_amount += sale.get_amount(); +// add_points((int)sale.get_amount()/Common_Rule.DOLLARS_PER_POINT); +// } finally { +// lock.writeLock().unlock(); +// } +// } + + public void add_notes(String note) { + try { + lock.writeLock().lock(); + this.notes.add(note); + } finally { + lock.writeLock().unlock(); + } + } +} diff --git a/src/main/customer/Customer_Profile.java b/src/main/customer/Customer_Profile.java new file mode 100644 index 0000000..df5f58b --- /dev/null +++ b/src/main/customer/Customer_Profile.java @@ -0,0 +1,128 @@ +package main.customer; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +public class Customer_Profile implements Serializable { + protected String card_number; + protected String name; + protected String phone; + protected ArrayList notes; + protected int points; + protected int year; + protected double total_amount; + // protected ArrayList sales; + protected ReadWriteLock lock; + + public Customer_Profile (String card_number, String name, String phone, int year) { + this.card_number = card_number; + this.name = name; + this.phone = phone; + this.year = year; + points = 0; + total_amount = 0; +// sales = new ArrayList<>(); + this.lock = new ReentrantReadWriteLock(); + this.notes = new ArrayList(); + } + + + public String get_card_number(){ + try { + lock.readLock().lock(); + return card_number; + } finally { + lock.readLock().unlock(); + } + } + + public String get_name(){ + try { + lock.readLock().lock(); + return name; + } finally { + lock.readLock().unlock(); + } + } + + public String get_phone(){ + try { + lock.readLock().lock(); + return phone; + } finally { + lock.readLock().unlock(); + } + } + + public int get_year() { + try { + lock.readLock().lock(); + return year; + } finally { + lock.readLock().unlock(); + } + } + + public int get_points(){ + try { + lock.readLock().lock(); + return points; + } finally { + lock.readLock().unlock(); + } + } + + public double get_total_amount(){ + try { + lock.readLock().lock(); + return total_amount; + } finally { + lock.readLock().unlock(); + } + } + +// public ArrayList get_sales(){ +// try { +// lock.readLock().lock(); +// return sales; +// } finally { +// lock.readLock().unlock(); +// } +// } + + public Customer_Profile get_profile() { + try { + lock.readLock().lock(); + Customer_Profile customer_profile = new Customer_Profile(card_number,name,phone,year); + customer_profile.points = this.points; + customer_profile.total_amount = this.total_amount; +// customer_profile.sales.addAll(this.sales); + return customer_profile; + } finally { + lock.readLock().unlock(); + } + } + + public ArrayList get_notes() { + try { + lock.readLock().lock(); + return new ArrayList(this.notes); + } finally { + lock.readLock().unlock(); + } + } + + @Override + public String toString() { + String s_notes = ""; + for(String s : notes) { + s_notes += s; + s_notes += System.lineSeparator(); + } + return card_number + System.lineSeparator() + name + System.lineSeparator() + phone + System.lineSeparator() + + ("" + notes.size()) + System.lineSeparator() + s_notes + points + System.lineSeparator() + year + System.lineSeparator() + + ("" + (int) (total_amount * 100)); + } +} diff --git a/src/main/customer/Customers.java b/src/main/customer/Customers.java new file mode 100644 index 0000000..5a7ba34 --- /dev/null +++ b/src/main/customer/Customers.java @@ -0,0 +1,133 @@ +package main.customer; + +import main.exception.Card_Number_Taken_Exception; +import main.exception.Customer_Does_Not_Exit_Exception; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +public class Customers { + private static Default_Customer default_customer = new Default_Customer(); + private static HashMap customers = new HashMap<>(); + private static ReadWriteLock lock = new ReentrantReadWriteLock(); + + public static void add_customer(String card_number, String name, String phone, int year) throws Card_Number_Taken_Exception { + try { + lock.writeLock().lock(); + if (default_customer.get_card_number().equals(card_number) || customers.containsKey(card_number)) { + throw new Card_Number_Taken_Exception(); + } else { + Customer temp = new Customer(card_number, name,phone,year); + customers.put(card_number, temp); + } + } finally { + lock.writeLock().unlock(); + } + } + + public static ArrayList search_customer_by_name(String name) throws Customer_Does_Not_Exit_Exception { + ArrayList lists = new ArrayList<>(); + try { + lock.readLock().lock(); + for (String s : customers.keySet()) { + Customer temp = customers.get(s); + if(temp.get_name().equals(name)){ + lists.add(temp.get_profile()); + } + } + } finally { + lock.readLock().unlock(); + } + if (lists.size() > 0) { + return lists; + } else { + throw new Customer_Does_Not_Exit_Exception(); + } + } + + public static ArrayList search_customer_by_phone(String phone) throws Customer_Does_Not_Exit_Exception { + ArrayList lists = new ArrayList<>(); + try { + lock.readLock().lock(); + for (String s : customers.keySet()) { + Customer temp = customers.get(s); + if(temp.get_phone().equals(phone)){ + lists.add(temp.get_profile()); + } + } + } finally { + lock.readLock().unlock(); + } + if (lists.size() > 0) { + return lists; + } else { + throw new Customer_Does_Not_Exit_Exception(); + } + } + + public static Customer search_customer_by_card_number(String card_number) throws Customer_Does_Not_Exit_Exception { + Customer customer = null; + try { + lock.readLock().lock(); + if (default_customer.get_card_number().equals(card_number)) { + customer = default_customer; + } else { + customer = customers.get(card_number); + } + } finally { + lock.readLock().unlock(); + } + if (customer != null) { + return customer; + } else { + throw new Customer_Does_Not_Exit_Exception(); + } + } + + public static ArrayList search_customer(String search_string) throws Customer_Does_Not_Exit_Exception { + ArrayList lists = new ArrayList<>(); + try { + lock.readLock().lock(); + for (String s : customers.keySet()) { + Customer temp = customers.get(s); + if(s.equals(search_string) || temp.get_name().equals(search_string) || temp.get_phone().equals(search_string)){ + lists.add(temp.get_profile()); + } + } + } finally { + lock.readLock().unlock(); + } + if (lists.size() > 0) { + return lists; + } else { + throw new Customer_Does_Not_Exit_Exception(); + } + } + + public static ArrayList get_all_customers() { + ArrayList lists = new ArrayList<>(); + try { + lock.readLock().lock(); + for (String s : customers.keySet()) { + Customer temp = customers.get(s); + lists.add(temp.get_profile()); + } + } finally { + lock.readLock().unlock(); + } + return lists; + } + + public static Default_Customer get_default_customer() { + try { + lock.readLock().lock(); + return default_customer; + } finally { + lock.readLock().unlock(); + } + } + + +} diff --git a/src/main/customer/Default_Customer.java b/src/main/customer/Default_Customer.java new file mode 100644 index 0000000..d353c81 --- /dev/null +++ b/src/main/customer/Default_Customer.java @@ -0,0 +1,24 @@ +package main.customer; + +public class Default_Customer extends Customer{ + + public Default_Customer() { + super("","None","",2020); + } + + @Override + public boolean redeem_points(int points){ + return false; + } + +// @Override +// public void add_sale(Sale sale){ +// try { +// lock.writeLock().lock(); +// sales.add(sale); +// total_amount += sale.get_amount(); +// } finally { +// lock.writeLock().unlock(); +// } +// } +} diff --git a/src/main/exception/AccessDeniedException.java b/src/main/exception/AccessDeniedException.java new file mode 100644 index 0000000..b4963c6 --- /dev/null +++ b/src/main/exception/AccessDeniedException.java @@ -0,0 +1,7 @@ +package main.exception; + +public class AccessDeniedException extends Exception { + public AccessDeniedException() { + super("You do not have access to do this"); + } +} diff --git a/src/main/exception/Account_Does_Not_Exit_Exception.java b/src/main/exception/Account_Does_Not_Exit_Exception.java new file mode 100644 index 0000000..6619c67 --- /dev/null +++ b/src/main/exception/Account_Does_Not_Exit_Exception.java @@ -0,0 +1,7 @@ +package main.exception; + +public class Account_Does_Not_Exit_Exception extends Exception { + public Account_Does_Not_Exit_Exception() { + super("Your account has been disabled"); + } +} diff --git a/src/main/exception/Card_Number_Taken_Exception.java b/src/main/exception/Card_Number_Taken_Exception.java new file mode 100644 index 0000000..9639b0d --- /dev/null +++ b/src/main/exception/Card_Number_Taken_Exception.java @@ -0,0 +1,4 @@ +package main.exception; + +public class Card_Number_Taken_Exception extends Exception{ +} diff --git a/src/main/exception/Customer_Does_Not_Exit_Exception.java b/src/main/exception/Customer_Does_Not_Exit_Exception.java new file mode 100644 index 0000000..a3d878e --- /dev/null +++ b/src/main/exception/Customer_Does_Not_Exit_Exception.java @@ -0,0 +1,4 @@ +package main.exception; + +public class Customer_Does_Not_Exit_Exception extends Exception{ +} diff --git a/src/main/exception/DataNotFoundException.java b/src/main/exception/DataNotFoundException.java new file mode 100644 index 0000000..0cebdfc --- /dev/null +++ b/src/main/exception/DataNotFoundException.java @@ -0,0 +1,7 @@ +package main.exception; + +public class DataNotFoundException extends Exception { + public DataNotFoundException(String message) { + super(message); + } +} diff --git a/src/main/exception/Email_Does_Not_Exist_Exception.java b/src/main/exception/Email_Does_Not_Exist_Exception.java new file mode 100644 index 0000000..685bdc8 --- /dev/null +++ b/src/main/exception/Email_Does_Not_Exist_Exception.java @@ -0,0 +1,4 @@ +package main.exception; + +public class Email_Does_Not_Exist_Exception extends Exception{ +} diff --git a/src/main/exception/IncorrectPasswordException.java b/src/main/exception/IncorrectPasswordException.java new file mode 100644 index 0000000..69137e5 --- /dev/null +++ b/src/main/exception/IncorrectPasswordException.java @@ -0,0 +1,7 @@ +package main.exception; + +public class IncorrectPasswordException extends Exception { + public IncorrectPasswordException() { + super("password is incorrect"); + } +} diff --git a/src/main/exception/ItemNotFoundException.java b/src/main/exception/ItemNotFoundException.java new file mode 100644 index 0000000..b3f848e --- /dev/null +++ b/src/main/exception/ItemNotFoundException.java @@ -0,0 +1,7 @@ +package main.exception; + +public class ItemNotFoundException extends Exception { + public ItemNotFoundException() { + super("Item is not in the system"); + } +} diff --git a/src/main/exception/Item_Does_Not_Exit_Exception.java b/src/main/exception/Item_Does_Not_Exit_Exception.java new file mode 100644 index 0000000..9ea249c --- /dev/null +++ b/src/main/exception/Item_Does_Not_Exit_Exception.java @@ -0,0 +1,4 @@ +package main.exception; + +public class Item_Does_Not_Exit_Exception extends Exception{ +} diff --git a/src/main/exception/UsernameTakenException.java b/src/main/exception/UsernameTakenException.java new file mode 100644 index 0000000..a344e8b --- /dev/null +++ b/src/main/exception/UsernameTakenException.java @@ -0,0 +1,7 @@ +package main.exception; + +public class UsernameTakenException extends Exception { + public UsernameTakenException() { + super("This user name is already taken"); + } +} \ No newline at end of file diff --git a/src/main/request_handler/Check_Logged_In_Request_Handler.java b/src/main/request_handler/Check_Logged_In_Request_Handler.java new file mode 100644 index 0000000..cf6680a --- /dev/null +++ b/src/main/request_handler/Check_Logged_In_Request_Handler.java @@ -0,0 +1,40 @@ +package main.request_handler; + +import main.Operators_Login_Control; +import main.config.Communication_Rules; +import main.config.requests.Check_Logged_In_Request; + +import java.io.*; +import java.net.Socket; + +public class Check_Logged_In_Request_Handler implements Runnable{ + private final Socket connection_socket; + private BufferedReader in; + private PrintWriter printWriter; + + public Check_Logged_In_Request_Handler(Socket connection_socket,BufferedReader in) { + this.connection_socket = connection_socket; + this.in = in; + try { + this.printWriter = new PrintWriter(this.connection_socket.getOutputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + } + @Override + public void run() { + try { + Check_Logged_In_Request check_logged_in_request = new Check_Logged_In_Request(this.in); + if (Operators_Login_Control.session_key_string_verification(check_logged_in_request.get_logged_In_username(),check_logged_in_request.get_login_session_key_string())) { + this.printWriter.println("" + Communication_Rules.OPERATION_SUCCESSFUL); + this.printWriter.flush(); + } else { + this.printWriter.println("" + Communication_Rules.OPERATION_FAILED); + this.printWriter.flush(); + } + connection_socket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/request_handler/Client_Handler.java b/src/main/request_handler/Client_Handler.java new file mode 100644 index 0000000..cf6655d --- /dev/null +++ b/src/main/request_handler/Client_Handler.java @@ -0,0 +1,64 @@ +package main.request_handler; + +import main.config.Communication_Rules; +import main.request_handler.customer_request_handler.Get_Customer_Request_handler; +import main.request_handler.customer_request_handler.Search_Customer_Request_handler; +import main.request_handler.operator_profile_request_handler.Add_Operator_Handler; +import main.request_handler.operator_profile_request_handler.Change_Profile_Handler; +import main.request_handler.operator_profile_request_handler.Delete_Operator_Handler; +import main.request_handler.operator_profile_request_handler.Get_Operator_Profiles_Handler; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.ObjectInputStream; +import java.net.Socket; +import java.net.SocketException; + +public class Client_Handler implements Runnable{ + private Socket connection_socket; + private BufferedReader bufferedReader; + + public Client_Handler(Socket connection_socket) { + this.connection_socket = connection_socket; + } + + @Override + public void run() { + try { + this.bufferedReader = new BufferedReader(new InputStreamReader(this.connection_socket.getInputStream())); + int request = Integer.parseInt(this.bufferedReader.readLine()); + switch (request) { + case Communication_Rules.LOGIN_REQUEST: run_thread(new Login_Handler(this.connection_socket,this.bufferedReader));break; + case Communication_Rules.LOGOUT_REQUEST: run_thread(new LogOut_Handler(this.connection_socket,this.bufferedReader)); break; + case Communication_Rules.VERIFY_PASSWORD_REQUEST: + run_thread(new Password_Verification_Handler(this.connection_socket,this.bufferedReader));break; + case Communication_Rules.CHANGE_PASSWORD_REQUEST: + case Communication_Rules.CHANGE_BIRTHDAY_REQUEST: + case Communication_Rules.CHANGE_PHONE_REQUEST: + case Communication_Rules.CHANGE_EMAIL_REQUEST: + case Communication_Rules.CHANGE_SECURE_LEVEL_REQUEST: + case Communication_Rules.CHANGE_USERNAME_REQUEST: + case Communication_Rules.CHANGE_NAME_REQUEST: + run_thread(new Change_Profile_Handler(this.connection_socket,this.bufferedReader,request));break; + case Communication_Rules.GET_OPERATOR_PROFILES_REQUEST: run_thread(new Get_Operator_Profiles_Handler(this.connection_socket,this.bufferedReader));break; + case Communication_Rules.DELETE_OPERATOR_REQUEST: run_thread(new Delete_Operator_Handler(this.connection_socket,this.bufferedReader));break; + case Communication_Rules.ADD_OPERATOR_REQUEST: run_thread(new Add_Operator_Handler(this.connection_socket,this.bufferedReader));break; + case Communication_Rules.RESET_PASSWORD_REQUEST: run_thread(new Reset_Password_Handler(this.connection_socket,this.bufferedReader));break; + case Communication_Rules.SEND_VERIFICATION_CODE: run_thread(new Password_Reset_Verification_Code_Handler(this.connection_socket,this.bufferedReader));break; +// case Communication_Rules.GET_SALABLE_REQUEST: break; + case Communication_Rules.GET_CUSTOMER_REQUEST: run_thread(new Get_Customer_Request_handler(this.connection_socket,this.bufferedReader));break; + case Communication_Rules.SEARCH_CUSTOMER_REQUEST: run_thread(new Search_Customer_Request_handler(this.connection_socket,this.bufferedReader));break; + case Communication_Rules.CHECK_LOGGED_IN_REQUEST: run_thread(new Check_Logged_In_Request_Handler(this.connection_socket,this.bufferedReader));break; + default: + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void run_thread(Runnable runnable) { + Thread thread = new Thread(runnable); + thread.start(); + } +} diff --git a/src/main/request_handler/LogOut_Handler.java b/src/main/request_handler/LogOut_Handler.java new file mode 100644 index 0000000..4928eb0 --- /dev/null +++ b/src/main/request_handler/LogOut_Handler.java @@ -0,0 +1,38 @@ +package main.request_handler; + +import main.Operators_Login_Control; +import main.config.requests.Log_Out_Request; + +import java.io.BufferedReader; +import java.io.IOException; +import java.net.Socket; + +public class LogOut_Handler implements Runnable{ + private Socket connection_socket; + private BufferedReader in; + + public LogOut_Handler(Socket connection_socket, BufferedReader in) { + this.connection_socket = connection_socket; + this.in = in; + } + @Override + public void run() { + try { + Log_Out_Request log_out_request = new Log_Out_Request(this.in); + if (Operators_Login_Control.session_key_string_verification(log_out_request.get_logged_In_username(),log_out_request.get_login_session_key_string())) { + Operators_Login_Control.logout(log_out_request.get_logged_In_username()); + } +// else { +// try { +// this.out.writeObject("" + Communication_Rules.OPERATION_FAILED); +// this.out.flush(); +// } catch (IOException ioException) { +// ioException.printStackTrace(); +// } +// } + connection_socket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/request_handler/Login_Handler.java b/src/main/request_handler/Login_Handler.java new file mode 100644 index 0000000..ac9180e --- /dev/null +++ b/src/main/request_handler/Login_Handler.java @@ -0,0 +1,49 @@ +package main.request_handler; + +import main.Operator; +import main.Operators_Login_Control; +import main.config.*; +import main.config.requests.LogIn_Request; +import main.exception.Account_Does_Not_Exit_Exception; +import main.exception.IncorrectPasswordException; + +import java.io.*; +import java.net.Socket; +import java.net.SocketException; + +public class Login_Handler implements Runnable{ + private final Socket connection_socket; + private BufferedReader in; + private PrintWriter printWriter; + + public Login_Handler(Socket connection_socket,BufferedReader in) { + this.connection_socket = connection_socket; + this.in = in; + } + + @Override + public void run() { + try { + this.printWriter = new PrintWriter(this.connection_socket.getOutputStream()); + + LogIn_Request logIn_request = new LogIn_Request(this.in); + + Operator operator = Operators_Login_Control.login(logIn_request); + this.printWriter.println("" + Communication_Rules.SUCCESSFUL_LOGIN); + this.printWriter.flush(); + this.printWriter.println(operator.get_operator_profile().toString()); + this.printWriter.flush(); + connection_socket.close(); + } catch (SocketException ignored) { + + } catch (Account_Does_Not_Exit_Exception e) { + this.printWriter.println("" + Communication_Rules.USERNAME_DOES_NOT_EXIST); + this.printWriter.flush(); + } catch (IncorrectPasswordException e) { + this.printWriter.println("" + Communication_Rules.PASSWORD_INCORRECT); + this.printWriter.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/request_handler/Password_Reset_Verification_Code_Handler.java b/src/main/request_handler/Password_Reset_Verification_Code_Handler.java new file mode 100644 index 0000000..0a9018e --- /dev/null +++ b/src/main/request_handler/Password_Reset_Verification_Code_Handler.java @@ -0,0 +1,48 @@ +package main.request_handler; + +import main.Operator; +import main.Operators; +import main.config.Communication_Rules; + +import java.io.*; +import java.net.Socket; +import java.net.SocketException; + +public class Password_Reset_Verification_Code_Handler implements Runnable{ + private final Socket connection_socket; + private BufferedReader in; + private PrintWriter printWriter; + + public Password_Reset_Verification_Code_Handler(Socket connection_socket,BufferedReader in) { + this.connection_socket = connection_socket; + this.in = in; + try { + this.printWriter = new PrintWriter(this.connection_socket.getOutputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void run() { + try { + String verification_code = this.in.readLine(); + String password = this.in.readLine(); + Operator operator = Password_Reset_Verification_Code_Manager.verify(verification_code); + if (operator != null) { + operator.set_password(password); + Operators.save(); + this.printWriter.println("" + Communication_Rules.OPERATION_SUCCESSFUL); + this.printWriter.flush(); + } else { + this.printWriter.println("" + Communication_Rules.OPERATION_FAILED); + this.printWriter.flush(); + } + connection_socket.close(); + } catch (SocketException ignored) { + + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/request_handler/Password_Reset_Verification_Code_Manager.java b/src/main/request_handler/Password_Reset_Verification_Code_Manager.java new file mode 100644 index 0000000..3c77337 --- /dev/null +++ b/src/main/request_handler/Password_Reset_Verification_Code_Manager.java @@ -0,0 +1,66 @@ +package main.request_handler; + +import main.Operator; +import main.Reset_Password_Count_Down; + +import java.util.HashMap; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +public class Password_Reset_Verification_Code_Manager { + private static HashMap verification_codes = new HashMap(); + private static HashMap count_downs = new HashMap(); + private static ReadWriteLock lock = new ReentrantReadWriteLock(); + + public static boolean put_verification_code (String verification_code, Operator operator) { + try { + lock.writeLock().lock(); + if (verification_codes.containsKey(verification_code)) { + return false; + } else { + for (String key : count_downs.keySet()) { + if (verification_codes.get(key) == operator) { + count_downs.remove(key).terminates(); + verification_codes.remove(key); + } + } + verification_codes.put(verification_code,operator); + return true; + } + } finally { + lock.writeLock().unlock(); + } + } + + public static boolean put_verification_count_down (String verification_code, Reset_Password_Count_Down count_down) { + try { + lock.writeLock().lock(); + if (verification_codes.containsKey(verification_code)) { + count_downs.put(verification_code,count_down); + return true; + } else { + return false; + } + } finally { + lock.writeLock().unlock(); + } + } + + public static void invalidate_verification_code (String verification_code) { + verify(verification_code); + } + + public static Operator verify (String verification_code) { + try { + lock.writeLock().lock(); + if (count_downs.containsKey(verification_code)) { + count_downs.remove(verification_code).terminates(); + return verification_codes.remove(verification_code); + } else { + return null; + } + } finally { + lock.writeLock().unlock(); + } + } +} diff --git a/src/main/request_handler/Password_Verification_Handler.java b/src/main/request_handler/Password_Verification_Handler.java new file mode 100644 index 0000000..e329606 --- /dev/null +++ b/src/main/request_handler/Password_Verification_Handler.java @@ -0,0 +1,80 @@ +package main.request_handler; + +import main.Login_Profile; +import main.Operators; +import main.Operators_Login_Control; +import main.config.Communication_Rules; +import main.exception.Account_Does_Not_Exit_Exception; +import main.exception.IncorrectPasswordException; + +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; +import java.io.*; +import java.net.Socket; +import java.net.SocketException; +import java.security.NoSuchAlgorithmException; +import java.util.Base64; + +public class Password_Verification_Handler implements Runnable{ + private final Socket connection_socket; + private BufferedReader in; + private PrintWriter printWriter; + + public Password_Verification_Handler(Socket connection_socket, BufferedReader in) { + this.connection_socket = connection_socket; + this.in = in; + try { + this.printWriter = new PrintWriter(this.connection_socket.getOutputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void run() { + try { + String username = this.in.readLine(); + String password = this.in.readLine(); + + Login_Profile login_profile = Operators_Login_Control.get_login_profile(username); + if (login_profile != null) { + Operators.check_password(username,password); + this.printWriter.println(new String("" + Communication_Rules.PASSWORD_CORRECT)); + this.printWriter.flush(); + + KeyGenerator keygen = KeyGenerator.getInstance("AES"); + keygen.init(256); + SecretKey aes_key = keygen.generateKey(); + String verification_key_string = Base64.getEncoder().encodeToString(aes_key.getEncoded()); + + login_profile.set_verification_key(verification_key_string); + this.printWriter.println(verification_key_string); + this.printWriter.flush(); + } else { + this.printWriter.println("" + Communication_Rules.OPERATION_FAILED); + this.printWriter.flush(); + } + connection_socket.close(); + } catch (SocketException | NoSuchAlgorithmException ignored) { + + } catch (IOException e) { + e.printStackTrace(); + } catch (Account_Does_Not_Exit_Exception e) { + try { + this.printWriter.println(new String("" + Communication_Rules.OPERATION_FAILED)); + this.printWriter.flush(); + connection_socket.close(); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } catch (IncorrectPasswordException e) { + try { + this.printWriter.println(new String("" + Communication_Rules.PASSWORD_INCORRECT)); + this.printWriter.flush(); + connection_socket.close(); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } + } +} diff --git a/src/main/request_handler/Reset_Password_Handler.java b/src/main/request_handler/Reset_Password_Handler.java new file mode 100644 index 0000000..1eed27d --- /dev/null +++ b/src/main/request_handler/Reset_Password_Handler.java @@ -0,0 +1,90 @@ +package main.request_handler; + +import main.*; +import main.config.Communication_Rules; +import main.config.requests.Reset_Password_Request; +import main.exception.Email_Does_Not_Exist_Exception; +import main.utility.EmailSender; +import main.utility.Random_String_Generator; + +import java.io.*; +import java.net.Socket; +import java.net.SocketException; + +public class Reset_Password_Handler implements Runnable{ + private final Socket connection_socket; + private BufferedReader in; + private PrintWriter printWriter; + + public Reset_Password_Handler(Socket connection_socket,BufferedReader in) { + this.connection_socket = connection_socket; + this.in = in; + try { + this.printWriter = new PrintWriter(this.connection_socket.getOutputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void run() { + try { + Reset_Password_Request reset_password_request = new Reset_Password_Request(this.in.readLine()); + + Operator operator = Operators.get_operator_by_email(reset_password_request.get_email()); + String verification_code = Random_String_Generator.get_random_string(8); + boolean successful = Password_Reset_Verification_Code_Manager.put_verification_code(verification_code,operator); + while (!successful) { + verification_code = Random_String_Generator.get_random_string(8); + successful = Password_Reset_Verification_Code_Manager.put_verification_code(verification_code,operator); + } + Reset_Password_Count_Down reset_password_count_down = new Reset_Password_Count_Down(verification_code); + Password_Reset_Verification_Code_Manager.put_verification_count_down(verification_code,reset_password_count_down); + new Thread(new Reset_Password_Count_Down(verification_code)).start(); + String message = "Dear " + operator.get_name() + ":\n" + + "\n" + + " Please enter your verification code within 5 minutes :\n" + + "\n" + + " Username: " + operator.get_username() + "\n" + + "\n" + + " Verification Code: " + verification_code + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "Copyrights © 2020 CoFan.Tech. All rights reserved. (Fake)"; + EmailSender.send(reset_password_request.get_email(),message); +// System.out.println(message); + this.printWriter.println("" + Communication_Rules.OPERATION_SUCCESSFUL); + this.printWriter.flush(); + connection_socket.close(); + } catch (SocketException ignored) { + + } catch (Email_Does_Not_Exist_Exception e) { + try { + this.printWriter.println("" + Communication_Rules.EMAIL_NOT_FOUND_ERROR); + this.printWriter.flush(); + connection_socket.close(); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } catch (Exception e) { + e.printStackTrace(); + try { + this.printWriter.println("" + Communication_Rules.OPERATION_FAILED); + this.printWriter.flush(); + this.connection_socket.close(); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } + } +} diff --git a/src/main/request_handler/customer_request_handler/Get_Customer_Request_handler.java b/src/main/request_handler/customer_request_handler/Get_Customer_Request_handler.java new file mode 100644 index 0000000..dd7dba0 --- /dev/null +++ b/src/main/request_handler/customer_request_handler/Get_Customer_Request_handler.java @@ -0,0 +1,60 @@ +package main.request_handler.customer_request_handler; + +import main.Operators_Login_Control; +import main.config.Communication_Rules; +import main.config.requests.Get_Customer_Request; +import main.customer.Customer_Profile; +import main.customer.Customers; +import main.exception.Customer_Does_Not_Exit_Exception; + +import java.io.*; +import java.net.Socket; + +public class Get_Customer_Request_handler implements Runnable{ + private final Socket connection_socket; + private BufferedReader in; + private PrintWriter printWriter; + + public Get_Customer_Request_handler(Socket connection_socket,BufferedReader in) { + this.connection_socket = connection_socket; + this.in = in; + try { + this.printWriter = new PrintWriter(this.connection_socket.getOutputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void run() { + try { + Get_Customer_Request get_customer_request = new Get_Customer_Request(this.in); + + if (Operators_Login_Control.session_key_string_verification(get_customer_request.get_logged_In_username(),get_customer_request.get_login_session_key_string())) { + String card_number = get_customer_request.get_card_number(); + Customer_Profile customer_profile = Customers.search_customer_by_card_number(card_number).get_profile(); + + this.printWriter.println("" + Communication_Rules.OPERATION_SUCCESSFUL); + this.printWriter.flush(); + + this.printWriter.println(customer_profile.toString()); + this.printWriter.flush(); + + } else { + this.printWriter.println("" + Communication_Rules.ACCESS_DENIED); + this.printWriter.flush(); + } + connection_socket.close(); + } catch (IOException e) { + e.printStackTrace(); + } catch (Customer_Does_Not_Exit_Exception e) { + try { + this.printWriter.println("" + Communication_Rules.OPERATION_FAILED); + this.printWriter.flush(); + connection_socket.close(); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } + } +} diff --git a/src/main/request_handler/customer_request_handler/Search_Customer_Request_handler.java b/src/main/request_handler/customer_request_handler/Search_Customer_Request_handler.java new file mode 100644 index 0000000..c92b827 --- /dev/null +++ b/src/main/request_handler/customer_request_handler/Search_Customer_Request_handler.java @@ -0,0 +1,64 @@ +package main.request_handler.customer_request_handler; + +import main.Operators_Login_Control; +import main.config.Communication_Rules; +import main.config.requests.Search_Customer_Request; +import main.customer.Customer_Profile; +import main.customer.Customers; +import main.exception.Customer_Does_Not_Exit_Exception; + +import java.io.*; +import java.net.Socket; +import java.util.ArrayList; + +public class Search_Customer_Request_handler implements Runnable{ + private final Socket connection_socket; + private BufferedReader in; + private PrintWriter printWriter; + + public Search_Customer_Request_handler(Socket connection_socket,BufferedReader in) { + this.connection_socket = connection_socket; + this.in = in; + try { + this.printWriter = new PrintWriter(this.connection_socket.getOutputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void run() { + try { + Search_Customer_Request search_customer_request = new Search_Customer_Request(this.in); + + if (Operators_Login_Control.session_key_string_verification(search_customer_request.get_logged_In_username(),search_customer_request.get_login_session_key_string())) { + String search_String = search_customer_request.get_search_string(); + ArrayList customer_profiles = Customers.search_customer(search_String); + + this.printWriter.println("" + Communication_Rules.OPERATION_SUCCESSFUL); + this.printWriter.flush(); + + this.printWriter.println("" + customer_profiles.size()); + for (Customer_Profile customer_profile : customer_profiles) { + this.printWriter.println(customer_profile.toString()); + } + this.printWriter.flush(); + + } else { + this.printWriter.println("" + Communication_Rules.ACCESS_DENIED); + this.printWriter.flush(); + } + connection_socket.close(); + } catch (IOException e) { + e.printStackTrace(); + } catch (Customer_Does_Not_Exit_Exception e) { + try { + this.printWriter.println("" + Communication_Rules.OPERATION_FAILED); + this.printWriter.flush(); + connection_socket.close(); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } + } +} diff --git a/src/main/request_handler/operator_profile_request_handler/Add_Operator_Handler.java b/src/main/request_handler/operator_profile_request_handler/Add_Operator_Handler.java new file mode 100644 index 0000000..7297ecb --- /dev/null +++ b/src/main/request_handler/operator_profile_request_handler/Add_Operator_Handler.java @@ -0,0 +1,80 @@ +package main.request_handler.operator_profile_request_handler; + +import main.Operator_Profile; +import main.Operators; +import main.Operators_Login_Control; +import main.config.Communication_Rules; +import main.config.requests.operator_profile_requests.Add_Operator_Request; +import main.exception.AccessDeniedException; +import main.exception.Account_Does_Not_Exit_Exception; +import main.exception.UsernameTakenException; + +import java.io.*; +import java.net.Socket; +import java.net.SocketException; + +public class Add_Operator_Handler implements Runnable{ + private final Socket connection_socket; + private BufferedReader in; + private PrintWriter printWriter; + + public Add_Operator_Handler(Socket connection_socket, BufferedReader in) { + this.connection_socket = connection_socket; + this.in = in; + try { + this.printWriter = new PrintWriter(this.connection_socket.getOutputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void run() { + try { + Add_Operator_Request add_operator_request = new Add_Operator_Request(this.in); + + boolean authenticated = Operators_Login_Control.enhanced_verification(add_operator_request.get_logged_In_username(), + add_operator_request.get_login_session_key_string(),add_operator_request.get_verification_key()); + int logged_In_secure_level = Operators.get_operator(add_operator_request.get_logged_In_username()).get_secure_level(); + int secure_level_of_new_user = add_operator_request.get_secure_level(); + + if (!authenticated) { + throw new AccessDeniedException(); + } + + if (logged_In_secure_level <= 1 | logged_In_secure_level <= secure_level_of_new_user || secure_level_of_new_user >= 3) { + throw new AccessDeniedException(); + } + Operators.add_operator(add_operator_request.get_name(),add_operator_request.get_username(),add_operator_request.get_password(), + add_operator_request.get_secure_level(),add_operator_request.get_email(),add_operator_request.get_phone(), + add_operator_request.get_birthday()); + this.printWriter.println("" + Communication_Rules.OPERATION_SUCCESSFUL); + this.printWriter.flush(); + Operators.save(); + + Operator_Profile operator_profile = Operators.get_operator(add_operator_request.get_username()).get_operator_profile(); + this.printWriter.println(operator_profile.toString()); + this.printWriter.flush(); + connection_socket.close(); + } catch (SocketException ignored) { + + } catch (IOException | Account_Does_Not_Exit_Exception | AccessDeniedException e) { + e.printStackTrace(); + try { + this.printWriter.println("" + Communication_Rules.OPERATION_FAILED); + this.printWriter.flush(); + connection_socket.close(); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } catch (UsernameTakenException e) { + try { + this.printWriter.println("" + Communication_Rules.USERNAME_ALREADY_EXIST); + this.printWriter.flush(); + connection_socket.close(); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } + } +} diff --git a/src/main/request_handler/operator_profile_request_handler/Change_Profile_Handler.java b/src/main/request_handler/operator_profile_request_handler/Change_Profile_Handler.java new file mode 100644 index 0000000..edb52ac --- /dev/null +++ b/src/main/request_handler/operator_profile_request_handler/Change_Profile_Handler.java @@ -0,0 +1,203 @@ +package main.request_handler.operator_profile_request_handler; + +import main.Login_Profile; +import main.Operator; +import main.Operators; +import main.Operators_Login_Control; +import main.config.Communication_Rules; +import main.config.requests.operator_profile_requests.*; +import main.exception.AccessDeniedException; +import main.exception.Account_Does_Not_Exit_Exception; +import main.exception.UsernameTakenException; + +import java.io.*; +import java.net.Socket; +import java.net.SocketException; + +public class Change_Profile_Handler implements Runnable{ + private final Socket connection_socket; + private BufferedReader in; + private PrintWriter printWriter; + private int request; + + public Change_Profile_Handler(Socket connection_socket, BufferedReader in,int request) { + this.connection_socket = connection_socket; + this.in = in; + try { + this.printWriter = new PrintWriter(this.connection_socket.getOutputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + this.request = request; + } + + private void change_password_request_handler (Change_Profile_Request change_profile_request) throws Account_Does_Not_Exit_Exception, AccessDeniedException, IOException { + Change_Password_Request change_password_request = new Change_Password_Request(change_profile_request.get_logged_In_username(),change_profile_request.get_username(), + change_profile_request.get_verification_key(),this.in.readLine(),change_profile_request.get_login_session_key_string()); + int logged_In_User_Secure_Level = Operators.get_secure_level(change_profile_request.get_logged_In_username()); + int changing_User_Secure_Level = Operators.get_secure_level(change_profile_request.get_username()); + if (logged_In_User_Secure_Level <= 1 && !change_profile_request.is_change_self_profile()) { + throw new AccessDeniedException(); + } + if (logged_In_User_Secure_Level <= 2 && !change_profile_request.is_change_self_profile() && logged_In_User_Secure_Level <= changing_User_Secure_Level) { + throw new AccessDeniedException(); + } + Operators.change_password(change_password_request.get_username(),change_password_request.get_new_password()); + } + + private void change_birthday_request_handler(Change_Profile_Request change_profile_request) throws Account_Does_Not_Exit_Exception, AccessDeniedException, IOException { + Change_Birthday_Request change_birthday_request = new Change_Birthday_Request(change_profile_request.get_logged_In_username(),change_profile_request.get_username(),this.in.readLine(), + change_profile_request.get_verification_key(),change_profile_request.get_login_session_key_string()); + int logged_In_User_Secure_Level = Operators.get_secure_level(change_profile_request.get_logged_In_username()); + int changing_User_Secure_Level = Operators.get_secure_level(change_profile_request.get_username()); + if (logged_In_User_Secure_Level <= 1) { + throw new AccessDeniedException(); + } + if (logged_In_User_Secure_Level <= 2 && !change_profile_request.is_change_self_profile() && logged_In_User_Secure_Level <= changing_User_Secure_Level) { + throw new AccessDeniedException(); + } + Operators.change_birthday(change_birthday_request.get_username(),change_birthday_request.get_new_birthday()); + } + + private void change_phone_request_handler(Change_Profile_Request change_profile_request) throws Account_Does_Not_Exit_Exception, AccessDeniedException, IOException { + Change_Phone_Request change_phone_request = new Change_Phone_Request(change_profile_request.get_logged_In_username(),change_profile_request.get_username(),this.in.readLine(), + change_profile_request.get_verification_key(),change_profile_request.get_login_session_key_string()); + int logged_In_User_Secure_Level = Operators.get_secure_level(change_profile_request.get_logged_In_username()); + int changing_User_Secure_Level = Operators.get_secure_level(change_profile_request.get_username()); + if (logged_In_User_Secure_Level <= 1 && !change_profile_request.is_change_self_profile()) { + throw new AccessDeniedException(); + } + if (logged_In_User_Secure_Level <= 0) { + throw new AccessDeniedException(); + } + if (logged_In_User_Secure_Level <= 2 && !change_profile_request.is_change_self_profile() && logged_In_User_Secure_Level <= changing_User_Secure_Level) { + throw new AccessDeniedException(); + } + Operators.change_phone(change_phone_request.get_username(),change_phone_request.get_new_phone()); + } + + private void change_email_request_handler(Change_Profile_Request change_profile_request) throws Account_Does_Not_Exit_Exception, AccessDeniedException, IOException { + Change_Email_Request change_email_request = new Change_Email_Request(change_profile_request.get_logged_In_username(),change_profile_request.get_username(),this.in.readLine(), + change_profile_request.get_verification_key(),change_profile_request.get_login_session_key_string()); + int logged_In_User_Secure_Level = Operators.get_secure_level(change_profile_request.get_logged_In_username()); + int changing_User_Secure_Level = Operators.get_secure_level(change_profile_request.get_username()); + if (logged_In_User_Secure_Level <= 1 && !change_profile_request.is_change_self_profile()) { + throw new AccessDeniedException(); + } + if (logged_In_User_Secure_Level <= 0) { + throw new AccessDeniedException(); + } + if (logged_In_User_Secure_Level <= 2 && !change_profile_request.is_change_self_profile() && logged_In_User_Secure_Level <= changing_User_Secure_Level) { + throw new AccessDeniedException(); + } + Operators.change_email(change_email_request.get_username(),change_email_request.get_new_email()); + } + + private void change_secure_level_request_handler(Change_Profile_Request change_profile_request) throws Account_Does_Not_Exit_Exception, AccessDeniedException, IOException { + Change_Secure_Level_Request change_secure_level_request = new Change_Secure_Level_Request(change_profile_request.get_logged_In_username(),change_profile_request.get_username(), + this.in.readLine(),change_profile_request.get_verification_key(),change_profile_request.get_login_session_key_string()) ; + int logged_In_User_Secure_Level = Operators.get_secure_level(change_profile_request.get_logged_In_username()); + int changing_User_Secure_Level = Operators.get_secure_level(change_profile_request.get_username()); + int secure_level_to_change_to = Integer.parseInt(change_secure_level_request.get_new_secure_level()); + if (change_profile_request.is_change_self_profile() || changing_User_Secure_Level >= 3 || secure_level_to_change_to >= 3) { + throw new AccessDeniedException(); + } + if (logged_In_User_Secure_Level <= 1) { + throw new AccessDeniedException(); + } + if (logged_In_User_Secure_Level <= 2 && ( logged_In_User_Secure_Level <= changing_User_Secure_Level || logged_In_User_Secure_Level <= secure_level_to_change_to)) { + throw new AccessDeniedException(); + } + Operators.change_secure_level(change_secure_level_request.get_username(),Integer.parseInt(change_secure_level_request.get_new_secure_level())); + } + + private void change_username_request_handler(Change_Profile_Request change_profile_request) throws Account_Does_Not_Exit_Exception, UsernameTakenException, AccessDeniedException, IOException { + Change_Username_Request change_username_request = new Change_Username_Request(change_profile_request.get_logged_In_username(),change_profile_request.get_username(),this.in.readLine(), + change_profile_request.get_verification_key(),change_profile_request.get_login_session_key_string()) ; + int logged_In_User_Secure_Level = Operators.get_secure_level(change_profile_request.get_logged_In_username()); + int changing_User_Secure_Level = Operators.get_secure_level(change_profile_request.get_username()); + if (logged_In_User_Secure_Level <= 1 && !change_profile_request.is_change_self_profile()) { + throw new AccessDeniedException(); + } + if (logged_In_User_Secure_Level <= 0) { + throw new AccessDeniedException(); + } + if (logged_In_User_Secure_Level <= 2 && !change_profile_request.is_change_self_profile() && logged_In_User_Secure_Level <= changing_User_Secure_Level) { + throw new AccessDeniedException(); + } + Operators_Login_Control.change_username_while_logged_In(change_username_request.get_username(),change_username_request.get_new_username()); + } + + private void change_name_request_handler(Change_Profile_Request change_profile_request) throws Account_Does_Not_Exit_Exception, AccessDeniedException, IOException { + Change_Name_Request change_name_request = new Change_Name_Request(change_profile_request.get_logged_In_username(),change_profile_request.get_username(),this.in.readLine(), + change_profile_request.get_verification_key(),change_profile_request.get_login_session_key_string()); + int logged_In_User_Secure_Level = Operators.get_secure_level(change_profile_request.get_logged_In_username()); + int changing_User_Secure_Level = Operators.get_secure_level(change_profile_request.get_username()); + if (logged_In_User_Secure_Level <= 1) { + throw new AccessDeniedException(); + } + if (logged_In_User_Secure_Level <= 2 && !change_profile_request.is_change_self_profile() && logged_In_User_Secure_Level <= changing_User_Secure_Level) { + throw new AccessDeniedException(); + } + Operators.change_name(change_name_request.get_username(),change_name_request.get_new_name()); + } + + @Override + public void run() { + try { + Change_Profile_Request change_profile_request = new Change_Profile_Request(this.in); + + if (Operators_Login_Control.enhanced_verification(change_profile_request.get_logged_In_username(), + change_profile_request.get_login_session_key_string(),change_profile_request.get_verification_key())) { + + Login_Profile login_profile = Operators_Login_Control.get_login_profile(change_profile_request.get_logged_In_username()); + Operator changed_operator = Operators.get_operator(change_profile_request.get_username()); + + switch (this.request) { + case Communication_Rules.CHANGE_PASSWORD_REQUEST: + change_password_request_handler(change_profile_request);break; + case Communication_Rules.CHANGE_BIRTHDAY_REQUEST: + change_birthday_request_handler(change_profile_request);break; + case Communication_Rules.CHANGE_PHONE_REQUEST: + change_phone_request_handler(change_profile_request);break; + case Communication_Rules.CHANGE_EMAIL_REQUEST: + change_email_request_handler(change_profile_request);break; + case Communication_Rules.CHANGE_SECURE_LEVEL_REQUEST: + change_secure_level_request_handler(change_profile_request);break; + case Communication_Rules.CHANGE_USERNAME_REQUEST: + change_username_request_handler(change_profile_request);break; + case Communication_Rules.CHANGE_NAME_REQUEST: + change_name_request_handler(change_profile_request);break; + } + this.printWriter.println("" + Communication_Rules.OPERATION_SUCCESSFUL); + this.printWriter.flush(); + Operators.save(); + this.printWriter.println(changed_operator.get_operator_profile().toString()); + this.printWriter.flush(); + } else { + this.printWriter.println("" + Communication_Rules.OPERATION_FAILED); + this.printWriter.flush(); + } + connection_socket.close(); + } catch (SocketException ignored) { + + } catch (Account_Does_Not_Exit_Exception | AccessDeniedException | IOException e) { + e.printStackTrace(); + try { + this.printWriter.println("" + Communication_Rules.OPERATION_FAILED); + this.printWriter.flush(); + connection_socket.close(); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } catch (UsernameTakenException e) { + try { + this.printWriter.println("" + Communication_Rules.USERNAME_ALREADY_EXIST); + this.printWriter.flush(); + connection_socket.close(); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } + } +} diff --git a/src/main/request_handler/operator_profile_request_handler/Delete_Operator_Handler.java b/src/main/request_handler/operator_profile_request_handler/Delete_Operator_Handler.java new file mode 100644 index 0000000..44924f5 --- /dev/null +++ b/src/main/request_handler/operator_profile_request_handler/Delete_Operator_Handler.java @@ -0,0 +1,66 @@ +package main.request_handler.operator_profile_request_handler; + +import main.Operators; +import main.Operators_Login_Control; +import main.config.Communication_Rules; +import main.config.requests.operator_profile_requests.Delete_Operator_Request; +import main.exception.AccessDeniedException; +import main.exception.Account_Does_Not_Exit_Exception; + +import java.io.*; +import java.net.Socket; +import java.net.SocketException; + +public class Delete_Operator_Handler implements Runnable{ + private final Socket connection_socket; + private BufferedReader in; + private PrintWriter printWriter; + + public Delete_Operator_Handler(Socket connection_socket, BufferedReader in) { + this.connection_socket = connection_socket; + this.in = in; + try { + this.printWriter = new PrintWriter(this.connection_socket.getOutputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + } + @Override + public void run() { + try { + Delete_Operator_Request delete_operator_request = new Delete_Operator_Request(this.in); + + boolean authenticated = Operators_Login_Control.enhanced_verification(delete_operator_request.get_logged_In_username(), + delete_operator_request.get_login_session_key_string(),delete_operator_request.get_verification_key()); + int logged_In_secure_level = Operators.get_operator(delete_operator_request.get_logged_In_username()).get_secure_level(); + int delete_secure_level = Operators.get_operator(delete_operator_request.get_username()).get_secure_level(); + if (authenticated && logged_In_secure_level >= 2 && delete_secure_level < 3 && logged_In_secure_level > delete_secure_level) { + + Operators.delete_operator(delete_operator_request.get_username()); + + this.printWriter.println("" + Communication_Rules.OPERATION_SUCCESSFUL); + this.printWriter.flush(); + Operators.save(); + } else { + try { + this.printWriter.println("" + Communication_Rules.OPERATION_FAILED); + this.printWriter.flush(); + throw new AccessDeniedException(); + } catch (AccessDeniedException e) { + e.printStackTrace(); + } + } + connection_socket.close(); + } catch (SocketException ignored) { + + } catch (IOException | Account_Does_Not_Exit_Exception e) { + try { + this.printWriter.println("" + Communication_Rules.OPERATION_FAILED); + this.printWriter.flush(); + connection_socket.close(); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } + } +} diff --git a/src/main/request_handler/operator_profile_request_handler/Get_Operator_Profiles_Handler.java b/src/main/request_handler/operator_profile_request_handler/Get_Operator_Profiles_Handler.java new file mode 100644 index 0000000..e8b88dd --- /dev/null +++ b/src/main/request_handler/operator_profile_request_handler/Get_Operator_Profiles_Handler.java @@ -0,0 +1,67 @@ +package main.request_handler.operator_profile_request_handler; + +import main.Operator_Profile; +import main.Operators; +import main.Operators_Login_Control; +import main.config.Communication_Rules; +import main.config.requests.operator_profile_requests.Get_Operator_Profiles_Request; +import main.exception.Account_Does_Not_Exit_Exception; + +import java.io.*; +import java.net.Socket; +import java.net.SocketException; +import java.util.HashMap; +import java.util.Set; + +public class Get_Operator_Profiles_Handler implements Runnable{ + private final Socket connection_socket; + private BufferedReader in; + private PrintWriter printWriter; + + public Get_Operator_Profiles_Handler(Socket connection_socket,BufferedReader in) { + this.connection_socket = connection_socket; + this.in = in; + try { + this.printWriter = new PrintWriter(this.connection_socket.getOutputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void run() { + try { + Get_Operator_Profiles_Request get_operator_profiles_request = new Get_Operator_Profiles_Request(this.in); + + if (Operators_Login_Control.session_key_string_verification(get_operator_profiles_request.get_logged_In_username(),get_operator_profiles_request.get_login_session_key_string())) { + this.printWriter.println("" + Communication_Rules.OPERATION_SUCCESSFUL); + this.printWriter.flush(); + + HashMap profiles = Operators.get_operator_profiles(get_operator_profiles_request.get_logged_In_username()); + Set keys = profiles.keySet(); + this.printWriter.println("" + keys.size()); + for(String key : keys) { + this.printWriter.println(profiles.get(key).toString()); + } + this.printWriter.flush(); + + } else { + this.printWriter.println("" + Communication_Rules.OPERATION_FAILED); + this.printWriter.flush(); + } + connection_socket.close(); + } catch (SocketException ignored) { + + } catch (IOException e) { + e.printStackTrace(); + } catch (Account_Does_Not_Exit_Exception e) { + try { + this.printWriter.println("" + Communication_Rules.OPERATION_FAILED); + this.printWriter.flush(); + connection_socket.close(); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } + } +} diff --git a/src/main/ui/Server_Command_Line_Handler.java b/src/main/ui/Server_Command_Line_Handler.java new file mode 100644 index 0000000..d99a068 --- /dev/null +++ b/src/main/ui/Server_Command_Line_Handler.java @@ -0,0 +1,332 @@ +package main.ui; + +import main.Operator; +import main.Operator_Profile; +import main.Operators; +import main.Operators_Login_Control; +import main.exception.Account_Does_Not_Exit_Exception; +import main.exception.UsernameTakenException; + +import java.util.HashMap; +import java.util.Scanner; + +public class Server_Command_Line_Handler implements Runnable{ + private final Scanner user; + + public Server_Command_Line_Handler() { + this.user = new Scanner(System.in); + } + + @Override + public void run() { + while (true) { + String command = this.user.next().toLowerCase(); + switch (command) { + case "help": help();break; + case "stop": stop_server();break; + case "addoperator": add_Operator();break; + case "deloperator": delete_Operator();break; + case "list": list();break; + case "change":change();break; + default: + } + } + } + + private void help() { + System.out.println("Commands Available:"); + System.out.printf("%26s: %s\n","stop","stops the server"); + System.out.printf("%26s: %s\n","addoperator","adds a new operator"); + System.out.printf("%26s: %s\n","deloperator","delete operator"); + System.out.printf("%26s: %s\n","list operators","list all operators"); + System.out.printf("%26s: %s\n","list operator [username]","list operator detail"); + System.out.printf("%26s: %s\n","change operator","change operator profile"); + } + + private void list() { + String input = this.user.next(); + if (input.equalsIgnoreCase("operators")) { + this.user.nextLine(); + HashMap operator_profiles = Operators.get_all_operator_profiles_cmd(); + for (String username: operator_profiles.keySet()) { + Operator_Profile profile = operator_profiles.get(username); + System.out.printf("Operator %12s | username: %12s | Secure Level: %d\n",profile.get_name(),profile.get_username(),profile.get_secure_level()); + } + System.out.println(); + System.out.println("Enter \"list operator [Username]\" to show detailed information"); + System.out.println(); + } else if (input.equalsIgnoreCase("operator")) { + input = this.user.next(); + this.user.nextLine(); + try { + Operator operator = Operators.get_operator(input); + list_operator_info(operator); + } catch (Account_Does_Not_Exit_Exception e) { + System.out.println("The user name entered does not exist!"); + } + } + } + + private void change() { + String input = this.user.next(); + if (input.equalsIgnoreCase("operator")) { + this.user.nextLine(); + boolean abort = false; + boolean user_exist = false; + int num = 3; + String username = ""; + while (!user_exist && num > 0) { + System.out.println("Enter the username of the Operator:"); + username = this.user.next(); + this.user.nextLine(); + user_exist = Operators.check_username(username); + if (!user_exist) { + System.out.println("The user name entered does not exist. Please Enter it again!"); + } + num--; + if (num <= 0) { + System.out.println("Pleas check your user name. To list the Operators, type: list operators"); + abort = true; + } + } + if (!abort) { + try { + Operator operator = Operators.get_operator(username); + boolean loop = true; + while (loop) { + System.out.println("Enter the index of the fields to change you want to change:"); + list_operator_info(operator); + + String sel = this.user.next(); + this.user.nextLine(); + switch (sel) { + case "1":change_name(operator);break; + case "2":change_username(operator);break; + case "3":change_password(operator);break; + case "4":change_secure_level(operator);break; + case "5":change_birthday(operator);break; + case "6":change_email(operator);break; + case "7":change_phone(operator);break; + default: System.out.println("Please enter an integer between 1 - 7 inclusive!"); + } + Operators.save(); + System.out.println("Do you wish to continue? Y/N :"); + if (!this.user.next().equalsIgnoreCase("y")) { + loop = false; + } + } + } catch (Account_Does_Not_Exit_Exception e) { + e.printStackTrace(); + } + } + System.out.println("Bye!~"); + } + } + + private void list_operator_info(Operator operator) { + System.out.printf("1 - %12s: %s\n","Name", operator.get_name()); + System.out.printf("2 - %12s: %s\n","Username", operator.get_username()); + System.out.printf("3 - %12s: %s\n","Password", "********"); + System.out.printf("4 - %12s: %s\n","Secure_Level", operator.get_secure_level()); + System.out.printf("5 - %12s: %s\n","Birthday", operator.get_birthday()); + System.out.printf("6 - %12s: %s\n","Email", operator.get_email()); + System.out.printf("7 - %12s: %s\n","Phone", operator.get_phone()); + } + + private void change_name(Operator operator) { + System.out.println("Enter the new name"); + String name = this.user.nextLine(); + operator.set_name(name); + System.out.println("Name successfully changed!"); + } + + private void change_username(Operator operator) { + System.out.println("Enter the new username"); + String username = this.user.next(); + this.user.nextLine(); + Operators_Login_Control.change_username_in_logged_in_list(operator.get_username(),username); + operator.set_username(username); + System.out.println("Username successfully changed!"); + } + + private void change_password(Operator operator) { + boolean flag = true; + String password = ""; + while (flag) { + System.out.println("Enter the new password (no spaces):"); + password = this.user.next(); + this.user.nextLine(); + System.out.println("Enter the password again (no spaces):"); + String confirm_password = this.user.next(); + this.user.nextLine(); + flag = !password.equals(confirm_password); + if (flag) { + System.out.println("Passwords does not match! Pleas enter it again"); + System.out.println(); + } + } + operator.set_password(password); + System.out.println("Password successfully changed!"); + } + + private void change_secure_level(Operator operator) { + boolean flag = true; + int secure_level = -1; + while (flag) { + System.out.println("Enter the new secure_level (0 - 3):"); + try { + secure_level = Integer.parseInt(this.user.next()); + this.user.nextLine(); + flag = secure_level < 0 || secure_level > 3; + if (flag) { + System.out.println("Secure Level Must be an integer between 0 - 3 inclusive! Pleas enter it again"); + } + } catch (NumberFormatException e) { + System.out.println("Secure Level Must be an integer! Pleas enter it again"); + this.user.nextLine(); + } + } + operator.set_secure_level(secure_level); + System.out.println("Secure Level successfully changed!"); + } + + private void change_birthday(Operator operator) { + System.out.println("Enter the new birthday (YYYY/MM/DD no spaces):"); + String birthday = this.user.next(); + this.user.nextLine(); + operator.set_birthday(birthday); + System.out.println("Birthday successfully changed!"); + } + + private void change_email(Operator operator) { + System.out.println("Enter the new email address (example@domain):"); + String email = this.user.next(); + this.user.nextLine(); + operator.set_email(email); + System.out.println("Email address successfully changed!"); + } + + private void change_phone(Operator operator) { + System.out.println("Enter the new phone number (no spaces):"); + String phone = this.user.next(); + this.user.nextLine(); + operator.set_phone(phone); + System.out.println("Phone number successfully changed!"); + } + + private void delete_Operator() { + this.user.nextLine(); + boolean abort = false; + boolean user_exist = false; + int num = 3; + String username = ""; + while (!user_exist && num > 0) { + System.out.println("Enter the username of the Operator:"); + username = this.user.next(); + this.user.nextLine(); + user_exist = Operators.check_username(username); + if (!user_exist) { + System.out.println("The user name entered does not exist. Please Enter it again!"); + } + num--; + if (num <= 0) { + System.out.println("Pleas check your user name. To list the Operators, type: list operators"); + abort = true; + } + } + if (!abort) { + try { + System.out.println("Please confirm the deletion of Operator " + Operators.get_operator(username).get_name() + + " with username " + username + ". Enter Y/y to delete, N/n to abort"); + abort = !this.user.next().equalsIgnoreCase("y"); + this.user.nextLine(); + if (!abort) { + Operators_Login_Control.logout(username); + Operators.delete_operator(username); + System.out.println("Account deleted"); + Operators.save(); + } else { + System.out.println("Aborted"); + } + } catch (Account_Does_Not_Exit_Exception e) { + e.printStackTrace(); + } + } + } + + private void add_Operator() { + this.user.nextLine(); + boolean flag = true; + System.out.println("Enter the name of the new user:"); + String name = this.user.nextLine(); + System.out.println("Enter the username (no spaces):"); + String username = this.user.next(); + this.user.nextLine(); + String password = ""; + while (flag) { + System.out.println("Enter the password (no spaces):"); + password = this.user.next(); + this.user.nextLine(); + System.out.println("Enter the password again (no spaces):"); + String confirm_password = this.user.next(); + this.user.nextLine(); + flag = !password.equals(confirm_password); + if (flag) { + System.out.println("Passwords does not match! Pleas enter it again"); + System.out.println(); + } + } + flag = true; + int secure_level = -1; + while (flag) { + System.out.println("Enter the secure_level (0 - 3):"); + try { + secure_level = Integer.parseInt(this.user.next()); + this.user.nextLine(); + flag = secure_level < 0 || secure_level > 3; + if (flag) { + System.out.println("Secure Level Must be an integer between 0 - 3 inclusive! Pleas enter it again"); + } + } catch (NumberFormatException e) { + System.out.println("Secure Level Must be an integer! Pleas enter it again"); + this.user.nextLine(); + } + } + System.out.println("Enter the birthday (YYYY/MM/DD no spaces):"); + String birthday = this.user.next(); + this.user.nextLine(); + System.out.println("Enter the email address (example@domain):"); + String email = this.user.next(); + this.user.nextLine(); + System.out.println("Enter the phone number (no spaces):"); + String phone = this.user.next(); + this.user.nextLine(); + System.out.println("Is this information correct?"); + System.out.printf("%12s: %s\n","Name", name); + System.out.printf("%12s: %s\n","Username", username); + System.out.printf("%12s: %s\n","Password", password); + System.out.printf("%12s: %s\n","Secure_Level", secure_level); + System.out.printf("%12s: %s\n","Birthday", birthday); + System.out.printf("%12s: %s\n","Email", email); + System.out.printf("%12s: %s\n","Phone", phone); + System.out.print("Enter Y/y to create account, N/n to abort: "); + String reply = this.user.next(); + this.user.nextLine(); + if (reply.equalsIgnoreCase("y")) { + try { + Operators.add_operator(name,username,password,secure_level,email,phone,birthday); + System.out.println("Account created!"); + Operators.save(); + } catch (UsernameTakenException e) { + System.err.println("Failed to create account! Username Already Exits!"); + } + } else { + System.out.println("Aborted!"); + } + } + + private void stop_server() { + this.user.close(); + System.exit(0); + } +} diff --git a/src/main/utility/EmailSender.java b/src/main/utility/EmailSender.java new file mode 100644 index 0000000..38ec08f --- /dev/null +++ b/src/main/utility/EmailSender.java @@ -0,0 +1,75 @@ +package main.utility; + +import main.config.File_Path; + +import javax.mail.*; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import java.io.*; +import java.util.Properties; + +// cited from https://www.mkyong.com/java/javamail-api-sending-email-via-gmail-smtp-example/ + +public class EmailSender { + private static final String FILE_NAME = File_Path.getPATH() + "Email_Config.txt"; + private static String server_ip = ""; + private static String server_domain = ""; + private static String username = ""; + private static String password = ""; + + public static void init() { + try { + FileInputStream f = new FileInputStream(new File(FILE_NAME)); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(f)); + + String email_config = bufferedReader.readLine().split(" ")[0]; + String[] config = email_config.split(","); + server_ip = config[0]; + server_domain = config[1]; + username = config[2]; + password = config[3]; + } catch (IOException e) { + e.printStackTrace(); + }; + } + + public static void send(String email, String messages) { +// final String username = "donotreplyfromfan"; +// final String password = "hellofan"; + final String username = EmailSender.username; + final String password = EmailSender.password; + Properties prop = new Properties(); + helper1(prop); + Session session = Session.getInstance(prop, new javax.mail.Authenticator() { + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password); + } + }); + try { + Message message = new MimeMessage(session); + helper2(message, email, messages); + Transport.send(message); + System.err.println("Email Sent to " + email + ":\n" + messages + "\n"); + } catch (MessagingException e) { + e.printStackTrace(); + } + } + + private static void helper1(Properties prop) { +// prop.put("mail.smtp.host", "smtp.gmail.com"); +// prop.put("mail.smtp.host", "in-v3.mailjet.com"); + prop.put("mail.smtp.host", EmailSender.server_ip); + prop.put("mail.smtp.port", "587"); + prop.put("mail.smtp.auth", "true"); + prop.put("mail.smtp.starttls.enable", "true"); //TLS + } + + + private static void helper2(Message message, String email, String messages) throws MessagingException { +// message.setFrom(new InternetAddress("from@gmail.com")); + message.setFrom(new InternetAddress(EmailSender.username.split("@")[0] + "@" + EmailSender.server_domain)); + message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email)); + message.setSubject("Password Reset"); + message.setText(messages); + } +} diff --git a/src/main/utility/Networking_Config.java b/src/main/utility/Networking_Config.java new file mode 100644 index 0000000..938715e --- /dev/null +++ b/src/main/utility/Networking_Config.java @@ -0,0 +1,31 @@ +package main.utility; + +import main.config.File_Path; + +import java.io.*; + +public class Networking_Config { + private static final String FILE_NAME = File_Path.getPATH() + "Networking_Config.txt"; + public static int PORT; + public static String IP = ""; +// public static final String IP = "localhost"; +// public static final String IP = "192.168.1.67"; +// public static final String IP = "192.168.1.64"; +// public static final String IP = "192.168.1.71"; +// public static final String IP = " 207.6.48.156"; +// public static final String IP = "106.14.205.210"; + + public static void init() { + try { + FileInputStream f = new FileInputStream(new File(FILE_NAME)); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(f)); + + String networking_config = bufferedReader.readLine().split(" ")[0]; + String[] ip_port = networking_config.split(","); + IP = ip_port[0]; + PORT = Integer.parseInt(ip_port[1]); + } catch (IOException e) { + e.printStackTrace(); + }; + } +} diff --git a/src/main/utility/Random_String_Generator.java b/src/main/utility/Random_String_Generator.java new file mode 100644 index 0000000..b13846a --- /dev/null +++ b/src/main/utility/Random_String_Generator.java @@ -0,0 +1,28 @@ +package main.utility; + +import java.security.SecureRandom; + +public class Random_String_Generator { + public static String get_random_string (int length) { + String s = ""; + if (length > 0) { + SecureRandom rand = new SecureRandom(); + for (int i = 0; i < length; i++) { + if (rand.nextInt(2) > 0) { + s = s + "" + rand.nextInt(10); + } else { + s = s + get_random_letter(rand); + } + } + } + return s; + } + + private static char get_random_letter(SecureRandom rand) { + if (rand.nextInt(2) > 0) { + return (char) ('A' + rand.nextInt(26)); + } else { + return (char) ('a' + rand.nextInt(26)); + } + } +} diff --git a/src/main/utility/ServerSocketFactoryGenerator.java b/src/main/utility/ServerSocketFactoryGenerator.java new file mode 100644 index 0000000..accf2b3 --- /dev/null +++ b/src/main/utility/ServerSocketFactoryGenerator.java @@ -0,0 +1,35 @@ +package main.utility; + +import javax.net.ServerSocketFactory; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLServerSocketFactory; +import java.io.FileInputStream; +import java.security.KeyStore; + +public class ServerSocketFactoryGenerator { + public static ServerSocketFactory getServerSocketFactory() { + SSLServerSocketFactory ssf = null; + try { + // set up key manager to do server authentication + SSLContext ctx; + KeyManagerFactory kmf; + KeyStore ks; + char[] passphrase = "passphrase".toCharArray(); + + ctx = SSLContext.getInstance("TLS"); + kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); + ks = KeyStore.getInstance("PKCS12"); + + ks.load(new FileInputStream("testkeys"), passphrase); + kmf.init(ks, passphrase); + ctx.init(kmf.getKeyManagers(), null, null); + + ssf = ctx.getServerSocketFactory(); + return ssf; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } +}