Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
TOSTUMI
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Maple
TOSTUMI
Commits
c0ed6d98
Commit
c0ed6d98
authored
Nov 17, 2020
by
Sixiang_Zzb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
首次登陆验证 以及修改密码
parent
2e104c6c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
152 additions
and
42 deletions
+152
-42
BasicLayout.tsx
src/layouts/BasicLayout.tsx
+34
-14
SecurityLayout.tsx
src/layouts/SecurityLayout.tsx
+10
-10
login.ts
src/models/login.ts
+54
-6
index.tsx
src/pages/user/login/index.tsx
+8
-5
login2.tsx
src/pages/user/login/login2.tsx
+37
-7
login.ts
src/services/login.ts
+9
-0
No files found.
src/layouts/BasicLayout.tsx
View file @
c0ed6d98
...
@@ -100,18 +100,18 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
...
@@ -100,18 +100,18 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
* constructor
* constructor
*/
*/
useEffect
(()
=>
{
//
useEffect(() => {
if
(
dispatch
)
{
//
if (dispatch) {
console
.
log
(
"Maple"
)
//
console.log("Maple")
dispatch
({
//
dispatch({
type
:
'user/fetchCurrent'
,
//
type: 'user/fetchCurrent',
playload
:
{
//
playload: {
userName
:
"admin"
,
//
userName: "admin",
password
:
"admin"
,
//
password: "admin",
}
//
}
});
//
});
}
//
}
},
[]);
//
}, []);
/**
/**
* init variables
* init variables
*/
*/
...
@@ -135,8 +135,28 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
...
@@ -135,8 +135,28 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
logo=
{
logo
}
logo=
{
logo
}
formatMessage=
{
formatMessage
}
formatMessage=
{
formatMessage
}
menuHeaderRender=
{
(
logoDom
,
titleDom
)
=>
(
menuHeaderRender=
{
(
logoDom
,
titleDom
)
=>
(
<
div
style=
{
{
marginLeft
:
-
25
,
width
:
260
,
height
:
64
,
backgroundColor
:
"#ffffff"
,
paddingLeft
:
16
,
paddingTop
:
10
}
}
>
<
div
<
img
src=
{
tsIcon
}
style=
{
{
width
:
50
,
height
:
50
}
}
/><
span
style=
{
{
fontSize
:
18
,
fontFamily
:
"Source Han Sans CN"
,
fontWeight
:
"bold"
,
color
:
"rgba(51,51,51,1)"
}
}
>
TOS Management
</
span
>
style=
{
{
marginLeft
:
-
25
,
width
:
260
,
height
:
64
,
backgroundColor
:
'#ffffff'
,
paddingLeft
:
16
,
paddingTop
:
10
,
}
}
>
<
img
src=
{
tsIcon
}
style=
{
{
width
:
50
,
height
:
50
}
}
/>
<
span
style=
{
{
fontSize
:
18
,
fontFamily
:
'Source Han Sans CN'
,
fontWeight
:
'bold'
,
color
:
'rgba(51,51,51,1)'
,
}
}
>
{
' '
}
TOS Management
</
span
>
</
div
>
</
div
>
// <Link to="/">
// <Link to="/">
//
{
/* {logoDom} */
}
//
{
/* {logoDom} */
}
...
...
src/layouts/SecurityLayout.tsx
View file @
c0ed6d98
...
@@ -29,16 +29,16 @@ class SecurityLayout extends React.Component<SecurityLayoutProps, SecurityLayout
...
@@ -29,16 +29,16 @@ class SecurityLayout extends React.Component<SecurityLayoutProps, SecurityLayout
isReady
:
true
,
isReady
:
true
,
});
});
const
{
dispatch
,
login
}
=
this
.
props
;
const
{
dispatch
,
login
}
=
this
.
props
;
// console.log("安全登录中")
console
.
log
(
'安全登录中'
);
// console.log(login)
console
.
log
(
login
);
if
(
dispatch
)
{
if
(
dispatch
&&
!!
login
?.
userName
&&
!!
login
?.
password
)
{
//
dispatch({
dispatch
({
//
type: 'user/fetchCurrent',
type
:
'user/fetchCurrent'
,
//
playload: {
playload
:
{
//
userName: login.userName,
userName
:
login
.
userName
,
// password: login.password
password
:
login
.
password
,
// }
},
//
});
});
}
}
}
}
...
...
src/models/login.ts
View file @
c0ed6d98
import
{
stringify
}
from
'querystring'
;
import
{
stringify
}
from
'querystring'
;
import
{
history
,
Reducer
,
Effect
}
from
'umi'
;
import
{
history
,
Reducer
,
Effect
}
from
'umi'
;
import
{
AccountLogin
,
AccountCheckLogin
,
AccountOut
}
from
'@/services/login'
;
import
{
AccountLogin
,
AccountCheckLogin
,
resetPassword
}
from
'@/services/login'
;
import
{
setAuthority
}
from
'@/utils/authority'
;
import
{
setAuthority
}
from
'@/utils/authority'
;
import
{
getPageQuery
}
from
'@/utils/utils'
;
import
{
getPageQuery
}
from
'@/utils/utils'
;
...
@@ -14,6 +14,7 @@ export interface StateType {
...
@@ -14,6 +14,7 @@ export interface StateType {
token
?:
string
;
token
?:
string
;
userName
?:
string
;
userName
?:
string
;
password
?:
string
;
password
?:
string
;
result
?:
boolean
;
}
}
export
interface
LoginModelType
{
export
interface
LoginModelType
{
...
@@ -22,9 +23,13 @@ export interface LoginModelType {
...
@@ -22,9 +23,13 @@ export interface LoginModelType {
effects
:
{
effects
:
{
login
:
Effect
;
login
:
Effect
;
logout
:
Effect
;
logout
:
Effect
;
reset
:
Effect
;
goResetPwd
:
Effect
;
};
};
reducers
:
{
reducers
:
{
changeLoginStatus
:
Reducer
<
StateType
>
;
changeLoginStatus
:
Reducer
<
StateType
>
;
saveToken
:
Reducer
<
StateType
>
;
resetPwd
:
Reducer
<
StateType
>
;
};
};
}
}
...
@@ -36,6 +41,7 @@ const Model: LoginModelType = {
...
@@ -36,6 +41,7 @@ const Model: LoginModelType = {
token
:
''
,
token
:
''
,
userName
:
''
,
userName
:
''
,
password
:
''
,
password
:
''
,
result
:
false
,
},
},
reducers
:
{
reducers
:
{
...
@@ -47,18 +53,30 @@ const Model: LoginModelType = {
...
@@ -47,18 +53,30 @@ const Model: LoginModelType = {
type
:
payload
.
type
,
type
:
payload
.
type
,
};
};
},
},
saveToken
(
state
,
{
token
,
userName
,
password
})
{
return
{
...
state
,
token
,
userName
,
password
};
saveToken
(
state
,
{
token
,
userName
,
password
,
result
})
{
return
{
...
state
,
token
,
userName
,
password
,
result
};
},
resetPwd
(
state
,
{
result
,
userName
})
{
console
.
log
(
result
,
userName
);
return
{
...
state
,
result
,
userName
};
},
},
},
},
effects
:
{
effects
:
{
*
login
({
payload
},
{
call
,
put
})
{
*
login
({
payload
},
{
call
,
put
})
{
const
response
=
yield
call
(
AccountLogin
,
payload
);
const
response
=
yield
call
(
AccountLogin
,
payload
);
console
.
log
(
response
);
if
(
response
.
status
===
'resetPwd'
)
{
if
(
response
.
status
===
'resetPwd'
)
{
// if () {
console
.
log
(
'跳转到修改密码页面'
);
// }
yield
put
({
type
:
'resetPwd'
,
result
:
true
,
userName
:
response
.
userName
,
});
message
.
success
(
'Reset your password for your first login!'
,
3
);
history
.
push
(
'/user/login2'
);
}
else
if
(
response
.
status
===
'ok'
&&
response
.
token
!=
null
)
{
}
else
if
(
response
.
status
===
'ok'
&&
response
.
token
!=
null
)
{
yield
put
({
yield
put
({
type
:
'changeLoginStatus'
,
type
:
'changeLoginStatus'
,
...
@@ -67,6 +85,7 @@ const Model: LoginModelType = {
...
@@ -67,6 +85,7 @@ const Model: LoginModelType = {
// Login successfully response.status === 'ok'
// Login successfully response.status === 'ok'
console
.
log
(
'用户名密码登录成功'
);
console
.
log
(
'用户名密码登录成功'
);
console
.
log
(
response
);
console
.
log
(
response
);
message
.
success
(
'Login Successfully!'
,
3
);
const
userMessage
=
yield
call
(
AccountCheckLogin
,
payload
);
//请求时间网络
const
userMessage
=
yield
call
(
AccountCheckLogin
,
payload
);
//请求时间网络
console
.
log
(
userMessage
);
console
.
log
(
userMessage
);
console
.
log
(
userMessage
.
token
);
console
.
log
(
userMessage
.
token
);
...
@@ -81,6 +100,7 @@ const Model: LoginModelType = {
...
@@ -81,6 +100,7 @@ const Model: LoginModelType = {
token
:
userMessage
.
token
,
token
:
userMessage
.
token
,
userName
:
payload
.
userName
,
userName
:
payload
.
userName
,
password
:
payload
.
password
,
password
:
payload
.
password
,
result
:
false
,
});
});
const
urlParams
=
new
URL
(
window
.
location
.
href
);
const
urlParams
=
new
URL
(
window
.
location
.
href
);
const
params
=
getPageQuery
();
const
params
=
getPageQuery
();
...
@@ -108,6 +128,12 @@ const Model: LoginModelType = {
...
@@ -108,6 +128,12 @@ const Model: LoginModelType = {
// Note: There may be security issues, please note
// Note: There may be security issues, please note
// const response = yield call(AccountOut, payload);
// const response = yield call(AccountOut, payload);
if
(
window
.
location
.
pathname
!==
'/user/login'
&&
!
redirect
)
{
if
(
window
.
location
.
pathname
!==
'/user/login'
&&
!
redirect
)
{
// 清楚用户信息
localStorage
.
removeItem
(
'permission'
);
setCookie
(
'token'
,
''
);
setCookie
(
'id'
,
''
);
setCookie
(
'name'
,
''
);
setCookie
(
'phone'
,
''
);
history
.
replace
({
history
.
replace
({
pathname
:
'/user/login'
,
pathname
:
'/user/login'
,
search
:
stringify
({
search
:
stringify
({
...
@@ -116,6 +142,28 @@ const Model: LoginModelType = {
...
@@ -116,6 +142,28 @@ const Model: LoginModelType = {
});
});
}
}
},
},
*
reset
({
payload
},
{
call
,
put
})
{
const
res
=
yield
call
(
resetPassword
,
payload
);
console
.
log
(
res
);
if
(
res
.
error_code
===
'0000'
)
{
message
.
success
(
'Modified successfully, please log in again!'
,
3
);
history
.
push
(
'/'
);
}
else
{
message
.
error
(
'Change password failed,Please try again!'
);
}
},
*
goResetPwd
({
payload
},
{
call
,
put
})
{
console
.
log
(
'跳转到修改密码页面'
);
console
.
log
(
payload
);
yield
put
({
type
:
'resetPwd'
,
result
:
false
,
userName
:
payload
,
});
history
.
push
(
'login2'
);
},
},
},
};
};
...
...
src/pages/user/login/index.tsx
View file @
c0ed6d98
import
{
ArrowLeftOutlined
}
from
'@ant-design/icons'
;
import
{
ArrowLeftOutlined
}
from
'@ant-design/icons'
;
import
{
Alert
,
Checkbox
,
Input
,
message
,
Form
,
Button
}
from
'antd'
;
import
{
message
,
Form
,
Button
}
from
'antd'
;
import
React
,
{
useState
,
useEffect
,
useCallback
}
from
'react'
;
import
React
,
{
useState
,
useEffect
,
useCallback
}
from
'react'
;
import
{
Link
,
connect
,
Dispatch
,
history
,
Redirect
}
from
'umi'
;
import
{
connect
,
Dispatch
,
history
}
from
'umi'
;
import
{
StateType
}
from
'@/models/login'
;
import
{
StateType
}
from
'@/models/login'
;
import
{
LoginParamsType
,
get
FakeCaptcha
,
get
Captcha
,
ValidateCaptcha
}
from
'@/services/login'
;
import
{
LoginParamsType
,
getCaptcha
,
ValidateCaptcha
}
from
'@/services/login'
;
import
{
ConnectState
}
from
'@/models/connect'
;
import
{
ConnectState
}
from
'@/models/connect'
;
import
styles
from
'./style.less'
;
import
styles
from
'./style.less'
;
...
@@ -35,9 +35,12 @@ const Login: React.FC<LoginProps> = (props) => {
...
@@ -35,9 +35,12 @@ const Login: React.FC<LoginProps> = (props) => {
if
(
res
.
error_code
===
'0000'
)
{
if
(
res
.
error_code
===
'0000'
)
{
console
.
log
(
'通过跳转到修改密码页面'
);
console
.
log
(
'通过跳转到修改密码页面'
);
history
.
push
(
'login2'
);
dispatch
({
type
:
'login/goResetPwd'
,
payload
:
userName
,
});
}
else
{
}
else
{
message
.
error
(
'
memberc
ode!'
);
message
.
error
(
'
MemberC
ode!'
);
}
}
}
else
{
}
else
{
if
(
values
.
userName
&&
values
.
password
)
{
if
(
values
.
userName
&&
values
.
password
)
{
...
...
src/pages/user/login/login2.tsx
View file @
c0ed6d98
import
React
from
'react'
;
import
React
,
{
useState
,
useEffect
}
from
'react'
;
import
{
message
,
Form
,
Input
,
Button
}
from
'antd'
;
import
{
message
,
Form
,
Input
,
Button
}
from
'antd'
;
import
styles
from
'./style.less'
;
import
styles
from
'./style.less'
;
import
{
connect
}
from
'umi'
;
interface
Password
{
interface
Password
{
password
:
string
;
password
:
string
;
}
}
const
Login2
=
(
props
:
{
history
:
{
push
:
(
location
:
string
)
=>
void
}
})
=>
{
const
Login2
=
(
props
:
{
const
{
history
}
=
props
;
history
:
{
push
:
(
location
:
string
)
=>
void
};
result
:
React
.
SetStateAction
<
boolean
>
;
dispatch
:
any
;
userName
:
string
;
})
=>
{
const
{
history
,
result
,
dispatch
,
userName
}
=
props
;
console
.
log
(
userName
);
const
[
resetPwd
,
setResetPwd
]
=
useState
(
false
);
useEffect
(()
=>
{
setResetPwd
(
result
);
},
[
result
]);
useEffect
(()
=>
{
if
(
!
userName
)
{
history
.
push
(
'/user/login'
);
}
},
[]);
// 修改密码
// 修改密码
const
onFinish
=
(
values
:
Password
)
=>
{
const
onFinish
=
(
values
:
Password
)
=>
{
console
.
log
(
'修改密码'
);
console
.
log
(
'修改密码'
);
message
.
success
(
'modify successfully!'
,
3
);
dispatch
({
history
.
push
(
'/user/login'
);
type
:
'login/reset'
,
payload
:
{
tosUserName
:
userName
,
tosUserPwd
:
values
.
password
,
},
});
};
};
return
(
return
(
...
@@ -58,7 +83,7 @@ const Login2 = (props: { history: { push: (location: string) => void } }) => {
...
@@ -58,7 +83,7 @@ const Login2 = (props: { history: { push: (location: string) => void } }) => {
</
Form
.
Item
>
</
Form
.
Item
>
<
Form
.
Item
className=
{
styles
.
passBtn
}
>
<
Form
.
Item
className=
{
styles
.
passBtn
}
>
<
Button
size=
"large"
type=
"primary"
shape=
"round"
htmlType=
{
'submit'
}
>
<
Button
size=
"large"
type=
"primary"
shape=
"round"
htmlType=
{
'submit'
}
>
Accomplish
{
resetPwd
?
'Submit'
:
'Accomplish'
}
</
Button
>
</
Button
>
</
Form
.
Item
>
</
Form
.
Item
>
</
Form
>
</
Form
>
...
@@ -66,4 +91,9 @@ const Login2 = (props: { history: { push: (location: string) => void } }) => {
...
@@ -66,4 +91,9 @@ const Login2 = (props: { history: { push: (location: string) => void } }) => {
);
);
};
};
export
default
Login2
;
function
map
(
state
:
{
login
:
{
result
:
boolean
;
userName
:
string
}
})
{
const
{
result
,
userName
}
=
state
.
login
;
return
{
result
,
userName
};
}
export
default
connect
(
map
)(
Login2
);
src/services/login.ts
View file @
c0ed6d98
...
@@ -16,6 +16,10 @@ export interface CodeType {
...
@@ -16,6 +16,10 @@ export interface CodeType {
// });
// });
// }
// }
export
interface
PwdType
{
password
:
string
;
}
export
async
function
AccountLogin
(
params
:
LoginParamsType
)
{
export
async
function
AccountLogin
(
params
:
LoginParamsType
)
{
console
.
log
(
'登录请求'
);
console
.
log
(
'登录请求'
);
console
.
log
(
params
);
console
.
log
(
params
);
...
@@ -51,3 +55,8 @@ export async function ValidateCaptcha(params: CodeType) {
...
@@ -51,3 +55,8 @@ export async function ValidateCaptcha(params: CodeType) {
console
.
log
(
params
);
console
.
log
(
params
);
return
request
(
'/tos/validate/code'
,
{
method
:
'POST'
,
data
:
params
});
return
request
(
'/tos/validate/code'
,
{
method
:
'POST'
,
data
:
params
});
}
}
export
async
function
resetPassword
(
params
:
PwdType
)
{
console
.
log
(
'重置密码'
);
return
request
(
'/tos/user/resetPwd'
,
{
method
:
'POST'
,
data
:
params
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment