|
|
@@ -9,6 +9,7 @@ let config = {
|
|
|
}
|
|
|
const plugin = requirePlugin('fm-plugin')
|
|
|
const { Parse, checkAuth } = plugin
|
|
|
+const { restrictionMessage, restrictionMessageForUser } = require('./utils/login-restrictions');
|
|
|
|
|
|
// enabledOptions 可能由插件初始化写入;未授权/首登异常时可能为 undefined
|
|
|
// 避免 data 初始化阶段直接读取 [0] 导致页面直接崩溃。
|
|
|
@@ -69,7 +70,6 @@ Page({
|
|
|
wx.login({
|
|
|
success: function (res) {
|
|
|
if (res.code) {
|
|
|
- console.log(res);
|
|
|
// wx.request({
|
|
|
// url: "https://server.fmode.cn/api/wxapp/auth_wxapp",
|
|
|
// data: {
|
|
|
@@ -211,6 +211,15 @@ Page({
|
|
|
},
|
|
|
|
|
|
async review(force){
|
|
|
+ const showRestriction = (message) => {
|
|
|
+ this.setData({loading:false});
|
|
|
+ wx.showModal({title:'无法登录',content:message,showCancel:false});
|
|
|
+ };
|
|
|
+ const clearLogin = async () => {
|
|
|
+ try { await Parse.User.logOut(); } catch {}
|
|
|
+ wx.removeStorageSync('sessionToken');
|
|
|
+ wx.removeStorageSync('userLogin');
|
|
|
+ };
|
|
|
try {
|
|
|
let options = this.data.options
|
|
|
let url = getApp().globalData.rootPage || getApp().globalData.defaultTabBar.list[0].pagePath
|
|
|
@@ -230,15 +239,29 @@ Page({
|
|
|
}
|
|
|
|
|
|
let currentUser = Parse.User.current()
|
|
|
- console.log('===========================================');
|
|
|
- console.log('======= index.js review 方法 =======');
|
|
|
- console.log('当前用户:', currentUser ? currentUser.id : '无');
|
|
|
- console.log('用户手机号:', currentUser?.get('mobile') || '无');
|
|
|
- console.log('用户名:', currentUser?.get('username') || '无');
|
|
|
- console.log('Session Token:', currentUser?.getSessionToken()?.substring(0, 20) || '无');
|
|
|
- console.log('userLogin 存储:', wx.getStorageSync('userLogin') || '无');
|
|
|
- console.log('force 参数:', force);
|
|
|
- console.log('===========================================');
|
|
|
+ if (currentUser) {
|
|
|
+ const token = currentUser.getSessionToken?.();
|
|
|
+ try {
|
|
|
+ if (!token) throw {code:209};
|
|
|
+ const verified = await Parse.User.become(token);
|
|
|
+ if (!verified?.id || verified.id !== currentUser.id) throw {code:209};
|
|
|
+ currentUser=verified;
|
|
|
+ } catch (err) {
|
|
|
+ if (Number(err?.code)!==209) {
|
|
|
+ this.setData({loading:false});
|
|
|
+ wx.showModal({title:'登录状态待核验',content:'暂时无法连接登录服务,请稍后重试。',showCancel:false});
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ await clearLogin();
|
|
|
+ currentUser=null;
|
|
|
+ }
|
|
|
+ const restriction=restrictionMessageForUser(currentUser);
|
|
|
+ if (restriction) {
|
|
|
+ await clearLogin();
|
|
|
+ showRestriction(restriction);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
// 查询 Company 的 isPublishing 字段
|
|
|
let isPublishing = false;
|
|
|
@@ -290,16 +313,23 @@ Page({
|
|
|
console.log('🔐 是否强制登录:', forceAuth);
|
|
|
|
|
|
let r = await checkAuth(forceAuth);
|
|
|
+ const restriction = restrictionMessage(r);
|
|
|
+ if (restriction) {
|
|
|
+ showRestriction(restriction);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
console.log('===========================================');
|
|
|
console.log('======= checkAuth 返回结果 =======');
|
|
|
- console.log('返回值:', r);
|
|
|
|
|
|
// 重新获取用户信息
|
|
|
currentUser = Parse.User.current();
|
|
|
- console.log('checkAuth 后的用户:', currentUser ? currentUser.id : '无');
|
|
|
- console.log('checkAuth 后的手机号:', currentUser?.get('mobile') || '无');
|
|
|
- console.log('checkAuth 后的 Session Token:', currentUser?.getSessionToken()?.substring(0, 20) || '无');
|
|
|
+ const activeRestriction = restrictionMessageForUser(currentUser);
|
|
|
+ if (activeRestriction) {
|
|
|
+ await clearLogin();
|
|
|
+ showRestriction(activeRestriction);
|
|
|
+ return;
|
|
|
+ }
|
|
|
console.log('===========================================');
|
|
|
|
|
|
// 如果强制登录但用户未登录,不允许继续访问
|
|
|
@@ -317,10 +347,8 @@ Page({
|
|
|
if (currentUser && currentUser.get('mobile')) {
|
|
|
wx.setStorageSync("userLogin", currentUser.id);
|
|
|
console.log('✅ 授权登录成功,已设置 userLogin:', currentUser.id);
|
|
|
- console.log('✅ 用户手机号:', currentUser.get('mobile'));
|
|
|
} else {
|
|
|
console.warn('⚠️ checkAuth 返回成功,但用户没有手机号!');
|
|
|
- console.warn(' 用户对象:', currentUser);
|
|
|
}
|
|
|
|
|
|
// 禁用扫码相关统计/来源记录
|
|
|
@@ -404,10 +432,15 @@ Page({
|
|
|
});
|
|
|
}
|
|
|
catch (err) {
|
|
|
- console.log('❌ review 方法出错:', err);
|
|
|
+ const restriction = restrictionMessage(err);
|
|
|
+ if (restriction) {
|
|
|
+ showRestriction(restriction);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ console.log('登录未完成');
|
|
|
|
|
|
/* 登录身份信息到期,重新登陆 */
|
|
|
- if((err?.message?.indexOf('Session token is expired') != -1 || err?.message?.indexOf('Invalid session token') != -1) && !force){
|
|
|
+ if((Number(err?.code)===209 || /Session token is expired|Invalid session token/.test(err?.message || '')) && !force){
|
|
|
console.log('⚠️ Session Token 过期,准备重新登录');
|
|
|
|
|
|
// 保存需要保留的数据
|