diff --git a/src/index.tsx b/src/index.tsx index f4ac328..5debccb 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -5,8 +5,9 @@ import { PageLogin } from './pages/login' import { BrowserRouter, Route, Routes } from 'react-router-dom' import { PageNotFound } from './pages/notfound' import { PageRegister } from './pages/register' +import { PageInfo } from './pages/info' -const API_BASE_ADDRESS = "http://127.0.0.1:30" +const API_BASE_ADDRESS = "https://api.charmless.today" export const api = (path: string) => API_BASE_ADDRESS + path @@ -41,6 +42,7 @@ const LSPYggdrasilWebApp = () => { } /> } /> + } /> } /> diff --git a/src/pages/info.tsx b/src/pages/info.tsx new file mode 100644 index 0000000..ba29e82 --- /dev/null +++ b/src/pages/info.tsx @@ -0,0 +1,59 @@ +import { useRef, useState } from "react" +import axios from "axios" +import { api } from ".." + +export const PageInfo = () => { + const fileRef = useRef(null) + const [error, setError] = useState("没上传/没报错") + const [disableBtn, setDisableBtn] = useState(false) + + return
+

+ 总之如果你能看到这里说明你登陆成功了,下面是你的账号信息: Key(别发给别人)={window.sessionStorage.getItem('identifier')}, Textures={window.sessionStorage.getItem('textures')}, Username={window.sessionStorage.getItem('username')}, UUID={window.sessionStorage.getItem('uuid')} +

+ +

+ 神马?你问我改密码?我懒得做,真要改找lama +

+ +

+ 为什么这个页面成这个B样子了?因为我没时间做了,你就说能不能用吧 +

+ +

+ 登出?自己关了这个页面就登出了 +

+ + + + + +

皮肤上传报错:{error}

+
+} \ No newline at end of file diff --git a/src/pages/login.tsx b/src/pages/login.tsx index 2ac8614..5ee57fa 100644 --- a/src/pages/login.tsx +++ b/src/pages/login.tsx @@ -1,4 +1,4 @@ -import { Box, Button, CssBaseline, Grid, Link, Paper, TextField, ThemeProvider, Typography, Alert, Collapse } from "@mui/material" +import { Box, Button, CssBaseline, Grid, Paper, TextField, ThemeProvider, Typography, Alert, Collapse, Dialog, DialogTitle, DialogContentText, DialogActions, DialogContent, Link } from "@mui/material" import { useNavigate } from "react-router-dom" import { api, theme } from '../index' import axios from "axios" @@ -9,24 +9,56 @@ export const PageLogin = () => { const navigate = useNavigate() const usernameInput = useRef(null) const passwordInput = useRef(null) + const [disableBtn, setDisableBtn] = useState(false) + const [cors, setCors] = useState(false) const [illegal, setIllegal] = useState(false) + const [illegalMessgae, setIllegalMessgae] = useState("") const handleLogin = () => { - const username = usernameInput.current?.value - const password = passwordInput.current?.value - if(!username || !password) { - return setIllegal(true) - } + setDisableBtn(true); + (async () => { + const username = usernameInput.current?.value + const password = passwordInput.current?.value + if(!username || !password) { + setIllegalMessgae("请输入用户名或密码") + return setIllegal(true) + } + + try { + let response = await axios.post(api("/api/login"), { + username, + password, + }) + + if(response.data.err !== 1.048596) { + setIllegalMessgae(`登录失败! 错误代码 ${response.data.err} 原因: ${response.data.msg}`) + setIllegal(true) + } - axios.post(api("/api/login"), { - username, - password, - createToken: false - }).then((response) => { - window.sessionStorage.setItem('identifier', response.data.identifier) - window.sessionStorage.setItem('textures', response.data.texturs) - window.sessionStorage.setItem('username', response.data.username) - window.sessionStorage.setItem('uuid', response.data.uuid) + + if(response.data.err !== 1.048596) { + setIllegalMessgae(`登录失败! 错误代码 ${response.data.err} 原因: ${response.data.msg}`) + return setIllegal(true) + } + + console.log(response.data) + + window.sessionStorage.setItem('identifier', response.data.extra.identifier) + window.sessionStorage.setItem('textures', JSON.stringify(response.data.extra.textures)) + window.sessionStorage.setItem('username', response.data.extra.username) + window.sessionStorage.setItem('uuid', response.data.extra.uuid) + + navigate("/info") + } catch (err: any) { + if(err.code === "ERR_NETWORK") { + return setCors(true) + } + setIllegalMessgae(`登录失败! 错误代码 ${err.code} 原因: ${err.message}`) + setIllegal(true) + } + + })().finally(() => { + setDisableBtn(false); }) } @@ -34,6 +66,20 @@ export const PageLogin = () => { return + + + {"无法发送请求!"} + + + + 由于您的浏览器有 CORS 限制导致页面无法向 Mojang API/LSP-Yggdrasil API 发送请求。您可以选择 点我安装绕过CORS Chrome浏览器插件。或者添加 Chrome 启动参数: --disable-web-security 来解决。 + + + + + + +
@@ -49,7 +95,7 @@ export const PageLogin = () => { - 无效的用户名或密码 + {illegalMessgae} @@ -63,7 +109,7 @@ export const PageLogin = () => { - diff --git a/src/pages/register.tsx b/src/pages/register.tsx index e876896..124dd99 100644 --- a/src/pages/register.tsx +++ b/src/pages/register.tsx @@ -1,4 +1,4 @@ -import { Box, Button, CssBaseline, Grid, Paper, TextField, ThemeProvider, Typography, Alert, Collapse } from "@mui/material" +import { Box, Button, CssBaseline, Grid, Paper, TextField, Link, ThemeProvider, Typography, Alert, Collapse, Checkbox, FormGroup, FormControlLabel, Dialog, DialogTitle, DialogContentText, DialogActions, DialogContent } from "@mui/material" import { useNavigate } from "react-router-dom" import { api, theme } from '../index' import axios from "axios" @@ -7,15 +7,109 @@ import "./custom.css" export const PageRegister = () => { const navigate = useNavigate() - const [illegal1, setIllegal1] = useState(false) - const [illegal2, setIllegal2] = useState(false) - const [illegal3, setIllegal3] = useState(false) + const usernameInput = useRef(null) + const passwordInput = useRef(null) + const emailInput = useRef(null) + const invitationCodeInput = useRef(null) + const validationCodeInput = useRef(null) + const [useMojangSkin, setUseMojangSkin] = useState(false) + const [disableBtn, setDisableBtn] = useState(false) + const [cors, setCors] = useState(false) + const [illegal, setIllegal] = useState(false) + const [illegalMessgae, setIllegalMessgae] = useState("") + + + const handleRegister = () => { + setDisableBtn(true); + (async () => { + const username = usernameInput.current?.value + const password = passwordInput.current?.value + const email = emailInput.current?.value + const invitationCode = passwordInput.current?.value + const validationCode = invitationCodeInput.current?.value + if(!username || !password) { + setIllegalMessgae("请将以下内容全部输入") + setIllegal(true) + } + + let textureMigrations = undefined + + if(useMojangSkin) { + try { + const response = await axios.get("https://api.mojang.com/users/profiles/minecraft/" + username) + const profile = await axios.get("https://sessionserver.mojang.com/session/minecraft/profile/" + response.data.id) + profile.data.properties.forEach((prop: any) => { + if(prop.name === "textures") { + const texture = JSON.parse(atob(prop.value)).textures + + if(texture.SKIN || texture.CAPE) { + textureMigrations = { + skin: texture.SKIN?.url ?? undefined, + cape: texture.SKIN?.url ?? undefined, + } + } + } + }) + } catch(err: any) { + if(err.code === "ERR_NETWORK") { + setCors(true) + return + } + setIllegalMessgae(`无法同步正版皮肤,可能是用户不存在`) + setIllegal(true) + } + } + + console.log(textureMigrations) + + try { + const response = await axios.post(api("/api/register"), { + username, + password, + email, + invitationCode, + validationCode, + textureMigrations + }) + + if(response.data.err !== 1.048596) { + setIllegalMessgae(`注册失败! 错误代码 ${response.data.err} 原因: ${response.data.msg}`) + setIllegal(true) + } else { + navigate("/") + } + } catch (err: any) { + if(err.code === "ERR_NETWORK") { + setCors(true) + return + } + setIllegalMessgae(`注册失败! 错误代码 ${err.code} 原因: ${err.message}`) + setIllegal(true) + } + })().finally(() => { + setDisableBtn(false); + }) + } //TODO return + + + {"无法发送请求!"} + + + + 由于您的浏览器有 CORS 限制导致页面无法向 Mojang API/LSP-Yggdrasil API 发送请求。您可以选择 点我安装绕过CORS Chrome浏览器插件。或者添加 Chrome 启动参数: --disable-web-security 来解决。 + + + + + + +
@@ -28,48 +122,45 @@ export const PageRegister = () => { - - - - 无效的用户名、密码或邮箱 - - - - - - 无效的邀请码 - - - - - - 无效的邀请码 - - + + + + + {illegalMessgae} + + + + - setIllegal1(false)} /> + setIllegal(false)} /> - setIllegal1(false)} /> + setIllegal(false)} /> - setIllegal1(false)} /> + setIllegal(false)} /> + + + + setIllegal(false)} /> - setIllegal2(false)} /> + setIllegal(false)} /> - setIllegal3(false)} /> + + {setUseMojangSkin(!useMojangSkin)}} />}/> + -