diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUsersByEmailAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUsersByEmailAction.java new file mode 100755 index 00000000..058594f6 --- /dev/null +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetUsersByEmailAction.java @@ -0,0 +1,66 @@ +/* + * This file is part of the Wildfire Chat package. + * (c) Heavyrain2012 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +package com.xiaoleilu.loServer.action.admin; + +import cn.wildfirechat.common.APIPath; +import cn.wildfirechat.common.ErrorCode; +import cn.wildfirechat.pojos.InputGetUserInfo; +import cn.wildfirechat.pojos.InputOutputUserInfo; +import cn.wildfirechat.pojos.OutputUserInfoList; +import cn.wildfirechat.proto.WFCMessage; +import com.xiaoleilu.loServer.RestResult; +import com.xiaoleilu.loServer.annotation.HttpMethod; +import com.xiaoleilu.loServer.annotation.Route; +import com.xiaoleilu.loServer.handler.Request; +import com.xiaoleilu.loServer.handler.Response; +import io.netty.handler.codec.http.FullHttpRequest; +import io.netty.util.internal.StringUtil; + +import java.util.ArrayList; +import java.util.List; + +@Route(APIPath.User_Get_Email_Info) +@HttpMethod("POST") +public class GetUsersByEmailAction extends AdminAction { + + @Override + public boolean isTransactionAction() { + return true; + } + + @Override + public boolean action(Request request, Response response) { + if (request.getNettyRequest() instanceof FullHttpRequest) { + String email = getRequestBody(request.getNettyRequest(), String.class); + if (!StringUtil.isNullOrEmpty(email)) { + + List users = messagesStore.getUserInfosByEmail(email); + List list = new ArrayList<>(); + for (WFCMessage.User user : users) { + list.add(InputOutputUserInfo.fromPbUser(user)); + } + + RestResult result; + if (list.isEmpty()) { + result = RestResult.resultOf(ErrorCode.ERROR_CODE_NOT_EXIST); + } else { + OutputUserInfoList outputUserInfoList = new OutputUserInfoList(); + outputUserInfoList.userInfos = list; + result = RestResult.ok(outputUserInfoList); + } + + setResponseContent(result, response); + } else { + setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response); + } + + } + return true; + } +} diff --git a/broker/src/main/java/io/moquette/persistence/DatabaseStore.java b/broker/src/main/java/io/moquette/persistence/DatabaseStore.java index 18e76c28..a783d861 100644 --- a/broker/src/main/java/io/moquette/persistence/DatabaseStore.java +++ b/broker/src/main/java/io/moquette/persistence/DatabaseStore.java @@ -2917,6 +2917,99 @@ public class DatabaseStore { return null; } + List getUserInfosByEmail(String email) { + Connection connection = null; + PreparedStatement statement = null; + ResultSet rs = null; + List outList = new ArrayList<>(); + try { + connection = DBUtil.getConnection(); + String sql = "select `_uid`, `_name`" + + ", `_display_name`" + + ", `_portrait`" + + ", `_mobile`" + + ", `_gender`" + + ", `_email`" + + ", `_address`" + + ", `_company`" + + ", `_social`" + + ", `_extra`" + + ", `_type`" + + ", `_deleted`" + + ", `_dt` from t_user where `_deleted` = 0 and `_email` = ?"; + statement = connection.prepareStatement(sql); + statement.setString(1, email); + + rs = statement.executeQuery(); + while (rs.next()) { + WFCMessage.User.Builder builder = WFCMessage.User.newBuilder(); + int index = 1; + String value = rs.getString(index++); + value = (value == null ? "" : value); + builder.setUid(value); + + value = rs.getString(index++); + value = (value == null ? "" : value); + builder.setName(value); + + value = rs.getString(index++); + value = (value == null ? "" : value); + builder.setDisplayName(value); + + value = rs.getString(index++); + value = (value == null ? "" : value); + builder.setPortrait(value); + + value = rs.getString(index++); + value = (value == null ? "" : value); + builder.setMobile(value); + + int gender = rs.getInt(index++); + builder.setGender(gender); + + value = rs.getString(index++); + value = (value == null ? "" : value); + builder.setEmail(value); + + value = rs.getString(index++); + value = (value == null ? "" : value); + builder.setAddress(value); + + value = rs.getString(index++); + value = (value == null ? "" : value); + builder.setCompany(value); + + value = rs.getString(index++); + value = (value == null ? "" : value); + builder.setSocial(value); + + value = rs.getString(index++); + value = (value == null ? "" : value); + builder.setExtra(value); + + int type = rs.getInt(index++); + builder.setType(type); + + int deleted = rs.getInt(index++); + builder.setDeleted(deleted); + + long longValue = rs.getLong(index++); + if(longValue <= 0) + longValue = 1; + builder.setUpdateDt(longValue); + + outList.add(builder.build()); + } + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + Utility.printExecption(LOG, e, RDBS_Exception); + } finally { + DBUtil.closeDB(connection, statement, rs); + } + return outList; + } + List getAllUsers(int count, int offset) { Connection connection = null; PreparedStatement statement = null; diff --git a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java index 483f895a..5fd7a7e5 100755 --- a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java @@ -2986,6 +2986,11 @@ public class MemoryMessagesStore implements IMessagesStore { return getUserInfo(userId); } + @Override + public List getUserInfosByEmail(String email) { + return databaseStore.getUserInfosByEmail(email); + } + @Override public List getUserInfoList(int count, int offset) { return databaseStore.getAllUsers(count, offset); diff --git a/broker/src/main/java/io/moquette/spi/IMessagesStore.java b/broker/src/main/java/io/moquette/spi/IMessagesStore.java index 0f0c4960..c6f94ccf 100755 --- a/broker/src/main/java/io/moquette/spi/IMessagesStore.java +++ b/broker/src/main/java/io/moquette/spi/IMessagesStore.java @@ -153,6 +153,7 @@ public interface IMessagesStore { WFCMessage.User getUserInfo(String userId); WFCMessage.User getUserInfoByName(String name); WFCMessage.User getUserInfoByMobile(String mobile); + List getUserInfosByEmail(String email); List searchUser(String keyword, int searchType, int page); List getUserInfoList(int count, int offset); diff --git a/common/src/main/java/cn/wildfirechat/common/APIPath.java b/common/src/main/java/cn/wildfirechat/common/APIPath.java index a0a5e0f3..576cec3a 100644 --- a/common/src/main/java/cn/wildfirechat/common/APIPath.java +++ b/common/src/main/java/cn/wildfirechat/common/APIPath.java @@ -27,6 +27,7 @@ public interface APIPath { String User_Get_Token = "/admin/user/get_token"; String User_Update_Block_Status = "/admin/user/update_block_status"; String User_Get_Info = "/admin/user/get_info"; + String User_Get_Email_Info = "/admin/user/get_info_by_email"; String User_Get_All = "/admin/user/all"; String User_Get_Robot_Info = "/admin/user/get_robot_info"; String User_Get_Blocked_List = "/admin/user/get_blocked_list"; diff --git a/common/src/main/java/cn/wildfirechat/pojos/OutputUserInfoList.java b/common/src/main/java/cn/wildfirechat/pojos/OutputUserInfoList.java new file mode 100755 index 00000000..40a20bfc --- /dev/null +++ b/common/src/main/java/cn/wildfirechat/pojos/OutputUserInfoList.java @@ -0,0 +1,18 @@ +/* + * This file is part of the Wildfire Chat package. + * (c) Heavyrain2012 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +package cn.wildfirechat.pojos; + + +import cn.wildfirechat.proto.WFCMessage; + +import java.util.List; + +public class OutputUserInfoList { + public List userInfos; +} diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/Main.java b/sdk/src/main/java/cn/wildfirechat/sdk/Main.java index 5e8adfc3..66355646 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/Main.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/Main.java @@ -178,6 +178,15 @@ public class Main { System.out.println("get user info by userId failure"); System.exit(-1); } + + IMResult userInfoListIMResult = UserAdmin.getUserByEmail("13900000001@139.com"); + if(userInfoListIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS || userInfoListIMResult.getErrorCode() == ErrorCode.ERROR_CODE_NOT_EXIST) { + System.out.println("getUserByEmail success"); + } else { + System.out.println("getUserByEmail failure"); + System.exit(-1); + } + InputOutputUserInfo updateUserInfo = new InputOutputUserInfo(); updateUserInfo.setUserId(System.currentTimeMillis()+""); updateUserInfo.setDisplayName("updatedUserName"); diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/UserAdmin.java b/sdk/src/main/java/cn/wildfirechat/sdk/UserAdmin.java index 34233103..6560edff 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/UserAdmin.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/UserAdmin.java @@ -24,6 +24,11 @@ public class UserAdmin { return AdminHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class); } + public static IMResult getUserByEmail(String email) throws Exception { + String path = APIPath.User_Get_Email_Info; + return AdminHttpUtils.httpJsonPost(path, email, OutputUserInfoList.class); + } + public static IMResult getAllUsers(int count, int offset) throws Exception { String path = APIPath.User_Get_All; InputGetUserList input = new InputGetUserList();