创建用户时检查用户的有效性
This commit is contained in:
@@ -2187,6 +2187,33 @@ public class DatabaseStore {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isUidAndNameConflict(String uid, String name) {
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
try {
|
||||||
|
connection = DBUtil.getConnection();
|
||||||
|
String sql = "select _uid from t_user where _name = ? and _uid <> ? limit 1";
|
||||||
|
statement = connection.prepareStatement(sql);
|
||||||
|
statement.setString(1, name);
|
||||||
|
statement.setString(2, uid);
|
||||||
|
rs = statement.executeQuery();
|
||||||
|
if (rs.next()) {
|
||||||
|
String conflictId = rs.getString(1);
|
||||||
|
LOG.error("user {} already have name {} !!!", conflictId, name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
Utility.printExecption(LOG, e);
|
||||||
|
} finally {
|
||||||
|
DBUtil.closeDB(connection, statement, rs);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void updateUser(final WFCMessage.User user) throws Exception {
|
void updateUser(final WFCMessage.User user) throws Exception {
|
||||||
LOG.info("Database update user info {} {}", user.getUid(), user.getUpdateDt());
|
LOG.info("Database update user info {} {}", user.getUid(), user.getUpdateDt());
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
|
|||||||
@@ -1783,6 +1783,9 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
public void addUserInfo(WFCMessage.User user, String password) throws Exception {
|
public void addUserInfo(WFCMessage.User user, String password) throws Exception {
|
||||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||||
IMap<String, WFCMessage.User> mUserMap = hzInstance.getMap(USERS);
|
IMap<String, WFCMessage.User> mUserMap = hzInstance.getMap(USERS);
|
||||||
|
if (databaseStore.isUidAndNameConflict(user.getUid(), user.getName())) {
|
||||||
|
throw new Exception("用户名不能重复,必须唯一!!!");
|
||||||
|
}
|
||||||
databaseStore.updateUser(user);
|
databaseStore.updateUser(user);
|
||||||
mUserMap.put(user.getUid(), user);
|
mUserMap.put(user.getUid(), user);
|
||||||
databaseStore.updateUserPassword(user.getUid(), password);
|
databaseStore.updateUserPassword(user.getUid(), password);
|
||||||
|
|||||||
@@ -52,7 +52,9 @@ public class Main {
|
|||||||
//***********************************************
|
//***********************************************
|
||||||
static void testUser() throws Exception {
|
static void testUser() throws Exception {
|
||||||
InputOutputUserInfo userInfo = new InputOutputUserInfo();
|
InputOutputUserInfo userInfo = new InputOutputUserInfo();
|
||||||
|
//用户ID,必须保证唯一性
|
||||||
userInfo.setUserId("userId1");
|
userInfo.setUserId("userId1");
|
||||||
|
//用户名,一般是用户登录帐号,也必须保证唯一性。也就是说所有用户的userId必须不能重复,所有用户的name必须不能重复,但可以同一个用户的userId和name是同一个,一般建议userId使用一个uuid,name是"微信号"且可以修改,
|
||||||
userInfo.setName("user1");
|
userInfo.setName("user1");
|
||||||
userInfo.setMobile("13900000000");
|
userInfo.setMobile("13900000000");
|
||||||
userInfo.setDisplayName("user 1");
|
userInfo.setDisplayName("user 1");
|
||||||
|
|||||||
Reference in New Issue
Block a user