This commit is contained in:
caishi 2022-05-24 18:14:38 +08:00
parent 8c6ba5f050
commit 3ecfec141c
6 changed files with 190 additions and 46 deletions

View File

@ -26,6 +26,7 @@ const SimpleLayouts: FC<PageProps> = ({ loading, globalSetting, children, user,
const getData = async () => {
let res;
if (location?.search) {
let subject_id;
const path = location.pathname.split("/");
@ -49,7 +50,9 @@ const SimpleLayouts: FC<PageProps> = ({ loading, globalSetting, children, user,
},
})
}
if(res){
InitSetting();
}
if (res?.username && loca.pathname === '/login') {
location.href = "/"
}
@ -89,9 +92,9 @@ const SimpleLayouts: FC<PageProps> = ({ loading, globalSetting, children, user,
delCookie("logintrustie");
getData();
}, [location.pathname])
useEffect(() => {
const InitSetting= async () =>{
if (location.pathname.indexOf("classrooms") > -1 && location.pathname.indexOf("detail") === -1) {
} else {
document.body.scrollIntoView()
}
@ -100,16 +103,13 @@ const SimpleLayouts: FC<PageProps> = ({ loading, globalSetting, children, user,
window.location.href = "https://kepukehuan.educoder.net/classrooms/4RW9CYHY/exercise"
return;
}
dispatch({
type: 'globalSetting/query',
payload: {},
})
dispatch({ type: "globalSetting/setGlobalLoading", payload: { show: false, text: "" } })
// dispatch({ type: "globalSetting/getSystemUpdate", payload: { show: false, text: "" } })
console.log(location, ":location")
// http://localhost:8000
// https://jetcoder.educoder.net
if (window.location.href === 'https://jetcoder.educoder.net' || window.location.href === 'https://jetcoder.educoder.net/') {
window.location.href = 'https://www.educoder.net/problems'
return
@ -132,7 +132,7 @@ const SimpleLayouts: FC<PageProps> = ({ loading, globalSetting, children, user,
}
Modal.destroyAll();
setLocale('zh-CN', false);
}, [location.pathname])
}
useEffect(() => {
if (globalSetting.updateData.system_update) {

View File

@ -1,6 +1,6 @@
import { Effect, Reducer, Subscription, history } from 'umi'
import { Action } from '@@/plugin-dva/connect'
import { LoginIn, getUserInfo, getNavigationInfo , ForgeLogin , getEducoderUserInfo } from '@/service/user'
import { LoginIn, getUserInfo, getNavigationInfo , ForgeLogin , getEducoderUserInfo , ForgeCheckName , ForgeSaveUserInfo , ForgeCheckEmail } from '@/service/user'
export interface UserModelState {
name: string
@ -22,7 +22,10 @@ export interface UserModelType {
getNavigationInfo: Effect
setActionTabs: Effect;
ForgeLogin:Effect;
getEducoderUserInfo:Effect
getEducoderUserInfo:Effect,
ForgeCheckName:Effect,
ForgeCheckEmail:Effect,
ForgeSaveUserInfo:Effect
}
reducers: {
save: Reducer<UserModelState>
@ -72,7 +75,17 @@ const UserModel: UserModelType = {
})
},
*ForgeLogin({ payload }, { call, put }) {
const { to } = payload
const response = yield call(ForgeLogin, { ...payload })
if (!response.status) {
try {
if (to) {
history.replace(to)
} else {
location.reload()
}
} catch (e) { }
}
return response;
},
*getUserInfo({ payload }, { call, put }) {
@ -84,6 +97,7 @@ const UserModel: UserModelType = {
type: 'save',
payload: { userInfo: { ...response } },
})
return response;
},
*getEducoderUserInfo({ payload }, { call, put }) {
const response = yield call(getEducoderUserInfo, { ...payload})
@ -102,6 +116,18 @@ const UserModel: UserModelType = {
payload: { actionTabs: { ...payload } },
});
},
*ForgeCheckName({ payload }, { call, put }) {
const response = yield call(ForgeCheckName, { ...payload,debug:"admin" });
return response;
},
*ForgeCheckEmail({ payload }, { call, put }) {
const response = yield call(ForgeCheckEmail, { ...payload,debug:"admin" });
return response;
},
*ForgeSaveUserInfo({ payload }, { call, put }) {
const response = yield call(ForgeSaveUserInfo, { ...payload });
return response;
}
},
reducers: {
save(state, action) {

View File

@ -9,4 +9,7 @@
div[class~='ant-form-item-control-input-content'] {
text-align: left;
}
div[class~='ant-form-item-explain'] {
text-align: left;
}
}

View File

@ -7,8 +7,9 @@ import {
connect,
Dispatch,
} from 'umi';
import { Modal, Button , Form , Input, Checkbox } from 'antd';
import { Modal, Button , Form , Input, Spin } from 'antd';
import styles from './index.less';
import { getCourseParam } from '@/components/Header';
interface PageProps extends Partial<ConnectProps> {
@ -22,23 +23,96 @@ const InitGitlink:FC<PageProps>=({
visible,
user,
onClose = () => { },
dispatch
})=>{
const [form] = Form.useForm();
const [ updateEmail , setUpdateEmail ] = useState(false);
const [ emailforName , setEmailforName ] = useState(false);
const [ loading , setLoading ] = useState(false);
useEffect(()=>{
if(user?.userInfo?.email){
setUpdateEmail(true);
form.setFieldsValue({ email: user?.userInfo?.email });
if(!user?.userInfo?.email || (user?.userInfo?.email && user?.userInfo?.email.indexOf("gitlink.org.cn")>-1)){
form.setFieldsValue({email:""})
}else{
setUpdateEmail(false);
form.setFieldsValue({
email:user?.userInfo?.email,
username:user?.userInfo?.login
})
setEmailforName(true)
}
},[user?.userInfo])
function handleFinish(values:any){
const handleFinish=async (values:any)=>{
setLoading(true);
if(emailforName){
// 如果输入的邮箱已存在用户就走登录流程
dispatch({
type:"user/ForgeLogin",
payload:{
login:values?.email || user?.userInfo?.email,
password:values?.password
}
})
}else{
let res = await dispatch({
type:"user/ForgeSaveUserInfo",
payload:{
...values,
email:values?.email || user?.userInfo?.email
}
})
if(res){
setLoading(false);
onClose();
const payload = getCourseParam();
let res = dispatch({
type: 'user/getUserInfo',
payload: {
...payload,
},
})
if(res){
dispatch({
type: 'globalSetting/query',
payload: {},
})
}
}
}
}
//判断用户名username是否注册
async function usernameConfirm(rule:any, value:string, callback:any,type:any){
if(value){
var result = await dispatch({
type:"user/ForgeCheckName",
payload:{
value,type
}
})
}
callback();
}
//判断邮箱email是否注册
async function useremailConfirm(rule:any, value:string, callback:any,type:any){
if(value){
var result = await dispatch({
type:"user/ForgeCheckEmail",
payload:{
email:value
}
})
if(result?.login){
setEmailforName(true);
form.setFieldsValue({username:result?.login})
}else{
setEmailforName(false);
form.setFieldsValue({username:""})
}
}
callback();
}
return(
<Modal
centered
@ -51,6 +125,7 @@ const InitGitlink:FC<PageProps>=({
onCancel={onClose}
footer={null}
>
<Spin spinning={loading}>
<Form
className={styles.formWrap}
form={form}
@ -63,30 +138,50 @@ const InitGitlink:FC<PageProps>=({
<span style={{fontSize:"16px"}}>{user?.userInfo?.real_name}</span>
</Form.Item>
<Form.Item
label="用户名"
name="username"
label="邮箱"
name="email"
rules={[{
required: true,
message: '请输入用户名',
},{
message: '请输入邮箱',
},
{
validator: (rule:any, value:any, callback:any) => { useremailConfirm(rule, value, callback,2) }
}]}
validateTrigger={"onBlur"}
validateFirst={true}
>
<Input placeholder="请输入4-15位用户名以字母开头只能使用字母和数字" size={"large"}/>
<Input placeholder="请输入邮箱" size={"large"} />
</Form.Item>
<Form.Item
label="用户名"
name="username"
rules={[
{
required:true,
message:"请输入用户名"
},
{
pattern: /^[a-zA-Z]/,
message: "用户名必须以字母开头"
},
{
pattern: /[a-zA-Z0-9]$/,
message: "用户名只能使用英文字母和数字"
},
{
min: 4,
max: 15,
message: "用户名长度为4到15个字符"
},
{
validator: (rule:any, value:any, callback:any,type:any) => { usernameConfirm(rule, value, callback,1) }
}
]}
validateTrigger={"onBlur"}
validateFirst={true}
>
<Input placeholder="请输入4-15位用户名以字母开头只能使用字母和数字" disabled={emailforName} size={"large"}/>
</Form.Item>
{
!updateEmail &&
<Form.Item
label="邮箱"
name="email"
rules={[{
required: true,
message: '请输入邮箱',
}]}
>
<Input placeholder="请输入邮箱" size={"large"}/>
</Form.Item>
}
<Form.Item
label="密码"
name="password"
@ -119,6 +214,7 @@ const InitGitlink:FC<PageProps>=({
</Button>
</Form.Item>
</Form>
</Spin>
</Modal>
)
}

View File

@ -87,12 +87,6 @@ const competitionDetails: FC<PageProps> = ({
useEffect(() => {
async function init() {
setStaffDetail(await dispatch({
type: 'competitions/getStaff',
payload: {
identifier: identifier
}
}))
const res = await dispatch({
type: 'competitions/getHeader',
payload: {
@ -100,7 +94,14 @@ const competitionDetails: FC<PageProps> = ({
}
})
setHeaderDetail(res)
setDocumentTitle(res?.name || '竞赛')
setDocumentTitle(res?.name || '竞赛');
setStaffDetail(await dispatch({
type: 'competitions/getStaff',
payload: {
identifier: identifier
}
}))
}
if (identifier) {
init();
@ -322,7 +323,7 @@ const competitionDetails: FC<PageProps> = ({
return (
<div className={"edu-container minH500"}>
<SubCompetition visible={subComShow} onClose={()=>setSubComShow(false)} filterlist={subComList}/>
<InitGitLink visible={subGitlinkShow} onClose={()=>setSubGitlinkShow(false)}/>
<InitGitLink visible={subGitlinkShow && !user?.userInfo?.is_new} onClose={()=>setSubGitlinkShow(false)}/>
<Breadcrumb className="mt10" separator=">">
<Breadcrumb.Item><Link to={"/competitions/index"}>线</Link></Breadcrumb.Item>
<Breadcrumb.Item>{HeaderDetail.name}{HeaderDetail.sub_title ? '-' + HeaderDetail.sub_title : null}</Breadcrumb.Item>

View File

@ -13,6 +13,24 @@ export async function ForgeLoginOut(params: any) {
// body: { ...params },
});
}
export async function ForgeCheckName(params: any) {
return Fetch(`${ENV.FORGE_SERVER}/api/accounts/check.json`, {
method: 'post',
body: { ...params },
});
}
export async function ForgeCheckEmail(params: any) {
return Fetch(`${ENV.FORGE_SERVER}/api/users/email_search.json`, {
method: 'get',
params: {...params}
});
}
export async function ForgeSaveUserInfo(params: any) {
return Fetch(`${ENV.FORGE_SERVER}/api/accounts/simple_update.json`, {
method: 'post',
body: { ...params },
});
}
export async function LoginIn(params: any) {
return Fetch('/api/accounts/login.json', {
method: 'post',