use of com.akaxin.site.storage.bean.UserProfileBean in project openzaly by akaxincom.
the class ApiSiteService method register.
public CommandResponse register(Command command) {
CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
ErrorCode2 errorCode = ErrorCode2.ERROR;
try {
ApiSiteRegisterProto.ApiSiteRegisterRequest registerRequest = ApiSiteRegisterProto.ApiSiteRegisterRequest.parseFrom(command.getParams());
// 这里需要验证邀请码,如果有需要
String userIdPubk = registerRequest.getUserIdPubk();
// siteUserId保证各站不同
String siteUserId = UUID.randomUUID().toString();
String userName = registerRequest.getUserName();
String userPhoto = registerRequest.getUserPhoto();
String userUic = registerRequest.getUserUic();
String applyInfo = registerRequest.getApplyInfo();
String phoneToken = registerRequest.getPhoneToken();
// 通过phoneCod
String phoneId = null;
LogUtils.requestDebugLog(logger, command, registerRequest.toString());
if (StringUtils.isAnyEmpty(userIdPubk, userName)) {
errorCode = ErrorCode2.ERROR_PARAMETER;
return commandResponse.setErrCode2(errorCode);
}
// 判断站点的注册方式
ConfigProto.RegisterWay regWay = SiteConfig.getRegisterWay();
logger.debug("api.site.register register way={}", regWay);
switch(regWay) {
case USERUIC:
logger.debug("注册方式:邀请码注册");
if (!UserUic.getInstance().checkUic(userUic, siteUserId)) {
errorCode = ErrorCode2.ERROR_REGISTER_UIC;
return commandResponse.setErrCode2(errorCode);
}
break;
case REALNAME:
logger.debug("注册方式:实名注册");
if (StringUtils.isNotBlank(phoneToken)) {
phoneId = UserPhone.getInstance().getPhoneIdFromPlatform(phoneToken);
logger.debug("实名注册,站点获取手机号:{}", phoneId);
if (!StringUtils.isNotBlank(phoneId)) {
errorCode = ErrorCode2.ERROR_REGISTER_PHONEID;
return commandResponse.setErrCode2(errorCode);
}
}
break;
case ANONYMOUS:
logger.debug("注册方式:匿名注册");
break;
case UNRECOGNIZED:
break;
}
UserProfileBean regBean = new UserProfileBean();
regBean.setSiteUserId(siteUserId);
regBean.setUserIdPubk(userIdPubk);
regBean.setUserName(userName);
regBean.setApplyInfo(applyInfo);
regBean.setUserPhoto(userPhoto);
regBean.setPhoneId(phoneId);
regBean.setUserStatus(UserProto.UserStatus.NORMAL_VALUE);
regBean.setRegisterTime(System.currentTimeMillis());
if (SiteLoginDao.getInstance().registerUser(regBean)) {
ApiSiteRegisterProto.ApiSiteRegisterResponse response = ApiSiteRegisterProto.ApiSiteRegisterResponse.newBuilder().setSiteUserId(siteUserId).build();
commandResponse.setParams(response.toByteArray());
errorCode = ErrorCode2.SUCCESS;
} else {
errorCode = ErrorCode2.ERROR_REGISTER_SAVEPROFILE;
}
logger.info("client={} siteUserId={} action={} register on site", command.getClientIp(), siteUserId, command.getAction());
if (ErrorCode2.SUCCESS == errorCode) {
// 注册成功,需要做一个管理员身份验证
justForAdminUser(siteUserId, command.getHeader());
}
} catch (Exception e) {
errorCode = ErrorCode2.ERROR_SYSTEMERROR;
LogUtils.requestErrorLog(logger, command, e);
}
return commandResponse.setErrCode2(errorCode);
}
use of com.akaxin.site.storage.bean.UserProfileBean in project openzaly by akaxincom.
the class ApiUserService method updateProfile.
/**
* 更新用户个人信息
*
* @param command
* @return
*/
public CommandResponse updateProfile(Command command) {
CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
ErrorCode2 errCode = ErrorCode2.ERROR;
try {
ApiUserUpdateProfileProto.ApiUserUpdateProfileRequest request = ApiUserUpdateProfileProto.ApiUserUpdateProfileRequest.parseFrom(command.getParams());
String siteUserId = command.getSiteUserId();
String userName = request.getUserProfile().getUserName();
String userPhoto = request.getUserProfile().getUserPhoto();
String introduce = request.getUserProfile().getSelfIntroduce();
LogUtils.requestDebugLog(logger, command, request.toString());
if (StringUtils.isNoneEmpty(siteUserId, userName, userPhoto)) {
UserProfileBean userBean = new UserProfileBean();
userBean.setSiteUserId(siteUserId);
userBean.setUserName(userName);
userBean.setUserPhoto(userPhoto);
userBean.setSelfIntroduce(introduce);
if (UserProfileDao.getInstance().updateUserProfile(userBean)) {
errCode = ErrorCode2.SUCCESS;
} else {
errCode = ErrorCode2.ERROR2_USER_UPDATE_PROFILE;
}
} else {
errCode = ErrorCode2.ERROR_PARAMETER;
}
} catch (Exception e) {
errCode = ErrorCode2.ERROR_SYSTEMERROR;
LogUtils.requestErrorLog(logger, command, e);
}
return commandResponse.setErrCode2(errCode);
}
use of com.akaxin.site.storage.bean.UserProfileBean in project openzaly by akaxincom.
the class HttpUserService method profile.
/**
* 查看用户的个人profile
*
* @param command
* @return
*/
public CommandResponse profile(Command command) {
CommandResponse commandResponse = new CommandResponse();
ErrorCode2 errorCode = ErrorCode2.ERROR;
try {
HaiUserProfileProto.HaiUserProfileRequest request = HaiUserProfileProto.HaiUserProfileRequest.parseFrom(command.getParams());
String siteUserId = request.getSiteUserId();
LogUtils.requestDebugLog(logger, command, request.toString());
if (StringUtils.isNotBlank(siteUserId)) {
UserProfileBean bean = UserProfileDao.getInstance().getUserProfileById(siteUserId);
if (bean != null && StringUtils.isNotBlank(bean.getSiteUserId())) {
UserProto.UserProfile profile = UserProto.UserProfile.newBuilder().setSiteUserId(bean.getSiteUserId()).setUserName(String.valueOf(bean.getUserName())).setUserPhoto(String.valueOf(bean.getUserPhoto())).setUserStatusValue(bean.getUserStatus()).build();
HaiUserProfileProto.HaiUserProfileResponse response = HaiUserProfileProto.HaiUserProfileResponse.newBuilder().setUserProfile(profile).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);
}
use of com.akaxin.site.storage.bean.UserProfileBean in project openzaly by akaxincom.
the class SQLiteUserProfileDao method queryUserProfileByGlobalUserId.
/**
* 通过globalUserId查询用户信息
*
* @param globalUserId
* globalUserId
* @return
* @throws SQLException
*/
public UserProfileBean queryUserProfileByGlobalUserId(String globalUserId) throws SQLException {
long startTime = System.currentTimeMillis();
String sql = "SELECT site_user_id,user_id_pubk,user_name,user_photo,self_introduce,user_status,register_time FROM " + USER_PROFILE_TABLE + " WHERE global_user_id=?;";
PreparedStatement preStatement = SQLiteJDBCManager.getConnection().prepareStatement(sql);
preStatement.setString(1, globalUserId);
ResultSet rs = preStatement.executeQuery();
UserProfileBean userBean = null;
if (rs.next()) {
userBean = new UserProfileBean();
userBean.setSiteUserId(rs.getString(1));
userBean.setUserIdPubk(rs.getString(2));
userBean.setUserName(rs.getString(3));
userBean.setUserPhoto(rs.getString(4));
userBean.setSelfIntroduce(rs.getString(5));
userBean.setUserStatus(rs.getInt(6));
userBean.setRegisterTime(rs.getLong(7));
}
LogUtils.dbDebugLog(logger, startTime, userBean, sql, globalUserId);
return userBean;
}
use of com.akaxin.site.storage.bean.UserProfileBean in project openzaly by akaxincom.
the class SQLiteUserProfileDao method queryUserProfileById.
/**
* 通过站点用户ID,查询用户
*
* @param siteUserId
* @return
* @throws SQLException
*/
public UserProfileBean queryUserProfileById(String siteUserId) throws SQLException {
long startTime = System.currentTimeMillis();
String sql = "SELECT site_user_id,user_id_pubk,user_name,user_photo,self_introduce,user_status,register_time FROM " + USER_PROFILE_TABLE + " WHERE site_user_id=?;";
PreparedStatement preStatement = SQLiteJDBCManager.getConnection().prepareStatement(sql);
preStatement.setString(1, siteUserId);
ResultSet rs = preStatement.executeQuery();
UserProfileBean userBean = null;
if (rs.next()) {
userBean = new UserProfileBean();
userBean.setSiteUserId(rs.getString(1));
userBean.setUserIdPubk(rs.getString(2));
userBean.setUserName(rs.getString(3));
userBean.setUserPhoto(rs.getString(4));
userBean.setSelfIntroduce(rs.getString(5));
userBean.setUserStatus(rs.getInt(6));
userBean.setRegisterTime(rs.getLong(7));
}
LogUtils.dbDebugLog(logger, startTime, userBean, sql, siteUserId);
return userBean;
}
Aggregations