Skip to content

Commit

Permalink
Merge pull request #7 from NJUPT-SAST/dev-max
Browse files Browse the repository at this point in the history
fix: 修复跳转
  • Loading branch information
MaxtuneLee authored Mar 20, 2024
2 parents 6a83877 + fabd19f commit 79a4b20
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 35 deletions.
17 changes: 7 additions & 10 deletions app/(tourist)/login/2/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@ import { useAppDispatch, useAppSelector } from "@/redux";
import Link from "next/link";
import styles from "../page.module.scss";
import PageTransition from "@/components/pageTransition";
import { addRedirect, clearLoginMessage } from "@/redux/features/login";

const LoginStep2 = () => {
const tokenRef = useRef<string>("");
const dispatch = useAppDispatch();
const inputRef = useRef<HTMLInputElement>(null);
const router = useRouter();
const [loading, setLoading] = useState<boolean>(false);
const { redirect, loginTicket } = useAppSelector(
(state) => state.loginMessage,
);
const redirect_uri = useAppSelector((state) => state.loginMessage.redirect);
const { loginTicket } = useAppSelector((state) => state.loginMessage);
// const redirect_uri = useAppSelector((state) => state.loginMessage.redirect);
const urlParams = useSearchParams();
const redirect_uri = atob(urlParams.get("redirect") ?? "");
const [error, setError] = useState<
{ error: false } | { error: true; errMsg: string }
>({ error: false });
Expand Down Expand Up @@ -79,12 +77,11 @@ const LoginStep2 = () => {
}),
);
//dispatch(login({ username: "ming", email: data.email }));
if (redirect_uri) {
if (urlParams.get("redirect") !== null) {
console.log(redirect_uri);
location.href = redirect_uri;
dispatch(clearLoginMessage());
router.push(redirect_uri);
} else {
router.replace(redirect ?? "/home");
router.push(redirect_uri ?? "/home");
}
return;
}
Expand Down Expand Up @@ -143,7 +140,7 @@ const LoginStep2 = () => {
}}
type="submit"
>
{redirect ? "登录并前往授权" : "登录 SAST Link"}
{redirect_uri !== "" ? "登录并前往授权" : "登录 SAST Link"}
</Button>
<Button onClick={() => router.replace("../")} type="button" white>
使用其他账号
Expand Down
17 changes: 0 additions & 17 deletions app/(tourist)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,7 @@ import { useAppDispatch, useAppSelector } from "@/redux";
import { addRedirect } from "@/redux/features/login";

const Login = () => {
const searchParams = useSearchParams();
// TODO 错误处理
function formatRedirectParams(redirectParams: string | null) {
if (redirectParams === null) return null;
const redirectArray = redirectParams.split("?");
if (redirectArray.length > 2) {
return redirectArray[0] + "?" + JSON.parse(redirectArray[1]).join("&");
}
return null;
}
const redirectParams = searchParams.get("redirect");
const redirect = formatRedirectParams(redirectParams);
const dispatch = useAppDispatch();
useEffect(() => {
if (!!redirect) {
dispatch(addRedirect(redirect));
}
}, [redirect, dispatch]);
return (
<>
<LoginStep1 />
Expand Down
6 changes: 3 additions & 3 deletions app/(user)/auth/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { useAppDispatch } from "@/redux";
import { addRedirect } from "@/redux/features/login";

export default function Auth() {
// TODO
const appName = "SAST Evento";
// TODO 应用名称
const appName = "应用";
const [userData, setUserData] = useState<{ email: string; userId: string }>();
// 获取参数
const router = useRouter();
Expand Down Expand Up @@ -45,7 +45,7 @@ export default function Auth() {
(querys as any)[key] = searchParams.get(key);
return `${key}=${searchParams.get(key)}`;
});
const redirect = `/auth?${querysArray.join("&")}`;
const redirect = btoa(`/auth?${querysArray.join("&")}`);
useEffect(
() => {
if (localStorage.getItem("Token") === null) {
Expand Down
1 change: 1 addition & 0 deletions app/(user)/home/@appPanel/default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useAppDispatch, useAppSelector } from "@/redux";
import { handleHomeAppPanel } from "@/redux/features/panelState";
import { message } from "@/components/message";

// million-ignore
const AppPanel = () => {
const appPanelState = useAppSelector(
(state) => state.panelState.homeAppPanel,
Expand Down
2 changes: 1 addition & 1 deletion app/(user)/home/@profilePanel/default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useAppSelector } from "@/redux";

const ProfilePanel = () => {
const userBasicInfo = useAppSelector((state) => state.userBasicInfo);
console.log(userBasicInfo);
// console.log(userBasicInfo);
const pathname = usePathname();
return (
<>
Expand Down
2 changes: 1 addition & 1 deletion app/(user)/home/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Layout = (props: {
profilePanel: ReactNode;
getInfo: ReactNode;
}) => {
console.log(props);
// console.log(props);
const { children, infoPanel, appPanel, profilePanel, getInfo } = props;
return (
<>
Expand Down
2 changes: 1 addition & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ReduxProvider } from "@/redux/reduxProvider";
import { SWRProvider } from "@/components/swrProvider";
import "./globals.scss";

export const metadata = {
const metadata = {
title: "SAST Link",
description: "OAuth of SAST",
};
Expand Down
1 change: 1 addition & 0 deletions components/message/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let GlobalMessagePanel: () => JSX.Element | null;

const message = Messagefn();

/*million ignore*/
function Messagefn() {
let id: NodeJS.Timeout;
let dispatch: any = null;
Expand Down
1 change: 1 addition & 0 deletions components/topbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Logo, MenuIcon } from "../icon";
import Image from "next/image";
import avatar from "@public/defaultAvatar.png";

// million-ignore
const TopBar = () => {
const dispatch = useAppDispatch();
const userBasicInfo = useAppSelector((state) => state.userBasicInfo);
Expand Down
2 changes: 1 addition & 1 deletion components/veriCode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const VeriCode = (props: { reset?: true }) => {
aria-disabled={clickable}
onClick={() => {
setClickable(false);
console.log(resetContext.username);
// console.log(resetContext.username);
veriResetAccount(resetContext.username ?? "")
.then((res) => {
if (res.data.Success) {
Expand Down
2 changes: 1 addition & 1 deletion lib/apis/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function oAuth(data: oAuthType) {
"&" +
"part=" +
JSON.parse(localStorage.getItem("Token") ?? "");
console.log(query);
// console.log(query);
// TODO 更改为部署后地址
return (window.location.href = `http://81.68.225.220:8080/api/v1/oauth2/authorize?${query}`);
}

0 comments on commit 79a4b20

Please sign in to comment.