-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
234 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import React, { Component } from 'react' | ||
import { PropTypes, connect } from '../../family' | ||
import { reset } from '../../actions/account' | ||
import { Link } from 'react-router-dom' | ||
import './ResetForm.css' | ||
|
||
// 展示组件 | ||
class LoginForm extends Component { | ||
static contextTypes = { | ||
store: PropTypes.object.isRequired | ||
} | ||
static propTypes = { | ||
auth: PropTypes.object.isRequired | ||
} | ||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
email: '', | ||
password: '', | ||
showPassword: false, | ||
newPassword: '', | ||
} | ||
} | ||
render() { | ||
const { showPassword, email, password, newPassword } = this.state | ||
if (newPassword) { | ||
return ( | ||
<section className='ResetForm'> | ||
<div className='header'> | ||
<span className='title'>找回密码</span> | ||
</div> | ||
<div className='body'> | ||
<div className='form-group'> | ||
您的密码已重设为: {newPassword}, 请重新登陆。 | ||
</div> | ||
</div> | ||
</section> | ||
) | ||
} | ||
return ( | ||
<section className='ResetForm'> | ||
<div className='header'> | ||
<span className='title'>找回密码</span> | ||
</div> | ||
<form onSubmit={this.handleSubmit}> | ||
<div className='body'> | ||
<div className='form-group'> | ||
<label>邮箱:</label> | ||
<input value={email} onChange={e => this.setState({ email: e.target.value })} className='form-control' placeholder='Email' autoFocus='true' required disabled={showPassword} /> | ||
</div> | ||
{showPassword && <div> | ||
<div className='form-group'> | ||
<label>验证码:</label> | ||
<input value={password} onChange={e => this.setState({ password: e.target.value })} className='form-control' placeholder='验证码' /> | ||
</div> | ||
<div className='form-group'> | ||
已发送验证码至您输入的邮箱,请输入验证码以重置您的密码。 | ||
</div> | ||
</div>} | ||
</div> | ||
<div className='footer'> | ||
<button type='submit' className='btn btn-primary w80 mr10'>提交</button> | ||
<Link to='/account/login' className='mr10'>返回</Link> | ||
</div> | ||
{this.props.auth.message && | ||
<div className='alert alert-danger fade show' role='alert'> | ||
{this.props.auth.message} | ||
</div> | ||
} | ||
</form> | ||
</section> | ||
) | ||
} | ||
handleSubmit = (e) => { | ||
const { onReset } = this.props | ||
const { email, password } = this.state | ||
e.preventDefault() | ||
if (email) { | ||
this.setState({ | ||
showPassword: true, | ||
}) | ||
onReset(email, password, (result) => { | ||
if (!result.isOk) { | ||
alert(result.errMsg) | ||
return | ||
} | ||
if (result.data) { | ||
this.setState({ | ||
newPassword: result.data, | ||
}) | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
|
||
// 容器组件 | ||
const mapStateToProps = (state) => ({ | ||
auth: state.auth | ||
}) | ||
const mapDispatchToProps = ({ | ||
onReset: reset, | ||
}) | ||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(LoginForm) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@import "../../assets/variables.sass"; | ||
// 水平居中 + 垂直居中 | ||
.ResetForm | ||
position: fixed; | ||
left: 50%; | ||
top: 50%; | ||
width: 25rem; | ||
margin-left: -12.5rem; | ||
margin-top: -135px; | ||
border: 1px solid #E6E6E6; | ||
border-radius: .5rem; | ||
.header | ||
padding: 1.5rem 3rem; | ||
border-bottom: 1px solid $border; | ||
.title | ||
font-size: 2rem; | ||
.body | ||
padding: 1.5rem 3rem; | ||
.footer | ||
padding: 1.5rem 3rem; | ||
border-top: 1px solid $border; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,115 @@ | ||
import { CREDENTIALS, serve, HEADERS } from './constant' | ||
import { | ||
CREDENTIALS, | ||
serve, | ||
HEADERS | ||
} from './constant' | ||
|
||
export default { | ||
// 获取登陆信息 | ||
fetchLoginInfo () { | ||
return fetch(`${serve}/account/info`, { ...CREDENTIALS }) | ||
fetchLoginInfo() { | ||
return fetch(`${serve}/account/info`, { ...CREDENTIALS | ||
}) | ||
.then(res => res.json()) | ||
.then(json => json.data) | ||
}, | ||
|
||
// 注册用户 | ||
addUser (user) { | ||
addUser(user) { | ||
return fetch(`${serve}/account/register`, { | ||
...CREDENTIALS, | ||
method: 'POST', | ||
body: JSON.stringify(user), | ||
headers: { 'Content-Type': 'application/json' } | ||
}) | ||
...CREDENTIALS, | ||
method: 'POST', | ||
body: JSON.stringify(user), | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}) | ||
.then(res => res.json()) | ||
.then(json => json.data) | ||
}, | ||
// 重置用户 | ||
resetUser(email, password) { | ||
return fetch(`${serve}/account/reset`, { | ||
...CREDENTIALS, | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
email, password, | ||
}), | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}) | ||
.then(res => res.json()) | ||
.then(json => json.data) | ||
}, | ||
// 修改密码 | ||
updateUser (user) { | ||
updateUser(user) { | ||
return fetch(`${serve}/account/update`, { | ||
...CREDENTIALS, | ||
method: 'POST', | ||
body: JSON.stringify(user), | ||
headers: HEADERS.JSON | ||
}) | ||
...CREDENTIALS, | ||
method: 'POST', | ||
body: JSON.stringify(user), | ||
headers: HEADERS.JSON | ||
}) | ||
.then(res => res.json()) | ||
.then(json => json.data) | ||
}, | ||
// 用户登陆 | ||
login ({ email, password, captcha }) { | ||
login({ | ||
email, | ||
password, | ||
captcha | ||
}) { | ||
return fetch(`${serve}/account/login`, { | ||
...CREDENTIALS, | ||
method: 'POST', | ||
body: JSON.stringify({ email, password, captcha }), | ||
headers: { 'Content-Type': 'application/json' } | ||
}) | ||
...CREDENTIALS, | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
email, | ||
password, | ||
captcha | ||
}), | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}) | ||
.then(res => res.json()) | ||
.then(json => json.data) | ||
}, | ||
// 用户退出 | ||
logout () { | ||
return fetch(`${serve}/account/logout`, { ...CREDENTIALS }) | ||
logout() { | ||
return fetch(`${serve}/account/logout`, { ...CREDENTIALS | ||
}) | ||
.then(res => res.json()) | ||
.then(json => json.data) | ||
}, | ||
// 获取用户总数 | ||
fetchUserCount () { | ||
fetchUserCount() { | ||
return fetch(`${serve}/account/count`) | ||
.then(res => res.json()) | ||
.then(json => json.data) | ||
}, | ||
// 获取用户列表 | ||
fetchUserList ({ name = '', cursor = 1, limit = 100 } = {}) { | ||
fetchUserList({ | ||
name = '', | ||
cursor = 1, | ||
limit = 100 | ||
} = {}) { | ||
return fetch(`${serve}/account/list?name=${name}&cursor=${cursor}&limit=${limit}`) | ||
.then(res => res.json()) | ||
// .then(json => json.data) | ||
// .then(json => json.data) | ||
}, | ||
// 根据 id 删除指定用户 | ||
deleteUser (id) { | ||
deleteUser(id) { | ||
return fetch(`${serve}/account/remove?id=${id}`) | ||
.then(res => res.json()) | ||
.then(json => json.data) | ||
}, | ||
// 获取用户列表 | ||
fetchLogList ({ cursor = 1, limit = 100 } = {}) { | ||
return fetch(`${serve}/account/logger?cursor=${cursor}&limit=${limit}`, { ...CREDENTIALS }) | ||
fetchLogList({ | ||
cursor = 1, | ||
limit = 100 | ||
} = {}) { | ||
return fetch(`${serve}/account/logger?cursor=${cursor}&limit=${limit}`, { ...CREDENTIALS | ||
}) | ||
.then(res => res.json()) | ||
// .then(json => json.data) | ||
// .then(json => json.data) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters