开始从 discuzX3.4 迁移到 nodebb(二)

(续)

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" "9[email protected]t", email 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

你可能感兴趣的:(开始从 discuzX3.4 迁移到 nodebb(二))