Search in sources :

Example 21 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class ApiPluginService method list.

/**
 * 分页获取扩展列表
 *
 * @param command
 * @return
 */
public CommandResponse list(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiPluginListProto.ApiPluginListRequest request = ApiPluginListProto.ApiPluginListRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        int pageNumber = request.getPageNumber();
        int pageSize = request.getPageSize();
        PluginProto.PluginPosition position = request.getPosition();
        String siteAdmin = SiteConfig.getSiteAdmin();
        LogUtils.requestDebugLog(logger, command, request.toString());
        // 先做首帧扩展
        if (PluginProto.PluginPosition.HOME_PAGE == position) {
            List<PluginBean> pluginList = null;
            if (StringUtils.isNotBlank(siteUserId) && siteUserId.equals(siteAdmin)) {
                pluginList = SitePluginDao.getInstance().getAdminPluginPageList(pageNumber, pageSize, position.getNumber());
            } else {
                pluginList = SitePluginDao.getInstance().getOrdinaryPluginPageList(pageNumber, pageSize, position.getNumber());
            }
            if (pluginList != null) {
                ApiPluginListProto.ApiPluginListResponse.Builder responseBuilder = ApiPluginListProto.ApiPluginListResponse.newBuilder();
                for (PluginBean bean : pluginList) {
                    responseBuilder.addPlugin(getPluginProfile(bean));
                }
                commandResponse.setParams(responseBuilder.build().toByteArray());
                errCode = ErrorCode2.SUCCESS;
            }
        } else {
            errCode = ErrorCode2.ERROR2_PLUGIN_STATUS;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : PluginProto(com.akaxin.proto.core.PluginProto) CommandResponse(com.akaxin.common.command.CommandResponse) ByteString(com.google.protobuf.ByteString) ApiPluginListProto(com.akaxin.proto.site.ApiPluginListProto) ErrorCode2(com.akaxin.common.constant.ErrorCode2) PluginBean(com.akaxin.site.storage.bean.PluginBean)

Example 22 with CommandResponse

use of com.akaxin.common.command.CommandResponse 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 23 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class ApiSiteService method config.

/**
 * <pre>
 * 		api.site.config
 * 		获取站点配置信息
 * </pre>
 *
 * @param command
 * @return
 */
public CommandResponse config(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        Map<Integer, String> configMap = SiteConfig.getConfigMap();
        LogUtils.requestDebugLog(logger, command, "");
        if (configMap != null) {
            ConfigProto.SiteConfig.Builder configBuilder = ConfigProto.SiteConfig.newBuilder();
            if (StringUtils.isNotBlank(configMap.get(ConfigProto.ConfigKey.SITE_ADDRESS_VALUE))) {
                configBuilder.setSiteAddress(configMap.get(ConfigProto.ConfigKey.SITE_ADDRESS_VALUE));
            }
            if (StringUtils.isNumeric(configMap.get(ConfigProto.ConfigKey.SITE_PORT_VALUE))) {
                configBuilder.setSitePort(Integer.valueOf(configMap.get(ConfigProto.ConfigKey.SITE_PORT_VALUE)));
            }
            if (StringUtils.isNotBlank(configMap.get(ConfigProto.ConfigKey.SITE_NAME_VALUE))) {
                configBuilder.setSiteName(configMap.get(ConfigProto.ConfigKey.SITE_NAME_VALUE));
            }
            if (StringUtils.isNotBlank(configMap.get(ConfigProto.ConfigKey.SITE_LOGO_VALUE))) {
                configBuilder.setSiteLogo(configMap.get(ConfigProto.ConfigKey.SITE_LOGO_VALUE));
            }
            if (StringUtils.isNotBlank(configMap.get(ConfigProto.ConfigKey.SITE_VERSION_VALUE))) {
                configBuilder.setSiteVersion(configMap.get(ConfigProto.ConfigKey.SITE_VERSION_VALUE));
            }
            if (StringUtils.isNotBlank(configMap.get(ConfigProto.ConfigKey.SITE_INTRODUCTION_VALUE))) {
                configBuilder.setSiteIntroduction(configMap.get(ConfigProto.ConfigKey.SITE_INTRODUCTION_VALUE));
            }
            if (StringUtils.isNotBlank(configMap.get(ConfigProto.ConfigKey.PIC_SIZE_VALUE))) {
                configBuilder.setPicSize(configMap.get(ConfigProto.ConfigKey.PIC_SIZE_VALUE));
            }
            if (StringUtils.isNumeric(configMap.get(ConfigProto.ConfigKey.REGISTER_WAY_VALUE))) {
                configBuilder.setRegisterWay(Integer.valueOf(configMap.get(ConfigProto.ConfigKey.REGISTER_WAY_VALUE)));
            }
            ApiSiteConfigProto.ApiSiteConfigResponse response = ApiSiteConfigProto.ApiSiteConfigResponse.newBuilder().setSiteConfig(configBuilder.build()).build();
            commandResponse.setParams(response.toByteArray());
            errCode = ErrorCode2.SUCCESS;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ApiSiteConfigProto(com.akaxin.proto.site.ApiSiteConfigProto) ErrorCode2(com.akaxin.common.constant.ErrorCode2) SiteConfig(com.akaxin.site.business.impl.site.SiteConfig) CommandResponse(com.akaxin.common.command.CommandResponse)

Example 24 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class ApiUserService method profile.

/**
 * 获取用户个人资料信息
 *
 * 支持使用globalUserid与siteUserId
 *
 * @param command
 * @return
 */
public CommandResponse profile(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errorCode = ErrorCode2.ERROR;
    try {
        ApiUserProfileProto.ApiUserProfileRequest request = ApiUserProfileProto.ApiUserProfileRequest.parseFrom(command.getParams());
        String currentUserId = command.getSiteUserId();
        String siteUserId = request.getSiteUserId();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(siteUserId) && siteUserId.equals(currentUserId)) {
            UserProfileBean userBean = UserProfileDao.getInstance().getUserProfileById(siteUserId);
            if (null == userBean) {
                // 直接复用之前的接口了。
                userBean = UserProfileDao.getInstance().getUserProfileByGlobalUserId(siteUserId);
            }
            if (userBean != null && StringUtils.isNotBlank(userBean.getSiteUserId())) {
                UserProto.UserProfile.Builder userProfileBuilder = UserProto.UserProfile.newBuilder();
                userProfileBuilder.setSiteUserId(userBean.getSiteUserId());
                if (userBean.getUserName() != null) {
                    userProfileBuilder.setUserName(userBean.getUserName());
                }
                if (userBean.getUserPhoto() != null) {
                    userProfileBuilder.setUserPhoto(userBean.getUserPhoto());
                }
                if (userBean.getSelfIntroduce() != null) {
                    userProfileBuilder.setSelfIntroduce(userBean.getSelfIntroduce());
                }
                userProfileBuilder.setUserStatusValue(userBean.getUserStatus());
                ApiUserProfileProto.ApiUserProfileResponse response = ApiUserProfileProto.ApiUserProfileResponse.newBuilder().setUserProfile(userProfileBuilder.build()).build();
                commandResponse.setParams(response.toByteArray());
                errorCode = ErrorCode2.SUCCESS;
            }
        } else {
            errorCode = ErrorCode2.ERROR_PARAMETER;
        }
    } catch (Exception e) {
        errorCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errorCode);
}
Also used : ApiUserProfileProto(com.akaxin.proto.site.ApiUserProfileProto) ErrorCode2(com.akaxin.common.constant.ErrorCode2) CommandResponse(com.akaxin.common.command.CommandResponse) UserProfileBean(com.akaxin.site.storage.bean.UserProfileBean)

Example 25 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class HttpGroupService method updateProfile.

/**
 * 更新群资料
 *
 * @param command
 * @return
 */
public CommandResponse updateProfile(Command command) {
    CommandResponse commandResponse = new CommandResponse();
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        HaiGroupUpdateProfileProto.HaiGroupUpdateProfileRequest request = HaiGroupUpdateProfileProto.HaiGroupUpdateProfileRequest.parseFrom(command.getParams());
        String groupId = request.getProfile().getId();
        String photoId = request.getProfile().getIcon();
        String groupName = request.getProfile().getName();
        String groupNotice = request.getProfile().getGroupNotice();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(groupId)) {
            GroupProfileBean gprofileBean = new GroupProfileBean();
            gprofileBean.setGroupId(groupId);
            gprofileBean.setGroupName(groupName);
            gprofileBean.setGroupPhoto(photoId);
            gprofileBean.setGroupNotice(groupNotice);
            if (UserGroupDao.getInstance().updateGroupProfile(gprofileBean)) {
                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 : ErrorCode2(com.akaxin.common.constant.ErrorCode2) HaiGroupUpdateProfileProto(com.akaxin.proto.plugin.HaiGroupUpdateProfileProto) CommandResponse(com.akaxin.common.command.CommandResponse) GroupProfileBean(com.akaxin.site.storage.bean.GroupProfileBean)

Aggregations

CommandResponse (com.akaxin.common.command.CommandResponse)82 ErrorCode2 (com.akaxin.common.constant.ErrorCode2)68 UserProto (com.akaxin.proto.core.UserProto)12 PluginBean (com.akaxin.site.storage.bean.PluginBean)7 ByteString (com.google.protobuf.ByteString)7 GroupProto (com.akaxin.proto.core.GroupProto)6 GroupProfileBean (com.akaxin.site.storage.bean.GroupProfileBean)6 SimpleUserBean (com.akaxin.site.storage.bean.SimpleUserBean)6 UserProfileBean (com.akaxin.site.storage.bean.UserProfileBean)6 UserDeviceBean (com.akaxin.site.storage.bean.UserDeviceBean)5 Command (com.akaxin.common.command.Command)4 DeviceProto (com.akaxin.proto.core.DeviceProto)4 ProtocolStringList (com.google.protobuf.ProtocolStringList)4 ConfigProto (com.akaxin.proto.core.ConfigProto)3 GroupMemberBean (com.akaxin.site.storage.bean.GroupMemberBean)3 UserGroupBean (com.akaxin.site.storage.bean.UserGroupBean)3 RedisCommand (com.akaxin.common.command.RedisCommand)2 ImStcPsnProto (com.akaxin.proto.client.ImStcPsnProto)2 CoreProto (com.akaxin.proto.core.CoreProto)2 FileProto (com.akaxin.proto.core.FileProto)2