Skip to content

Commit

Permalink
fetch user
Browse files Browse the repository at this point in the history
get list user when share file/folder
  • Loading branch information
huynhquangvinh01121999 committed Dec 23, 2021
1 parent a09c4ff commit 25a8ff9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
13 changes: 13 additions & 0 deletions LapTrinhMang_FTPSimulator/src/components/ListenThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,10 @@ public void run() {
System.out.println("Client[port " + getSocket().getPort() + "] said: " + message);
Files filesInfo = (Files) request.getObject();
FileEvent fileEvent = (FileEvent) request.getFileUpload();

new FileBLL().insertNewFile(filesInfo);

// convert byte sang file -> lại file lưu trên server
saveFile(fileEvent);
break;
}
Expand Down Expand Up @@ -602,6 +605,16 @@ public void run() {
}
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="FETCH_USERS">
case "FETCH_USERS": {
System.out.println("Client[port " + getSocket().getPort() + "] said: " + message);
String authenEmail = (String) request.getObject();
List<Users> listUsers = new UserBLL().getAllUser();
response("fetch_users_success", new HandleResult(listUsers));
break;
}
// </editor-fold>

default: {
System.out.println("Client[port " + getSocket().getPort() + "] said default: " + message);
response("test", "test");
Expand Down
6 changes: 5 additions & 1 deletion LapTrinhMang_FTPSimulator/src/components/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class Server {
// }
// }
// </editor-fold>

private static ExecutorService executor;
private static ServerSocket serverSocket;
private static int port;
Expand All @@ -59,8 +60,9 @@ public static void Start() {
System.out.println("Server is waiting for client on port " + port
+ "...");

executor = Executors.newFixedThreadPool(10);
executor = Executors.newFixedThreadPool(100); // giới hạn 10 client
executor.execute(new ServerUI());

listenClientConnect();
} catch (IOException ex) {
System.err.println("Server socket xảy ra lỗi khi khởi tạo" + ex);
Expand Down Expand Up @@ -92,10 +94,12 @@ private static void listenClientConnect() {
//------------------- DANH SÁCH CLIENT CONNECT TỚI SERVER ----------------
public static void registerClient(ListenThread listenThread) {
list_Client.add(listenThread);
System.out.println("Total client connect: " + list_Client.size());
}

public static void removeClientDisconnect(ListenThread listenThread) {
list_Client.remove(listenThread);
System.out.println("Total client connect: " + list_Client.size());
}

public static ArrayList<ListenThread> getListClient() {
Expand Down
3 changes: 2 additions & 1 deletion LapTrinhMang_FTPSimulator/src/middlewares/HandleVerify.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static HandleResult verifyRegisterUser(Users user) {
if (!existedEmail(user.getEmail())) {
int verifyCode = ThreadRandoms.generateCode(); // random ra 1 verify code
try {
// 1. mã code , 2. MailSender
new SendMail(verifyCode, new MailSender(user.getEmail()));
return new HandleResult(true, "Một mã xác thực vừa được gửi đến email của bạn!!!", verifyCode);
} catch (Exception ex) {
Expand All @@ -50,7 +51,7 @@ public static HandleResult verifyRegisterUser(Users user) {
}
return new HandleResult(false, "Họ và tên không được bỏ trống!!!");
}
return new HandleResult(false, "Tối thiểu tám ký tự.\nÍt nhất một chữ cái , một số, một ký tự in hoa, một ký tự đặc biệt (nếu có)!!!");
return new HandleResult(false, "Tối thiểu 8 ký tự.\nÍt nhất một chữ cái , một số, một ký tự in hoa, một ký tự đặc biệt (nếu có)!!!");
}
return new HandleResult(false, "Không được phép sử dụng email có tiền tố là anonymous!!!");
}
Expand Down
20 changes: 17 additions & 3 deletions LapTrinhMang_FTPSimulator/src/models/HandleResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ public class HandleResult implements Serializable {
private List<Permissions> ListPermissionses;
private List<FileShares> ListFileShared;
private List<FolderShares> ListFolderShared;
private List<Users> ListUsers;

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Dùng cho authenticate">
// 4 tham số: IsSuccessed - Message - User - Folder
public HandleResult(boolean IsSuccessed, String Message, Users User,
Folders Folder) {
Folders Folder) {
this.IsSuccessed = IsSuccessed;
this.Message = Message;
this.User = User;
Expand All @@ -47,8 +48,8 @@ public HandleResult(List<Folders> ListFolderChild, List<Files> ListFile) {

// 3 tham số: ListFileShareses - ListFolderShareses - ListPermissionses
public HandleResult(List<FileShares> ListFileShared, List<FolderShares> ListFolderShared,
List<Files> ListFileShareses, List<Folders> ListFolderShareses,
List<Permissions> ListPermissionses) {
List<Files> ListFileShareses, List<Folders> ListFolderShareses,
List<Permissions> ListPermissionses) {
this.ListFileShared = ListFileShared;
this.ListFolderShared = ListFolderShared;
this.ListFileShareses = ListFileShareses;
Expand Down Expand Up @@ -80,6 +81,11 @@ public HandleResult(boolean IsSuccessed, String Message) {
public HandleResult(boolean IsSuccessed) {
this.IsSuccessed = IsSuccessed;
}

// fetch Users
public HandleResult(List<Users> listUsers){
this.ListUsers = listUsers;
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Set - Get methods">
Expand All @@ -88,6 +94,14 @@ public List<Permissions> getListPermissionses() {
return ListPermissionses;
}

public List<Users> getListUsers() {
return ListUsers;
}

public void setListUsers(List<Users> ListUsers) {
this.ListUsers = ListUsers;
}

public List<FileShares> getListFileShared() {
return ListFileShared;
}
Expand Down

0 comments on commit 25a8ff9

Please sign in to comment.