前端登录失败增加提示信息

鉴权header使用auth标准
前端可显示版本号
This commit is contained in:
johlanse 2022-08-26 08:25:07 +08:00
parent ab0465a9a1
commit 7f846ef707
14 changed files with 75 additions and 25 deletions

View File

@ -240,7 +240,7 @@ func (c *Core) L(retryTimes int, pushID string) (*model.User, error) {
} }
// 等待几分钟后重新执行 // 等待几分钟后重新执行
time.Sleep(time.Duration(conf.GetConfig().Retry.Intervals) * time.Minute) time.Sleep(time.Duration(conf.GetConfig().Retry.Intervals) * time.Minute)
c.Push(pushID, "text", fmt.Sprintf("登录超时,将进行第%d重新次登录", retryTimes)) c.Push(pushID, "flush", fmt.Sprintf("登录超时,将进行第%d重新次登录", retryTimes))
return c.L(retryTimes-1, pushID) return c.L(retryTimes-1, pushID)
} }

21
main.go
View File

@ -195,10 +195,7 @@ func do(m string) {
getPush := push.GetPush(config) getPush := push.GetPush(config)
getPush("", "flush", "学习强国助手已上线") getPush("", "flush", "学习强国助手已上线")
failUser, _ := model.QueryFailUser()
for _, user := range failUser {
getPush(user.PushId, "flush", user.Nick+"的cookie已过期")
}
core := &lib.Core{ShowBrowser: config.ShowBrowser, Push: getPush} core := &lib.Core{ShowBrowser: config.ShowBrowser, Push: getPush}
defer core.Quit() defer core.Quit()
core.Init() core.Init()
@ -241,6 +238,22 @@ func do(m string) {
core2.Push(u.PushId, "flush", message) core2.Push(u.PushId, "flush", message)
} }
failUser, _ := model.QueryFailUser()
for _, user := range failUser {
go func(user2 *model.User) {
c := &lib.Core{Push: getPush, ShowBrowser: config.ShowBrowser}
getPush(user2.PushId, "flush", user2.Nick+"的cookie已过期")
newUser, err := c.L(config.Retry.Times, user2.PushId)
if err != nil {
c.Push(user2.PushId, "flush", "用户"+user2.Nick+"登录超时!")
return
}
c.Init()
defer c.Quit()
study(c, newUser)
}(user)
}
// 用户小于1时自动登录 // 用户小于1时自动登录
if len(users) < 1 { if len(users) < 1 {
log.Infoln("未检测到有效用户信息,将采用登录模式") log.Infoln("未检测到有效用户信息,将采用登录模式")

View File

@ -229,8 +229,7 @@ func study() gin.HandlerFunc {
user := model.Find(uid) user := model.Find(uid)
core := &lib.Core{ core := &lib.Core{
ShowBrowser: conf.GetConfig().ShowBrowser, ShowBrowser: conf.GetConfig().ShowBrowser,
Push: func(id string, kind, message string) { Push: push.GetPush(conf.GetConfig()),
},
} }
core.Init() core.Init()
state.Store(uid, core) state.Store(uid, core)

View File

@ -5,6 +5,7 @@ package web
import ( import (
"embed" "embed"
"net/http" "net/http"
"strings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -32,7 +33,13 @@ func RouterInit() *gin.Engine {
}) })
router.GET("/about", func(context *gin.Context) { router.GET("/about", func(context *gin.Context) {
context.JSON(200, utils.GetAbout()) context.JSON(200, Resp{
Code: 200,
Message: "",
Data: utils.GetAbout(),
Success: true,
Error: "",
})
}) })
if utils.FileIsExist("./config/flutter_xxqg/") { if utils.FileIsExist("./config/flutter_xxqg/") {
@ -78,10 +85,11 @@ func RouterInit() *gin.Engine {
func check() gin.HandlerFunc { func check() gin.HandlerFunc {
config := conf.GetConfig() config := conf.GetConfig()
return func(ctx *gin.Context) { return func(ctx *gin.Context) {
token := ctx.GetHeader("xxqg_token") token := ctx.GetHeader("Authorization")
token = strings.Split(token, " ")[1]
if token == "" || (utils.StrMd5(config.Web.Account+config.Web.Password) != token) { if token == "" || (utils.StrMd5(config.Web.Account+config.Web.Password) != token) {
ctx.JSON(403, Resp{ ctx.JSON(401, Resp{
Code: 403, Code: 401,
Message: "the auth fail", Message: "the auth fail",
Data: nil, Data: nil,
Success: false, Success: false,

View File

@ -1,15 +1,15 @@
{ {
"files": { "files": {
"main.css": "/static/xxqg/build/static/css/main.6f1e3389.css", "main.css": "/static/xxqg/build/static/css/main.6f1e3389.css",
"main.js": "/static/xxqg/build/static/js/main.34367272.js", "main.js": "/static/xxqg/build/static/js/main.8720e9a4.js",
"static/js/787.273d6ce9.chunk.js": "/static/xxqg/build/static/js/787.273d6ce9.chunk.js", "static/js/787.273d6ce9.chunk.js": "/static/xxqg/build/static/js/787.273d6ce9.chunk.js",
"index.html": "/static/xxqg/build/index.html", "index.html": "/static/xxqg/build/index.html",
"main.6f1e3389.css.map": "/static/xxqg/build/static/css/main.6f1e3389.css.map", "main.6f1e3389.css.map": "/static/xxqg/build/static/css/main.6f1e3389.css.map",
"main.34367272.js.map": "/static/xxqg/build/static/js/main.34367272.js.map", "main.8720e9a4.js.map": "/static/xxqg/build/static/js/main.8720e9a4.js.map",
"787.273d6ce9.chunk.js.map": "/static/xxqg/build/static/js/787.273d6ce9.chunk.js.map" "787.273d6ce9.chunk.js.map": "/static/xxqg/build/static/js/787.273d6ce9.chunk.js.map"
}, },
"entrypoints": [ "entrypoints": [
"static/css/main.6f1e3389.css", "static/css/main.6f1e3389.css",
"static/js/main.34367272.js" "static/js/main.8720e9a4.js"
] ]
} }

View File

@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/static/xxqg/build/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/static/xxqg/build/logo192.png"/><link rel="manifest" href="/static/xxqg/build/manifest.json"/><title>Study XXQG</title><script defer="defer" src="/static/xxqg/build/static/js/main.34367272.js"></script><link href="/static/xxqg/build/static/css/main.6f1e3389.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html> <!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/static/xxqg/build/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/static/xxqg/build/logo192.png"/><link rel="manifest" href="/static/xxqg/build/manifest.json"/><title>Study XXQG</title><script defer="defer" src="/static/xxqg/build/static/js/main.8720e9a4.js"></script><link href="/static/xxqg/build/static/css/main.6f1e3389.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -3,8 +3,9 @@ import './App.css';
import {Button, Dialog, Divider, Form, Input, List, Modal, NavBar, Popup, TextArea, Toast,} from "antd-mobile"; import {Button, Dialog, Divider, Form, Input, List, Modal, NavBar, Popup, TextArea, Toast,} from "antd-mobile";
import {UnorderedListOutline} from "antd-mobile-icons"; import {UnorderedListOutline} from "antd-mobile-icons";
import {ListItem} from "antd-mobile/es/components/list/list-item"; import {ListItem} from "antd-mobile/es/components/list/list-item";
import {checkQrCode, getLog, getScore, getToken, getUsers, getLink, stopStudy, study, login, checkToken} from "./utils/api"; import {checkQrCode, getLog, getScore, getToken, getUsers, getLink, stopStudy, study, login, checkToken,getAbout} from "./utils/api";
import QrCode from 'qrcode.react'; import QrCode from 'qrcode.react';
import * as util from "util";
class App extends React.Component<any, any> { class App extends React.Component<any, any> {
@ -95,12 +96,12 @@ class Login extends Component<any, any>{
onFinish = (value:string)=>{ onFinish = (value:string)=>{
login(JSON.stringify(value)).then(resp => { login(JSON.stringify(value)).then(resp => {
console.log(resp) console.log(resp.message)
if (resp.success){ if (resp.success){
window.localStorage.setItem("xxqg_token",resp.data) window.localStorage.setItem("xxqg_token",resp.data)
this.props.parent.set_login() this.props.parent.set_login()
}else { }else {
Dialog.show(resp.message) Dialog.alert({content: resp.message,closeOnMaskClick:false})
} }
}) })
@ -253,9 +254,26 @@ class Log extends Component<any, any>{
} }
class Help extends Component<any, any> { class Help extends Component<any, any> {
constructor(props: any) {
super(props);
this.state = {
about: ""
};
}
componentDidMount() {
getAbout().then((value)=>{
this.setState({
about:value.data
})
})
}
render() { render() {
return <> return <>
<h2 style={{margin:10}}><a href="https://github.com/johlanse/study_xxqg">https://github.com/johlanse/study_xxqg</a></h2> <h2 style={{margin:10}}><a href="https://github.com/johlanse/study_xxqg">https://github.com/johlanse/study_xxqg</a></h2>
<br/><h2 style={{margin:10}}>{this.state.about}</h2>
</> </>
} }
} }
@ -366,6 +384,11 @@ class Users extends Component<any, any>{
</> </>
) )
} }
if (this.state.users.length === 0){
elements.push(<>
<span style={{color:"red"}}></span>
</>)
}
return <List>{elements}</List>; return <List>{elements}</List>;
} }

View File

@ -1,7 +1,7 @@
const { createProxyMiddleware } = require('http-proxy-middleware'); const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) { module.exports = function(app) {
app.use("/api",createProxyMiddleware({ app.use("/api",createProxyMiddleware({
target: "http://127.0.0.1:8083", target: "http://127.0.0.1:8085",
changeOrigin: true, changeOrigin: true,
pathRewrite:{ pathRewrite:{
"/api":"/" "/api":"/"

View File

@ -28,6 +28,8 @@ export async function checkToken() {
} }
export async function login(data) { export async function login(data) {
let responseData = await http.post(base+"/auth/login",data); let responseData = await http.post(base+"/auth/login",data);
return responseData.data; return responseData.data;
@ -46,6 +48,11 @@ export async function checkQrCode(code) {
return resp.data return resp.data
} }
export async function getAbout(){
let resp = await http.get(base+"/about");
return resp.data;
}
export async function getToken(code,sign){ export async function getToken(code,sign){
let resp = await http.post(base+"/user/",{ let resp = await http.post(base+"/user/",{
"code":code, "code":code,
@ -55,7 +62,7 @@ export async function getToken(code,sign){
} }
export async function getUsers(){ export async function getUsers(){
let resp = await http.get(base+"/user/"); let resp = await http.get(base+"/user");
return resp.data return resp.data
} }

View File

@ -19,7 +19,7 @@ class Http {
(value)=>{ (value)=>{
if (value.headers !== null){ if (value.headers !== null){
// @ts-ignore // @ts-ignore
value.headers.xxqg_token = localStorage.getItem("xxqg_token") value.headers.Authorization = "Bearer "+localStorage.getItem("xxqg_token")
} }
return value return value
},()=>{ },()=>{