removed test email server
This commit is contained in:
commit
dc380ff73c
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
16
.idea/checkstyle-idea.xml
Normal file
16
.idea/checkstyle-idea.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CheckStyle-IDEA">
|
||||
<option name="configuration">
|
||||
<map>
|
||||
<entry key="checkstyle-version" value="8.34" />
|
||||
<entry key="copy-libs" value="true" />
|
||||
<entry key="location-0" value="BUNDLED:(bundled):Sun Checks" />
|
||||
<entry key="location-1" value="BUNDLED:(bundled):Google Checks" />
|
||||
<entry key="scan-before-checkin" value="false" />
|
||||
<entry key="scanscope" value="JavaOnly" />
|
||||
<entry key="suppress-errors" value="false" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
10
.idea/libraries/lib.xml
Normal file
10
.idea/libraries/lib.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<component name="libraryTable">
|
||||
<library name="lib">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/lib" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib" recursive="false" />
|
||||
</library>
|
||||
</component>
|
||||
6
.idea/misc.xml
Normal file
6
.idea/misc.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="corretto-1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Project_One_Server.iml" filepath="$PROJECT_DIR$/Project_One_Server.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
10
.idea/runConfigurations.xml
Normal file
10
.idea/runConfigurations.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
17
Project_One_Server.iml
Normal file
17
Project_One_Server.iml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="CheckStyle-IDEA-Module">
|
||||
<option name="configuration">
|
||||
<map />
|
||||
</option>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="lib" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
BIN
lib/activation.jar
Normal file
BIN
lib/activation.jar
Normal file
Binary file not shown.
BIN
lib/javax.mail-1.6.2.jar
Normal file
BIN
lib/javax.mail-1.6.2.jar
Normal file
Binary file not shown.
1
out/production/Project_One/data/Email_Config.txt
Normal file
1
out/production/Project_One/data/Email_Config.txt
Normal file
@ -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
|
||||
BIN
out/production/Project_One/data/EncryptionKeyFile
Normal file
BIN
out/production/Project_One/data/EncryptionKeyFile
Normal file
Binary file not shown.
0
out/production/Project_One/data/Frames
Normal file
0
out/production/Project_One/data/Frames
Normal file
1
out/production/Project_One/data/Networking_Config.txt
Normal file
1
out/production/Project_One/data/Networking_Config.txt
Normal file
@ -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)
|
||||
BIN
out/production/Project_One/data/Operators
Normal file
BIN
out/production/Project_One/data/Operators
Normal file
Binary file not shown.
BIN
out/production/Project_One/data/Server_Private_Key
Normal file
BIN
out/production/Project_One/data/Server_Private_Key
Normal file
Binary file not shown.
BIN
out/production/Project_One/data/Server_Public_Key
Normal file
BIN
out/production/Project_One/data/Server_Public_Key
Normal file
Binary file not shown.
1
out/production/Project_One_Server/data/Email_Config.txt
Normal file
1
out/production/Project_One_Server/data/Email_Config.txt
Normal file
@ -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
|
||||
BIN
out/production/Project_One_Server/data/EncryptionKeyFile
Normal file
BIN
out/production/Project_One_Server/data/EncryptionKeyFile
Normal file
Binary file not shown.
0
out/production/Project_One_Server/data/Frames
Normal file
0
out/production/Project_One_Server/data/Frames
Normal file
@ -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)
|
||||
BIN
out/production/Project_One_Server/data/Operators
Normal file
BIN
out/production/Project_One_Server/data/Operators
Normal file
Binary file not shown.
BIN
out/production/Project_One_Server/data/Server_Private_Key
Normal file
BIN
out/production/Project_One_Server/data/Server_Private_Key
Normal file
Binary file not shown.
BIN
out/production/Project_One_Server/data/Server_Public_Key
Normal file
BIN
out/production/Project_One_Server/data/Server_Public_Key
Normal file
Binary file not shown.
BIN
out/production/Project_One_Server/main/Hashing.class
Normal file
BIN
out/production/Project_One_Server/main/Hashing.class
Normal file
Binary file not shown.
BIN
out/production/Project_One_Server/main/Login_Profile.class
Normal file
BIN
out/production/Project_One_Server/main/Login_Profile.class
Normal file
Binary file not shown.
BIN
out/production/Project_One_Server/main/Operator.class
Normal file
BIN
out/production/Project_One_Server/main/Operator.class
Normal file
Binary file not shown.
BIN
out/production/Project_One_Server/main/Operator_Profile.class
Normal file
BIN
out/production/Project_One_Server/main/Operator_Profile.class
Normal file
Binary file not shown.
BIN
out/production/Project_One_Server/main/Operators.class
Normal file
BIN
out/production/Project_One_Server/main/Operators.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
out/production/Project_One_Server/main/Server_Main.class
Normal file
BIN
out/production/Project_One_Server/main/Server_Main.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
out/production/Project_One_Server/main/config/File_Path.class
Normal file
BIN
out/production/Project_One_Server/main/config/File_Path.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
out/production/Project_One_Server/main/customer/Customer.class
Normal file
BIN
out/production/Project_One_Server/main/customer/Customer.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
out/production/Project_One_Server/main/customer/Customers.class
Normal file
BIN
out/production/Project_One_Server/main/customer/Customers.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
out/production/Project_One_Server/main/utility/EmailSender.class
Normal file
BIN
out/production/Project_One_Server/main/utility/EmailSender.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
src/data/Email_Config.txt
Normal file
1
src/data/Email_Config.txt
Normal file
@ -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
|
||||
BIN
src/data/EncryptionKeyFile
Normal file
BIN
src/data/EncryptionKeyFile
Normal file
Binary file not shown.
0
src/data/Frames
Normal file
0
src/data/Frames
Normal file
1
src/data/Networking_Config.txt
Normal file
1
src/data/Networking_Config.txt
Normal file
@ -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)
|
||||
BIN
src/data/Operators
Normal file
BIN
src/data/Operators
Normal file
Binary file not shown.
BIN
src/data/Server_Private_Key
Normal file
BIN
src/data/Server_Private_Key
Normal file
Binary file not shown.
BIN
src/data/Server_Public_Key
Normal file
BIN
src/data/Server_Public_Key
Normal file
Binary file not shown.
24
src/main/Hashing.java
Normal file
24
src/main/Hashing.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
52
src/main/Login_Profile.java
Normal file
52
src/main/Login_Profile.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
90
src/main/Operator.java
Normal file
90
src/main/Operator.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
93
src/main/Operator_Profile.java
Normal file
93
src/main/Operator_Profile.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
220
src/main/Operators.java
Normal file
220
src/main/Operators.java
Normal file
@ -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<Operator> list = new ArrayList<Operator>();
|
||||
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<String,Operator_Profile> get_operator_profiles(String username) throws Account_Does_Not_Exit_Exception {
|
||||
HashMap<String,Operator_Profile> operator_profiles = new HashMap<String,Operator_Profile>();
|
||||
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<String,Operator_Profile> get_all_operator_profiles_cmd() {
|
||||
HashMap<String,Operator_Profile> operator_profiles = new HashMap<String,Operator_Profile>();
|
||||
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<Operator>) 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
101
src/main/Operators_Login_Control.java
Normal file
101
src/main/Operators_Login_Control.java
Normal file
@ -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<String,Login_Profile> 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
35
src/main/Reset_Password_Count_Down.java
Normal file
35
src/main/Reset_Password_Count_Down.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
82
src/main/Server_Main.java
Normal file
82
src/main/Server_Main.java
Normal file
@ -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<Salable>(),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();
|
||||
// }
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user