Search in sources :

Example 1 with SimpleUserBean

use of com.akaxin.site.storage.bean.SimpleUserBean in project openzaly by akaxincom.

the class ApiFriendService method list.

public CommandResponse list(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiFriendListProto.ApiFriendListRequest request = ApiFriendListProto.ApiFriendListRequest.parseFrom(command.getParams());
        String currentUserId = command.getSiteUserId();
        String siteUserId = request.getSiteUserId();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(siteUserId) && siteUserId.equals(currentUserId)) {
            List<SimpleUserBean> friendBeanList = UserFriendDao.getInstance().getUserFriends(siteUserId);
            ApiFriendListProto.ApiFriendListResponse.Builder responseBuilder = ApiFriendListProto.ApiFriendListResponse.newBuilder();
            for (SimpleUserBean friendBean : friendBeanList) {
                UserProto.SimpleUserProfile friend = UserProto.SimpleUserProfile.newBuilder().setSiteUserId(String.valueOf(friendBean.getUserId())).setUserName(String.valueOf(friendBean.getUserName())).setUserPhoto(String.valueOf(friendBean.getUserPhoto())).build();
                responseBuilder.addList(friend);
            }
            commandResponse.setParams(responseBuilder.build().toByteArray());
            errCode = ErrorCode2.SUCCESS;
        } else {
            errCode = ErrorCode2.ERROR_PARAMETER;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ApiFriendListProto(com.akaxin.proto.site.ApiFriendListProto) ErrorCode2(com.akaxin.common.constant.ErrorCode2) UserProto(com.akaxin.proto.core.UserProto) CommandResponse(com.akaxin.common.command.CommandResponse) SimpleUserBean(com.akaxin.site.storage.bean.SimpleUserBean)

Example 2 with SimpleUserBean

use of com.akaxin.site.storage.bean.SimpleUserBean in project openzaly by akaxincom.

the class ApiGroupService method nonMembers.

/**
 * 获取用户群组中,不存在的好友用户
 *
 * @param command
 * @return
 */
public CommandResponse nonMembers(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiGroupNonMembersProto.ApiGroupNonMembersRequest request = ApiGroupNonMembersProto.ApiGroupNonMembersRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        String groupId = request.getGroupId();
        int pageNum = request.getPageNumber();
        int pageSize = request.getPageSize();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (pageNum == 0 && pageSize == 0) {
            pageSize = 100;
        }
        List<SimpleUserBean> userFriendList = UserGroupDao.getInstance().getUserFriendNonGroupMemberList(siteUserId, groupId, pageNum, pageSize);
        ApiGroupNonMembersProto.ApiGroupNonMembersResponse.Builder responseBuilder = ApiGroupNonMembersProto.ApiGroupNonMembersResponse.newBuilder();
        for (SimpleUserBean friendBean : userFriendList) {
            UserProto.SimpleUserProfile friendProfile = UserProto.SimpleUserProfile.newBuilder().setSiteUserId(friendBean.getUserId()).setUserName(String.valueOf(friendBean.getUserName())).setUserPhoto(String.valueOf(friendBean.getUserPhoto())).build();
            responseBuilder.addProfile(friendProfile);
        }
        commandResponse.setParams(responseBuilder.build().toByteArray());
        errCode = ErrorCode2.SUCCESS;
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ApiGroupNonMembersProto(com.akaxin.proto.site.ApiGroupNonMembersProto) UserProto(com.akaxin.proto.core.UserProto) CommandResponse(com.akaxin.common.command.CommandResponse) SimpleUserBean(com.akaxin.site.storage.bean.SimpleUserBean) ErrorCode2(com.akaxin.common.constant.ErrorCode2)

Example 3 with SimpleUserBean

use of com.akaxin.site.storage.bean.SimpleUserBean in project openzaly by akaxincom.

the class ApiGroupService method profile.

/**
 * 获取群资料信息,一般由以下几部分组成 <br>
 * 1.群资料GroupProfile <br>
 * 2.群主基本资料GroupMaster,群主通过GroupProfile获取 <br>
 * 3.群成员人数以及排在最前列的四位用户 <br>
 * 4.无权限限制
 *
 * @param command
 * @return
 */
public CommandResponse profile(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiGroupProfileProto.ApiGroupProfileRequest request = ApiGroupProfileProto.ApiGroupProfileRequest.parseFrom(command.getParams());
        String groupId = request.getGroupId();
        int pageNum = 1;
        int pageSize = GroupConfig.GROUP_MIN_MEMBER_COUNT;
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(groupId)) {
            GroupProfileBean groupBean = UserGroupDao.getInstance().getGroupProfile(groupId);
            if (groupBean != null && StringUtils.isNotBlank(groupBean.getGroupId())) {
                SimpleUserBean ownerProfileBean = UserProfileDao.getInstance().getSimpleProfileById(groupBean.getCreateUserId());
                logger.debug("get groupId={},groupOwner={}", groupId, ownerProfileBean.toString());
                int groupMembersCount = UserGroupDao.getInstance().getGroupMemberCount(groupId);
                logger.debug("get groupId={},groupMembers={}", groupId, groupMembersCount);
                List<GroupMemberBean> groupMemberList = UserGroupDao.getInstance().getGroupMemberList(groupId, pageNum, pageSize);
                UserProto.UserProfile ownerProfile = UserProto.UserProfile.newBuilder().setSiteUserId(String.valueOf(ownerProfileBean.getUserId())).setUserPhoto(String.valueOf(ownerProfileBean.getUserPhoto())).setUserName(String.valueOf(ownerProfileBean.getUserName())).build();
                GroupProto.GroupProfile groupProfile = GroupProto.GroupProfile.newBuilder().setId(groupBean.getGroupId()).setName(String.valueOf(groupBean.getGroupName())).setIcon(String.valueOf(groupBean.getGroupPhoto())).build();
                ApiGroupProfileProto.ApiGroupProfileResponse.Builder responseBuilder = ApiGroupProfileProto.ApiGroupProfileResponse.newBuilder();
                responseBuilder.setOwner(ownerProfile);
                responseBuilder.setProfile(groupProfile);
                responseBuilder.setGroupMemberCount(groupMembersCount);
                for (GroupMemberBean memberBean : groupMemberList) {
                    UserProto.UserProfile memberProfile = UserProto.UserProfile.newBuilder().setSiteUserId(String.valueOf(memberBean.getUserId())).setUserPhoto(String.valueOf(memberBean.getUserPhoto())).setUserName(String.valueOf(memberBean.getUserName())).build();
                    GroupProto.GroupMemberProfile groupMemberProfile = GroupProto.GroupMemberProfile.newBuilder().setProfile(memberProfile).build();
                    responseBuilder.addGroupLastestMember(groupMemberProfile);
                }
                // 是否可以邀请群聊(除了群主以外)
                responseBuilder.setCloseInviteGroupChat(groupBean.isCloseInviteGroupChat());
                ApiGroupProfileProto.ApiGroupProfileResponse response = responseBuilder.build();
                commandResponse.setParams(response.toByteArray());
                errCode = ErrorCode2.SUCCESS;
            }
        } else {
            errCode = ErrorCode2.ERROR_PARAMETER;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ApiGroupProfileProto(com.akaxin.proto.site.ApiGroupProfileProto) UserProto(com.akaxin.proto.core.UserProto) GroupProto(com.akaxin.proto.core.GroupProto) CommandResponse(com.akaxin.common.command.CommandResponse) GroupMemberBean(com.akaxin.site.storage.bean.GroupMemberBean) SimpleUserBean(com.akaxin.site.storage.bean.SimpleUserBean) ErrorCode2(com.akaxin.common.constant.ErrorCode2) GroupProfileBean(com.akaxin.site.storage.bean.GroupProfileBean)

Example 4 with SimpleUserBean

use of com.akaxin.site.storage.bean.SimpleUserBean in project openzaly by akaxincom.

the class ApiSiteService method login.

/**
 * 执行用户登陆站点行为
 *
 * @param command
 * @return
 */
public CommandResponse login(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiSiteLoginProto.ApiSiteLoginRequest loginRequest = ApiSiteLoginProto.ApiSiteLoginRequest.parseFrom(command.getParams());
        String userIdPubk = loginRequest.getUserIdPubk();
        String userIdSignBase64 = loginRequest.getUserIdSignBase64();
        String userDeviceIdPubk = loginRequest.getUserDeviceIdPubk();
        String userDeviceIdSignBase64 = loginRequest.getUserDeviceIdSignBase64();
        String userDeviceName = loginRequest.getUserDeviceName();
        String userToken = loginRequest.getUserToken();
        LogUtils.requestDebugLog(logger, command, loginRequest.toString());
        if (StringUtils.isAnyEmpty(userIdPubk, userIdSignBase64)) {
            errCode = ErrorCode2.ERROR2_LOGGIN_USERID_EMPTY;
            return commandResponse.setErrCode2(errCode);
        }
        if (StringUtils.isAnyEmpty(userDeviceIdPubk, userDeviceIdSignBase64)) {
            errCode = ErrorCode2.ERROR2_LOGGIN_DEVICEID_EMPTY;
            return commandResponse.setErrCode2(errCode);
        }
        // 个人身份公钥,解密Sign签名,解密Key
        PublicKey userPubKey = RSACrypto.getRSAPubKeyFromPem(userIdPubk);
        Signature userSign = Signature.getInstance("SHA512withRSA");
        userSign.initVerify(userPubKey);
        // 原文
        userSign.update(userIdPubk.getBytes());
        boolean userSignResult = userSign.verify(Base64.getDecoder().decode(userIdSignBase64));
        logger.debug("userSignResult={}", userSignResult);
        if (userSignResult) {
            Signature userDeviceSign = Signature.getInstance("SHA512withRSA");
            userDeviceSign.initVerify(userPubKey);
            // 原文
            userDeviceSign.update(userDeviceIdPubk.getBytes());
            userSignResult = userDeviceSign.verify(Base64.getDecoder().decode(userDeviceIdSignBase64));
        }
        logger.debug("deviceSignResult={}", userSignResult);
        // 用户身份校验成功,方可执行登陆操作
        if (userSignResult) {
            // 判断用户,是否已经注册
            SimpleUserBean subean = UserProfileDao.getInstance().getSimpleProfileByPubk(userIdPubk);
            if (subean == null || StringUtils.isEmpty(subean.getUserId())) {
                logger.info("login site: new user need to register before login site");
                // 未注册,告知用户执行注册行为
                errCode = ErrorCode2.ERROR2_LOGGIN_NOREGISTER;
                return commandResponse.setErrCode2(errCode);
            }
            if (subean.getUserStatus() == UserProto.UserStatus.SEALUP_VALUE) {
                logger.info("login site:	 user no permision as seal up");
                // 禁封用户禁止登陆
                errCode = ErrorCode2.ERROR2_LOGGIN_SEALUPUSER;
                return commandResponse.setErrCode2(errCode);
            }
            String siteUserId = subean.getUserId();
            String deviceId = HashCrypto.MD5(userDeviceIdPubk);
            // 保存设备信息
            UserDeviceBean deviceBean = new UserDeviceBean();
            deviceBean.setDeviceId(deviceId);
            deviceBean.setDeviceName(userDeviceName);
            deviceBean.setSiteUserId(siteUserId);
            deviceBean.setUserDevicePubk(userDeviceIdPubk);
            deviceBean.setUserToken(userToken);
            deviceBean.setActiveTime(System.currentTimeMillis());
            deviceBean.setAddTime(System.currentTimeMillis());
            boolean loginResult = SiteLoginDao.getInstance().updateUserDevice(deviceBean);
            if (!loginResult) {
                // 更新失败,则重新保存数据
                loginResult = SiteLoginDao.getInstance().saveUserDevice(deviceBean);
            }
            logger.debug("login site: save device result={} deviceBean={}", loginResult, deviceBean.toString());
            if (loginResult) {
                // 生成session
                String sessionId = UUID.randomUUID().toString();
                UserSessionBean sessionBean = new UserSessionBean();
                sessionBean.setLoginTime(System.currentTimeMillis());
                sessionBean.setSiteUserId(siteUserId);
                sessionBean.setOnline(true);
                sessionBean.setSessionId(sessionId);
                sessionBean.setDeviceId(deviceId);
                // 上次登陆(auth)时间
                sessionBean.setLoginTime(System.currentTimeMillis());
                loginResult = loginResult && SiteLoginDao.getInstance().saveUserSession(sessionBean);
                if (loginResult) {
                    ApiSiteLoginProto.ApiSiteLoginResponse response = ApiSiteLoginProto.ApiSiteLoginResponse.newBuilder().setSiteUserId(siteUserId).setUserSessionId(sessionId).build();
                    commandResponse.setParams(response.toByteArray());
                    errCode = ErrorCode2.SUCCESS;
                } else {
                    errCode = ErrorCode2.ERROR2_LOGGIN_UPDATE_SESSION;
                }
            } else {
                errCode = ErrorCode2.ERROR2_LOGGIN_UPDATE_DEVICE;
            }
        } else {
            errCode = ErrorCode2.ERROR2_LOGGIN_ERRORSIGN;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ApiSiteLoginProto(com.akaxin.proto.site.ApiSiteLoginProto) PublicKey(java.security.PublicKey) UserSessionBean(com.akaxin.site.storage.bean.UserSessionBean) CommandResponse(com.akaxin.common.command.CommandResponse) SimpleUserBean(com.akaxin.site.storage.bean.SimpleUserBean) ErrorCode2(com.akaxin.common.constant.ErrorCode2) UserDeviceBean(com.akaxin.site.storage.bean.UserDeviceBean) Signature(java.security.Signature)

Example 5 with SimpleUserBean

use of com.akaxin.site.storage.bean.SimpleUserBean in project openzaly by akaxincom.

the class SQLiteUserProfileDao method queryUserPageList.

/**
 * 单独获取当前站点的用户列表
 *
 * @param pageNum
 * @param pageSize
 * @return
 * @throws SQLException
 */
public List<SimpleUserBean> queryUserPageList(int pageNum, int pageSize) throws SQLException {
    long startTime = System.currentTimeMillis();
    List<SimpleUserBean> userPageList = new ArrayList<SimpleUserBean>();
    String sql = "SELECT site_user_id,user_name,user_photo,user_status FROM " + USER_PROFILE_TABLE + "  ORDER BY id DESC LIMIT ?,?;";
    int startNum = (pageNum - 1) * pageSize;
    PreparedStatement preStatement = SQLiteJDBCManager.getConnection().prepareStatement(sql);
    preStatement.setInt(1, startNum);
    preStatement.setInt(2, pageSize);
    ResultSet rs = preStatement.executeQuery();
    while (rs.next()) {
        SimpleUserBean bean = new SimpleUserBean();
        bean.setUserId(rs.getString(1));
        bean.setUserName(rs.getString(2));
        bean.setUserPhoto(rs.getString(3));
        bean.setUserStatus(rs.getInt(4));
        userPageList.add(bean);
    }
    LogUtils.dbDebugLog(logger, startTime, userPageList.size(), sql, startNum, pageSize);
    return userPageList;
}
Also used : ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SimpleUserBean(com.akaxin.site.storage.bean.SimpleUserBean)

Aggregations

SimpleUserBean (com.akaxin.site.storage.bean.SimpleUserBean)14 PreparedStatement (java.sql.PreparedStatement)7 ResultSet (java.sql.ResultSet)7 CommandResponse (com.akaxin.common.command.CommandResponse)6 ErrorCode2 (com.akaxin.common.constant.ErrorCode2)6 ArrayList (java.util.ArrayList)5 UserProto (com.akaxin.proto.core.UserProto)4 GroupProto (com.akaxin.proto.core.GroupProto)1 HaiUserListProto (com.akaxin.proto.plugin.HaiUserListProto)1 HaiUserSearchProto (com.akaxin.proto.plugin.HaiUserSearchProto)1 ApiFriendListProto (com.akaxin.proto.site.ApiFriendListProto)1 ApiGroupNonMembersProto (com.akaxin.proto.site.ApiGroupNonMembersProto)1 ApiGroupProfileProto (com.akaxin.proto.site.ApiGroupProfileProto)1 ApiSiteLoginProto (com.akaxin.proto.site.ApiSiteLoginProto)1 GroupMemberBean (com.akaxin.site.storage.bean.GroupMemberBean)1 GroupProfileBean (com.akaxin.site.storage.bean.GroupProfileBean)1 UserDeviceBean (com.akaxin.site.storage.bean.UserDeviceBean)1 UserSessionBean (com.akaxin.site.storage.bean.UserSessionBean)1 ByteString (com.google.protobuf.ByteString)1 PublicKey (java.security.PublicKey)1