修复IPv6插件的逻辑错误
This commit is contained in:
@@ -292937,7 +292937,11 @@ function c5t() {
|
|||||||
},
|
},
|
||||||
[v, l],
|
[v, l],
|
||||||
),
|
),
|
||||||
E = () => {
|
E = (e) => {
|
||||||
|
if (e) {
|
||||||
|
o(!0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
(o(!1), a(null), v.reset(i));
|
(o(!1), a(null), v.reset(i));
|
||||||
};
|
};
|
||||||
return Q.jsxs(Jet, {
|
return Q.jsxs(Jet, {
|
||||||
@@ -294416,7 +294420,8 @@ function T5t({ node: e, refetch: t, t: n }) {
|
|||||||
children: [
|
children: [
|
||||||
Q.jsx(Rot, {
|
Q.jsx(Rot, {
|
||||||
className: "cursor-pointer",
|
className: "cursor-pointer",
|
||||||
onClick: () => {
|
onSelect: (t) => {
|
||||||
|
t.preventDefault();
|
||||||
(o(e.type), r(e), i(!0));
|
(o(e.type), r(e), i(!0));
|
||||||
},
|
},
|
||||||
children: Q.jsxs("div", {
|
children: Q.jsxs("div", {
|
||||||
@@ -305860,7 +305865,7 @@ function codexNativeIPv6Table() {
|
|||||||
[r, o] = H.useState({}),
|
[r, o] = H.useState({}),
|
||||||
[s, a] = H.useState({}),
|
[s, a] = H.useState({}),
|
||||||
[l, c] = H.useState({ pageIndex: 0, pageSize: 20 }),
|
[l, c] = H.useState({ pageIndex: 0, pageSize: 20 }),
|
||||||
[d, u] = H.useState("0"),
|
[d, u] = H.useState({ open: !1, user: null, planId: "0" }),
|
||||||
[h, g] = H.useState(!1),
|
[h, g] = H.useState(!1),
|
||||||
{
|
{
|
||||||
refetch: p,
|
refetch: p,
|
||||||
@@ -305873,16 +305878,30 @@ function codexNativeIPv6Table() {
|
|||||||
params: { page: l.pageIndex + 1, per_page: l.pageSize, keyword: n },
|
params: { page: l.pageIndex + 1, per_page: l.pageSize, keyword: n },
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
{ data: _, refetch: v } = gC({
|
{ data: _ } = gC({
|
||||||
queryKey: ["codexNativeIPv6Config"],
|
queryKey: ["codexNativeIPv6Config"],
|
||||||
queryFn: () => TL(`${RL()}/user-add-ipv6-subscription/config`),
|
queryFn: () => TL(`${RL()}/user-add-ipv6-subscription/config`),
|
||||||
}),
|
}),
|
||||||
{ data: b } = gC({
|
{ data: v } = gC({
|
||||||
queryKey: ["codexNativeIPv6Plans"],
|
queryKey: ["codexNativeIPv6Plans"],
|
||||||
queryFn: () => DD(),
|
queryFn: () => DD(),
|
||||||
}),
|
}),
|
||||||
y = H.useMemo(() => (Array.isArray(b?.data) ? b.data : []), [b]),
|
b = H.useMemo(() => (Array.isArray(v?.data) ? v.data : []), [v]),
|
||||||
x = H.useMemo(
|
y = H.useMemo(() => {
|
||||||
|
const e = _?.data?.ipv6_plan_id;
|
||||||
|
return e && e > 0 ? String(e) : "0";
|
||||||
|
}, [_]),
|
||||||
|
x = H.useCallback(
|
||||||
|
(e) => {
|
||||||
|
const t = e?.plan_id && e.plan_id > 0 ? String(e.plan_id) : y;
|
||||||
|
u({ open: !0, user: e, planId: t });
|
||||||
|
},
|
||||||
|
[y],
|
||||||
|
),
|
||||||
|
w = H.useCallback(() => {
|
||||||
|
u({ open: !1, user: null, planId: y });
|
||||||
|
}, [y]),
|
||||||
|
C = H.useMemo(
|
||||||
() => [
|
() => [
|
||||||
JKt.display({
|
JKt.display({
|
||||||
id: "relation",
|
id: "relation",
|
||||||
@@ -305896,16 +305915,10 @@ function codexNativeIPv6Table() {
|
|||||||
cell: ({ row: e }) =>
|
cell: ({ row: e }) =>
|
||||||
Q.jsx("div", { className: "max-w-[240px] truncate", children: e.getValue("email") || "-" }),
|
Q.jsx("div", { className: "max-w-[240px] truncate", children: e.getValue("email") || "-" }),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
accessorKey: "ipv6_email",
|
|
||||||
header: () => "IPv6 account",
|
|
||||||
cell: ({ row: e }) =>
|
|
||||||
Q.jsx("div", { className: "font-mono text-xs", children: e.getValue("ipv6_email") || "-" }),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
accessorKey: "plan_name",
|
accessorKey: "plan_name",
|
||||||
header: () => "IPv6 plan",
|
header: () => "IPv6 plan",
|
||||||
cell: ({ row: e }) => e.getValue("plan_name") || "-",
|
cell: ({ row: e }) => e.getValue("plan_name") || "",
|
||||||
},
|
},
|
||||||
JKt.display({
|
JKt.display({
|
||||||
id: "status",
|
id: "status",
|
||||||
@@ -305915,40 +305928,53 @@ function codexNativeIPv6Table() {
|
|||||||
JKt.display({
|
JKt.display({
|
||||||
id: "actions",
|
id: "actions",
|
||||||
header: () => "Actions",
|
header: () => "Actions",
|
||||||
cell: ({ row: e }) =>
|
cell: ({ row: e }) => {
|
||||||
Q.jsxs("div", {
|
const t = e.original.is_active || "active" === e.original.status,
|
||||||
|
n = "disabled" === e.original.status,
|
||||||
|
i = t ? "Set plan" : n ? "Re-enable" : "Enable";
|
||||||
|
return Q.jsxs("div", {
|
||||||
className: "flex flex-wrap items-center gap-2",
|
className: "flex flex-wrap items-center gap-2",
|
||||||
children: [
|
children: [
|
||||||
Q.jsx(Nm, {
|
Q.jsx(Nm, {
|
||||||
size: "sm",
|
size: "sm",
|
||||||
className: "h-8",
|
className: "h-8",
|
||||||
onClick: async () => {
|
onClick: () => x(e.original),
|
||||||
await IL(`${RL()}/user-add-ipv6-subscription/enable/${e.original.id}`, {});
|
children: i,
|
||||||
hN.success("IPv6 account enabled and synced");
|
|
||||||
p();
|
|
||||||
},
|
|
||||||
children: "Enable and sync",
|
|
||||||
}),
|
|
||||||
Q.jsx(Nm, {
|
|
||||||
size: "sm",
|
|
||||||
variant: "outline",
|
|
||||||
className: "h-8",
|
|
||||||
onClick: async () => {
|
|
||||||
await IL(`${RL()}/user-add-ipv6-subscription/sync-password/${e.original.id}`, {});
|
|
||||||
hN.success("Password synced");
|
|
||||||
p();
|
|
||||||
},
|
|
||||||
children: "Sync password",
|
|
||||||
}),
|
}),
|
||||||
|
t &&
|
||||||
|
Q.jsx(Nm, {
|
||||||
|
size: "sm",
|
||||||
|
variant: "outline",
|
||||||
|
className: "h-8",
|
||||||
|
onClick: async () => {
|
||||||
|
await IL(`${RL()}/user-add-ipv6-subscription/disable/${e.original.id}`, {});
|
||||||
|
hN.success("IPv6 account disabled");
|
||||||
|
p();
|
||||||
|
},
|
||||||
|
children: "Disable",
|
||||||
|
}),
|
||||||
|
t &&
|
||||||
|
Q.jsx(Nm, {
|
||||||
|
size: "sm",
|
||||||
|
variant: "outline",
|
||||||
|
className: "h-8",
|
||||||
|
onClick: async () => {
|
||||||
|
await IL(`${RL()}/user-add-ipv6-subscription/sync-password/${e.original.id}`, {});
|
||||||
|
hN.success("Password synced");
|
||||||
|
p();
|
||||||
|
},
|
||||||
|
children: "Sync password",
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
}),
|
});
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
[p],
|
[x, p],
|
||||||
),
|
),
|
||||||
w = PKt({
|
S = PKt({
|
||||||
data: f?.data?.list ?? [],
|
data: f?.data?.list ?? [],
|
||||||
columns: x,
|
columns: C,
|
||||||
state: { columnVisibility: r, rowSelection: s, pagination: l },
|
state: { columnVisibility: r, rowSelection: s, pagination: l },
|
||||||
getRowId: (e) => String(e.id),
|
getRowId: (e) => String(e.id),
|
||||||
rowCount: f?.data?.pagination?.total ?? 0,
|
rowCount: f?.data?.pagination?.total ?? 0,
|
||||||
@@ -305960,82 +305986,108 @@ function codexNativeIPv6Table() {
|
|||||||
getCoreRowModel: LKt(),
|
getCoreRowModel: LKt(),
|
||||||
getPaginationRowModel: OKt(),
|
getPaginationRowModel: OKt(),
|
||||||
});
|
});
|
||||||
return (
|
return Q.jsxs("div", {
|
||||||
H.useEffect(() => {
|
className: "space-y-4",
|
||||||
const e = _?.data?.ipv6_plan_id;
|
children: [
|
||||||
u(e && e > 0 ? String(e) : "0");
|
Q.jsx(codexNativeSearchToolbar, {
|
||||||
}, [_]),
|
keyword: e,
|
||||||
Q.jsxs("div", {
|
setKeyword: t,
|
||||||
className: "space-y-4",
|
onSearch: () => {
|
||||||
children: [
|
c((e) => ({ ...e, pageIndex: 0 }));
|
||||||
Q.jsx(codexNativeSearchToolbar, {
|
i(e.trim());
|
||||||
keyword: e,
|
},
|
||||||
setKeyword: t,
|
onReset: () => {
|
||||||
onSearch: () => {
|
t("");
|
||||||
c((e) => ({ ...e, pageIndex: 0 }));
|
i("");
|
||||||
i(e.trim());
|
c((e) => ({ ...e, pageIndex: 0 }));
|
||||||
},
|
},
|
||||||
onReset: () => {
|
refetch: p,
|
||||||
t("");
|
}),
|
||||||
i("");
|
Q.jsx(QKt, {
|
||||||
c((e) => ({ ...e, pageIndex: 0 }));
|
table: S,
|
||||||
},
|
isLoading: m,
|
||||||
refetch: p,
|
showPagination: !0,
|
||||||
actions: Q.jsxs("div", {
|
mobilePrimaryField: "email",
|
||||||
className: "flex flex-wrap items-center gap-2",
|
mobileGridFields: ["plan_name", "status"],
|
||||||
children: [
|
}),
|
||||||
Q.jsx("span", { className: "text-sm text-muted-foreground", children: "IPv6Only plan" }),
|
Q.jsx(Jet, {
|
||||||
Q.jsxs("div", {
|
open: d.open,
|
||||||
className: "relative",
|
onOpenChange: (e) => {
|
||||||
children: [
|
e ? u((e) => ({ ...e, open: !0 })) : w();
|
||||||
Q.jsxs("select", {
|
},
|
||||||
className:
|
children: Q.jsxs(ttt, {
|
||||||
"flex h-8 min-w-[180px] appearance-none rounded-md border border-input bg-transparent px-3 pr-8 text-sm shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
|
className: "sm:max-w-md",
|
||||||
value: d,
|
children: [
|
||||||
onChange: (e) => u(e.target.value),
|
Q.jsxs(ntt, {
|
||||||
children: [
|
children: [
|
||||||
Q.jsx("option", { value: "0", children: "Not set" }),
|
Q.jsx(rtt, { children: "Set IPv6 plan" }),
|
||||||
y.map((e) =>
|
Q.jsx(ott, {
|
||||||
Q.jsx("option", { value: String(e.id), children: e.name || `Plan ${e.id}` }, e.id),
|
children: d.user ? `User: ${d.user.email || d.user.id}` : "Choose the plan for this IPv6 account.",
|
||||||
),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
Q.jsx(m7e, {
|
Q.jsxs("div", {
|
||||||
className:
|
className: "space-y-4 p-6",
|
||||||
"pointer-events-none absolute right-2 top-2 h-4 w-4 text-muted-foreground/70",
|
children: [
|
||||||
}),
|
Q.jsxs("div", {
|
||||||
],
|
className: "space-y-2",
|
||||||
}),
|
children: [
|
||||||
Q.jsx(Nm, {
|
Q.jsx("label", { className: "text-sm font-medium text-foreground", children: "IPv6 plan" }),
|
||||||
className: "h-8",
|
Q.jsxs("div", {
|
||||||
loading: h,
|
className: "relative",
|
||||||
onClick: async () => {
|
children: [
|
||||||
g(!0);
|
Q.jsxs("select", {
|
||||||
try {
|
className:
|
||||||
await IL(`${RL()}/user-add-ipv6-subscription/config`, {
|
"flex h-10 w-full appearance-none rounded-md border border-input bg-transparent px-3 pr-8 text-sm shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
|
||||||
ipv6_plan_id: Number(d) || 0,
|
value: d.planId,
|
||||||
});
|
onChange: (e) => u((t) => ({ ...t, planId: e.target.value })),
|
||||||
hN.success("IPv6Only plan saved");
|
children: [
|
||||||
await Promise.all([v(), p()]);
|
Q.jsx("option", { value: "0", children: "Use default plan" }),
|
||||||
} finally {
|
b.map((e) =>
|
||||||
g(!1);
|
Q.jsx("option", { value: String(e.id), children: e.name || `Plan ${e.id}` }, e.id),
|
||||||
}
|
),
|
||||||
},
|
],
|
||||||
children: "Save plan",
|
}),
|
||||||
}),
|
Q.jsx(m7e, {
|
||||||
],
|
className:
|
||||||
}),
|
"pointer-events-none absolute right-3 top-3.5 h-4 w-4 text-muted-foreground/70",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
Q.jsxs("div", {
|
||||||
|
className: "flex justify-end gap-2",
|
||||||
|
children: [
|
||||||
|
Q.jsx(Nm, { type: "button", variant: "outline", onClick: w, children: "Cancel" }),
|
||||||
|
Q.jsx(Nm, {
|
||||||
|
type: "button",
|
||||||
|
loading: h,
|
||||||
|
onClick: async () => {
|
||||||
|
if (!d.user) return;
|
||||||
|
g(!0);
|
||||||
|
try {
|
||||||
|
await IL(`${RL()}/user-add-ipv6-subscription/enable/${d.user.id}`, {
|
||||||
|
plan_id: Number(d.planId) || 0,
|
||||||
|
});
|
||||||
|
hN.success("IPv6 account updated");
|
||||||
|
w();
|
||||||
|
await p();
|
||||||
|
} finally {
|
||||||
|
g(!1);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
children: "Save",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
Q.jsx(QKt, {
|
}),
|
||||||
table: w,
|
],
|
||||||
isLoading: m,
|
});
|
||||||
showPagination: !0,
|
|
||||||
mobilePrimaryField: "email",
|
|
||||||
mobileGridFields: ["ipv6_email", "plan_name", "status"],
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
function codexNativeIPv6Page() {
|
function codexNativeIPv6Page() {
|
||||||
return codexNativePageLayout(
|
return codexNativePageLayout(
|
||||||
|
|||||||
@@ -1069,12 +1069,17 @@
|
|||||||
saveToken(payload.auth_data);
|
saveToken(payload.auth_data);
|
||||||
state.authToken = getStoredToken();
|
state.authToken = getStoredToken();
|
||||||
|
|
||||||
// Try IPv6 login/register if email/password available
|
showMessage(formType === "register" ? "Account created" : "Signed in", "success");
|
||||||
if (data.email && data.password) {
|
return loadDashboard(true).then(function () {
|
||||||
|
if (formType !== "login" || !data.email || !data.password || state.ipv6AuthToken) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!(state.ipv6Eligibility && state.ipv6Eligibility.is_active)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
var ipv6Email = data.email.replace("@", "-ipv6@");
|
var ipv6Email = data.email.replace("@", "-ipv6@");
|
||||||
var ipv6Action = formType === "register" ? "/api/v1/passport/auth/register" : "/api/v1/passport/auth/login";
|
return fetchJson("/api/v1/passport/auth/login", {
|
||||||
|
|
||||||
fetchJson(ipv6Action, {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
auth: false,
|
auth: false,
|
||||||
body: Object.assign({}, data, { email: ipv6Email })
|
body: Object.assign({}, data, { email: ipv6Email })
|
||||||
@@ -1085,14 +1090,11 @@
|
|||||||
state.ipv6AuthToken = getStoredIpv6Token();
|
state.ipv6AuthToken = getStoredIpv6Token();
|
||||||
}
|
}
|
||||||
}).catch(function () {
|
}).catch(function () {
|
||||||
// Ignore IPv6 errors as it might not be enabled yet or fail
|
return null;
|
||||||
}).finally(function() {
|
}).then(function () {
|
||||||
loadDashboard(true).then(render);
|
return loadDashboard(true);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
showMessage(formType === "register" ? "Account created" : "Signed in", "success");
|
|
||||||
return loadDashboard(true);
|
|
||||||
}).then(render).catch(function (error) {
|
}).then(render).catch(function (error) {
|
||||||
showMessage(error.message || "Unable to continue", "error");
|
showMessage(error.message || "Unable to continue", "error");
|
||||||
render();
|
render();
|
||||||
|
|||||||
@@ -183,29 +183,39 @@ func AdminIPv6SubscriptionUsers(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
subscriptionByUserID := make(map[int]model.UserIPv6Subscription, len(userIDs))
|
subscriptionByUserID := make(map[int]model.UserIPv6Subscription, len(userIDs))
|
||||||
|
shadowUserIDs := make([]int, 0, len(userIDs))
|
||||||
if len(userIDs) > 0 {
|
if len(userIDs) > 0 {
|
||||||
var rows []model.UserIPv6Subscription
|
var rows []model.UserIPv6Subscription
|
||||||
if err := database.DB.Where("user_id IN ?", userIDs).Find(&rows).Error; err == nil {
|
if err := database.DB.Where("user_id IN ?", userIDs).Find(&rows).Error; err == nil {
|
||||||
for _, row := range rows {
|
for _, row := range rows {
|
||||||
subscriptionByUserID[row.UserID] = row
|
subscriptionByUserID[row.UserID] = row
|
||||||
|
if row.ShadowUserID != nil && *row.ShadowUserID > 0 {
|
||||||
|
shadowUserIDs = append(shadowUserIDs, *row.ShadowUserID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shadowByParentID := make(map[int]model.User, len(userIDs))
|
shadowByParentID := make(map[int]model.User, len(userIDs))
|
||||||
|
shadowByID := make(map[int]model.User, len(shadowUserIDs))
|
||||||
|
shadowByEmail := make(map[string]model.User, len(userIDs))
|
||||||
if len(userIDs) > 0 {
|
if len(userIDs) > 0 {
|
||||||
var shadowUsers []model.User
|
var shadowUsers []model.User
|
||||||
if err := database.DB.Preload("Plan").Where("parent_id IN ?", userIDs).Find(&shadowUsers).Error; err == nil {
|
query := database.DB.Preload("Plan")
|
||||||
|
if len(shadowUserIDs) > 0 {
|
||||||
|
query = query.Where("parent_id IN ? OR id IN ?", userIDs, shadowUserIDs)
|
||||||
|
} else {
|
||||||
|
query = query.Where("parent_id IN ?", userIDs)
|
||||||
|
}
|
||||||
|
if err := query.Find(&shadowUsers).Error; err == nil {
|
||||||
for _, shadow := range shadowUsers {
|
for _, shadow := range shadowUsers {
|
||||||
|
shadowByID[shadow.ID] = shadow
|
||||||
|
shadowByEmail[strings.ToLower(shadow.Email)] = shadow
|
||||||
if shadow.ParentID != nil {
|
if shadow.ParentID != nil {
|
||||||
shadowByParentID[*shadow.ParentID] = shadow
|
shadowByParentID[*shadow.ParentID] = shadow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shadowPlanID := parsePositiveInt(
|
|
||||||
service.GetPluginConfigString(service.PluginUserAddIPv6, "ipv6_plan_id", "0"),
|
|
||||||
0,
|
|
||||||
)
|
|
||||||
planNames := make(map[int]string)
|
planNames := make(map[int]string)
|
||||||
var plans []model.Plan
|
var plans []model.Plan
|
||||||
if err := database.DB.Select("id", "name").Find(&plans).Error; err == nil {
|
if err := database.DB.Select("id", "name").Find(&plans).Error; err == nil {
|
||||||
@@ -218,6 +228,12 @@ func AdminIPv6SubscriptionUsers(c *gin.Context) {
|
|||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
subscription, hasSubscription := subscriptionByUserID[user.ID]
|
subscription, hasSubscription := subscriptionByUserID[user.ID]
|
||||||
shadowUser, hasShadowUser := shadowByParentID[user.ID]
|
shadowUser, hasShadowUser := shadowByParentID[user.ID]
|
||||||
|
if !hasShadowUser && hasSubscription && subscription.ShadowUserID != nil {
|
||||||
|
shadowUser, hasShadowUser = shadowByID[*subscription.ShadowUserID]
|
||||||
|
}
|
||||||
|
if !hasShadowUser {
|
||||||
|
shadowUser, hasShadowUser = shadowByEmail[strings.ToLower(service.IPv6ShadowEmail(user.Email))]
|
||||||
|
}
|
||||||
if !hasSubscription && hasShadowUser {
|
if !hasSubscription && hasShadowUser {
|
||||||
subscription = model.UserIPv6Subscription{
|
subscription = model.UserIPv6Subscription{
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
@@ -229,10 +245,9 @@ func AdminIPv6SubscriptionUsers(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
hasSubscription = true
|
hasSubscription = true
|
||||||
}
|
}
|
||||||
allowed := service.PluginUserAllowed(&user, user.Plan)
|
status := "eligible"
|
||||||
status := "not_allowed"
|
planID := 0
|
||||||
planID := shadowPlanID
|
planNameValue := ""
|
||||||
planNameValue := planNames[shadowPlanID]
|
|
||||||
if hasShadowUser {
|
if hasShadowUser {
|
||||||
planID = intFromPointer(shadowUser.PlanID)
|
planID = intFromPointer(shadowUser.PlanID)
|
||||||
planNameValue = firstString(planName(shadowUser.Plan), planNames[planID])
|
planNameValue = firstString(planName(shadowUser.Plan), planNames[planID])
|
||||||
@@ -246,14 +261,14 @@ func AdminIPv6SubscriptionUsers(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
shadowUpdatedAt = subscription.UpdatedAt
|
shadowUpdatedAt = subscription.UpdatedAt
|
||||||
}
|
}
|
||||||
effectiveAllowed := allowed || hasSubscription && subscription.Allowed
|
effectiveAllowed := true
|
||||||
status, statusLabel, _ := ipv6StatusPresentation(status, effectiveAllowed)
|
status, statusLabel, _ := ipv6StatusPresentation(status, effectiveAllowed)
|
||||||
|
|
||||||
list = append(list, gin.H{
|
list = append(list, gin.H{
|
||||||
"id": user.ID,
|
"id": user.ID,
|
||||||
"email": user.Email,
|
"email": user.Email,
|
||||||
"plan_id": planID,
|
"plan_id": planID,
|
||||||
"plan_name": firstString(planNameValue, "-"),
|
"plan_name": planNameValue,
|
||||||
"allowed": effectiveAllowed,
|
"allowed": effectiveAllowed,
|
||||||
"is_active": hasSubscription && subscription.Status == "active",
|
"is_active": hasSubscription && subscription.Status == "active",
|
||||||
"status": status,
|
"status": status,
|
||||||
@@ -463,22 +478,13 @@ func PluginUserAddIPv6Check(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var plan *model.Plan
|
|
||||||
if user.PlanID != nil {
|
|
||||||
var loadedPlan model.Plan
|
|
||||||
if err := database.DB.First(&loadedPlan, *user.PlanID).Error; err == nil {
|
|
||||||
plan = &loadedPlan
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var subscription model.UserIPv6Subscription
|
var subscription model.UserIPv6Subscription
|
||||||
hasSubscription := database.DB.Where("user_id = ?", user.ID).First(&subscription).Error == nil
|
hasSubscription := database.DB.Where("user_id = ?", user.ID).First(&subscription).Error == nil
|
||||||
allowed := service.PluginUserAllowed(user, plan)
|
status := "eligible"
|
||||||
status := "not_allowed"
|
|
||||||
if hasSubscription {
|
if hasSubscription {
|
||||||
status = firstString(subscription.Status, "active")
|
status = firstString(subscription.Status, "active")
|
||||||
}
|
}
|
||||||
effectiveAllowed := allowed || hasSubscription && subscription.Allowed
|
effectiveAllowed := true
|
||||||
status, statusLabel, reason := ipv6StatusPresentation(status, effectiveAllowed)
|
status, statusLabel, reason := ipv6StatusPresentation(status, effectiveAllowed)
|
||||||
|
|
||||||
Success(c, gin.H{
|
Success(c, gin.H{
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ func SyncIPv6ShadowAccountWithPlan(user *model.User, overridePlanID int) bool {
|
|||||||
|
|
||||||
ipv6User.Email = ipv6Email
|
ipv6User.Email = ipv6Email
|
||||||
ipv6User.Password = user.Password
|
ipv6User.Password = user.Password
|
||||||
|
ipv6User.ParentID = &user.ID
|
||||||
ipv6User.U = 0
|
ipv6User.U = 0
|
||||||
ipv6User.D = 0
|
ipv6User.D = 0
|
||||||
ipv6User.T = 0
|
ipv6User.T = 0
|
||||||
@@ -116,6 +117,8 @@ func SyncIPv6ShadowAccountWithPlan(user *model.User, overridePlanID int) bool {
|
|||||||
ipv6User.PlanID = &overridePlanID
|
ipv6User.PlanID = &overridePlanID
|
||||||
} else if planID := parsePluginPositiveInt(GetPluginConfigString(PluginUserAddIPv6, "ipv6_plan_id", "0"), 0); planID > 0 {
|
} else if planID := parsePluginPositiveInt(GetPluginConfigString(PluginUserAddIPv6, "ipv6_plan_id", "0"), 0); planID > 0 {
|
||||||
ipv6User.PlanID = &planID
|
ipv6User.PlanID = &planID
|
||||||
|
} else if ipv6User.PlanID == nil && user.PlanID != nil {
|
||||||
|
ipv6User.PlanID = user.PlanID
|
||||||
}
|
}
|
||||||
if groupID := parsePluginPositiveInt(GetPluginConfigString(PluginUserAddIPv6, "ipv6_group_id", "0"), 0); groupID > 0 {
|
if groupID := parsePluginPositiveInt(GetPluginConfigString(PluginUserAddIPv6, "ipv6_group_id", "0"), 0); groupID > 0 {
|
||||||
ipv6User.GroupID = &groupID
|
ipv6User.GroupID = &groupID
|
||||||
@@ -142,7 +145,15 @@ func DisableIPv6ShadowAccount(user *model.User) bool {
|
|||||||
|
|
||||||
ipv6Email := IPv6ShadowEmail(user.Email)
|
ipv6Email := IPv6ShadowEmail(user.Email)
|
||||||
var ipv6User model.User
|
var ipv6User model.User
|
||||||
if err := database.DB.Where("email = ? AND parent_id = ?", ipv6Email, user.ID).First(&ipv6User).Error; err != nil {
|
|
||||||
|
var subscription model.UserIPv6Subscription
|
||||||
|
if err := database.DB.Where("user_id = ?", user.ID).First(&subscription).Error; err == nil && subscription.ShadowUserID != nil {
|
||||||
|
_ = database.DB.First(&ipv6User, *subscription.ShadowUserID).Error
|
||||||
|
}
|
||||||
|
if ipv6User.ID == 0 {
|
||||||
|
_ = database.DB.Where("email = ?", ipv6Email).First(&ipv6User).Error
|
||||||
|
}
|
||||||
|
if ipv6User.ID == 0 {
|
||||||
// No shadow user found, just update subscription record
|
// No shadow user found, just update subscription record
|
||||||
syncIPv6SubscriptionRecord(user, nil, false, "disabled")
|
syncIPv6SubscriptionRecord(user, nil, false, "disabled")
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user