(续)
3、连贯 mysql, mongodb 传导数据
** 用户数据字段对照表:**
nodebb | 例子数据 // 作用阐明 | discuzX 字段 | discuzX 表名 | OK |
---|---|---|---|---|
“_id” | ObjectId(“65cb8801e09f69ff71141520”), | [x] | ||
“_key” | user:2 // 2 通常等于 uid | |||
“joindate” | 1707837441083, | regdate | pre2_common_member | [x] |
“lastonline” | 1708000177292, | lastvisit | pre2_common_member_status | [x] |
“uid” | 2, | uid | pre2_common_member | [x] |
“username” | “guo”, | “username” | pre2_common_member | [x] |
“userslug” | “guo”, | “username” | pre2_common_member | |
“password” | “$2a$12$VIKLGFC3AS1B4sDuVNivIOQMOmRseO1HVpxjdOJXyUDBnDZqbu5nK”, | “password” | pre2_common_member | [x] |
“dz_password” | “6e444aafb9b9f7ffaa88b061d8ed63f4” | discuzX3.4 生成的密文明码 | ||
“8d488b” | salt | uc_members | ||
“mobile” | 新加 | mobile | pre2_common_member_profile | [x] |
“email” | “9590@yeah.net”, | pre2_common_member | [x] | |
“email:confirmed” | 1, // 邮件验证 | 默认 =1 | ||
“groupTitle” | “[\”\”]”, | |||
“profileviews” | 0, // 空间点击数 views | views | pre2_common_member_count | [x] |
“reputation” | 0, // 名誉,积分 credits | credits | pre2_common_member | [x] |
“topiccount” | 1, // 主题 threads | threads | pre2_common_member_count | [x] |
“lastposttime” | 1707837441933, | lastpost | pre2_common_member_status | [x] |
“postcount” | 1, // 帖子 posts(蕴含了主题) | posts | pre2_common_member_count | [x] |
“picture” | “/assets/uploads/profile/1-profileavatar-1707989852545.jpeg”, | find_avatar 生成(用…_big.jpg) | [x] | |
“uploadedpicture” | “/assets/uploads/profile/1-profileavatar-1707989852545.jpeg”, | find_avatar 生成 | [x] | |
“fullname” | “ 全名 guojin”, | realname | pre2_common_member_profile | [x] |
“aboutme” | “ 对于我是一个管理员 ”, | bio | pre2_common_member_profile | [x] |
“birthday” | “2024-02-15”, | pre2_common_member_profile | [x] | |
“location” | “ 广州 ”, | resideprovince | pre2_common_member_profile | [x] |
“signature” | “ 签名:我是一个管理员 ”, | sightml | pre2_common_member_field_forum | [x] |
“website” | “https://weibo.com/ 我的网 ” | site | pre2_common_member_profile | [x] |
须要用 post 到 API 的形式在 nodebb 批量新建用户,API(v3.65): /api/v3/users,并且须要在后盾生成 Bearer Token,以下是官网指南:
To create a Bearer Token, do this:
- Settings > API Access > Create Token > Specify your User ID and Description (for example „Linuxfabrik API Token“).
感激 segmentfault 网的 bay1 网友发表的文章,有了前人的致力,再批改一下便能够用起来:
https://segmentfault.com/a/1190000015336130
在原来根底上减少一些字段
def get_forum_post(fid, tid):
forum_post_sql = "select author,dateline,message,authorid from pre2_forum_post where fid=%a and tid=%a" % (fid, tid)
dz_cursor.execute(forum_post_sql)
forum_post = dz_cursor.fetchall()
return forum_post
def get_salt(uid):
salt_sql = "select salt from pre2_ucenter_members where uid=%a" % uid
dz_cursor.execute(salt_sql)
salt = dz_cursor.fetchone()["salt"]
return salt
def get_mobile(uid):
mobile_sql = "select mobile from pre2_common_member_profile where uid=%a" % uid
dz_cursor.execute(mobile_sql)
mobile = dz_cursor.fetchone()["mobile"]
return mobile
def get_views(uid):
views_sql = "select views from pre2_common_member_count where uid=%a" % uid
dz_cursor.execute(views_sql)
views = dz_cursor.fetchone()["views"]
return views
def get_threads(uid):
threads_sql = "select threads from pre2_common_member_count where uid=%a" % uid
dz_cursor.execute(threads_sql)
threads = dz_cursor.fetchone()["threads"]
return threads
def get_posts(uid):
posts_sql = "select posts from pre2_common_member_count where uid=%a" % uid
dz_cursor.execute(posts_sql)
posts = dz_cursor.fetchone()["posts"]
return posts
def get_realname(uid):
realname_sql = "select realname from pre2_common_member_profile where uid=%a" % uid
dz_cursor.execute(realname_sql)
realname = dz_cursor.fetchone()["realname"]
return realname
def get_birth_site(uid):
birth_site_sql = "select birthyear,birthmonth,birthday,site from pre2_common_member_profile where uid=%a" % uid
dz_cursor.execute(birth_site_sql)
birth_site = dz_cursor.fetchone()
return birth_site
def get_resideprovince(uid): # 所在省份 location
resideprovince_sql = "select resideprovince from pre2_common_member_profile where uid=%a" % uid
dz_cursor.execute(resideprovince_sql)
resideprovince = dz_cursor.fetchone()["resideprovince"]
return resideprovince
def get_bio(uid): # 所在省份 location
bio_sql = "select bio from pre2_common_member_profile where uid=%a" % uid
dz_cursor.execute(bio_sql)
bio = dz_cursor.fetchone()["bio"]
return bio
def get_lastvisit(uid):
lastvisit_sql = "select lastvisit from pre2_common_member_status where uid=%a" % uid
dz_cursor.execute(lastvisit_sql)
lastvisit = dz_cursor.fetchone()["lastvisit"]
return lastvisit
def get_lastpost(uid):
lastpost_sql = "select lastpost from pre2_common_member_status where uid=%a" % uid
dz_cursor.execute(lastpost_sql)
lastpost = dz_cursor.fetchone()["lastpost"]
return lastpost
经测试生成新用户并把原论坛材料附上去没有多大问题,接下来要解决的就是登录和明码问题,因为 discuzX3.4 用的是 hash 也就是
md5(md5(password + salt)) 形式(留神 X3.5 是用的 bcrypt)
上表看到了我新加了 dz_password, salt, mobile 字段便是为了解决这方面的问题,上 nodebb 群向高手求教,大伙认为须要新写一个插件才好解决,并且不会影响日后 nodebb 的更新。
我代码能力很无限,写插件是头一次,便上网找到一些可能有用的材料:
nodebb 接入已有的账号体系
https://blog.csdn.net/qq_36742720/article/details/89226040
github 的范例:
https://github.com/misaka4e21/nodebb-plugin-auth-overrideLogin
一位 nodebb 的开发者也写了些指南:
https://gist.github.com/julianlam/19deafaa4dbd624ceecd
官网的 hook 列表:
https://github.com/NodeBB/NodeBB/wiki/Hooks