mirror of https://github.com/openspug/spug
F 前端 修复个人信息页一些问题
parent
e4638a3cc8
commit
9bbb371980
|
@ -79,25 +79,41 @@ def put(u_id):
|
||||||
return json_response(message=error)
|
return json_response(message=error)
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/modifypwd', methods=['POST'])
|
@blueprint.route('/setting/password', methods=['POST'])
|
||||||
def modify_pwd():
|
def setting_password():
|
||||||
form, error = JsonParser('password', 'newpassword').parse()
|
form, error = JsonParser(
|
||||||
|
Argument('password', help='请输入原密码'),
|
||||||
|
Argument('newpassword', help='请输入心密码')
|
||||||
|
).parse()
|
||||||
if error is None:
|
if error is None:
|
||||||
if g.user.verify_password(form.password):
|
if g.user.verify_password(form.password):
|
||||||
g.user.password = form.newpassword
|
g.user.password = form.newpassword
|
||||||
g.user.save()
|
g.user.save()
|
||||||
return json_response()
|
|
||||||
else:
|
else:
|
||||||
return json_response(message='原密码错误')
|
return json_response(message='原密码错误')
|
||||||
return json_response(message=error)
|
return json_response(message=error)
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/<int:u_id>', methods=['GET'])
|
@blueprint.route('/setting/info', methods=['POST'])
|
||||||
def get_person(u_id):
|
def setting_info():
|
||||||
if u_id:
|
form, error = JsonParser(
|
||||||
u_info = User.query.get_or_404(u_id)
|
Argument('nickname', help='请输入昵称'),
|
||||||
return json_response(u_info)
|
Argument('mobile', help='请输入手机号码'),
|
||||||
return json_response(message='user_id不能为空')
|
Argument('email', help='请输入电子邮件地址'),
|
||||||
|
).parse()
|
||||||
|
if error is None:
|
||||||
|
g.user.update(**form)
|
||||||
|
return json_response(message=error)
|
||||||
|
|
||||||
|
|
||||||
|
@blueprint.route('/self', methods=['GET'])
|
||||||
|
def get_self():
|
||||||
|
return json_response({
|
||||||
|
'username': g.user.username,
|
||||||
|
'nickname': g.user.nickname,
|
||||||
|
'mobile': g.user.mobile,
|
||||||
|
'email': g.user.email,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/login/', methods=['POST'])
|
@blueprint.route('/login/', methods=['POST'])
|
||||||
|
@ -112,9 +128,12 @@ def login():
|
||||||
user.access_token = token
|
user.access_token = token
|
||||||
user.token_expired = time.time() + 8 * 60 * 60
|
user.token_expired = time.time() + 8 * 60 * 60
|
||||||
user.save()
|
user.save()
|
||||||
user_data = user.to_json()
|
return json_response({
|
||||||
user_data.update({'token': token, 'permissions': list(user.permissions)})
|
'token': token,
|
||||||
return json_response(user_data)
|
'is_supper': user.is_supper,
|
||||||
|
'nickname': user.nickname,
|
||||||
|
'permissions': list(user.permissions)
|
||||||
|
})
|
||||||
else:
|
else:
|
||||||
login_limit[form.username] += 1
|
login_limit[form.username] += 1
|
||||||
if login_limit[form.username] >= 3:
|
if login_limit[form.username] >= 3:
|
||||||
|
|
|
@ -87,7 +87,6 @@
|
||||||
localStorage.setItem('token', res.result['token']);
|
localStorage.setItem('token', res.result['token']);
|
||||||
localStorage.setItem('is_supper', res.result['is_supper']);
|
localStorage.setItem('is_supper', res.result['is_supper']);
|
||||||
localStorage.setItem('permissions', res.result['permissions']);
|
localStorage.setItem('permissions', res.result['permissions']);
|
||||||
localStorage.setItem('user_id', res.result['id']);
|
|
||||||
localStorage.setItem('nickname', res.result['nickname']);
|
localStorage.setItem('nickname', res.result['nickname']);
|
||||||
this.$router.push('/welcome');
|
this.$router.push('/welcome');
|
||||||
}, response => {
|
}, response => {
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
methods: {
|
methods: {
|
||||||
//获取用户信息
|
//获取用户信息
|
||||||
getPersonInfo(user_id) {
|
getPersonInfo(user_id) {
|
||||||
this.$http.get(`/api/account/users/${user_id}`).then((response) => {
|
this.$http.get(`/api/account/users/self`).then((response) => {
|
||||||
this.personInfo = response.result;
|
this.personInfo = response.result;
|
||||||
}, (response) => this.$layer_message(response.result))
|
}, (response) => this.$layer_message(response.result))
|
||||||
},
|
},
|
||||||
|
|
|
@ -133,8 +133,8 @@
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
//获取用户信息
|
//获取用户信息
|
||||||
getPersonInfo(user_id) {
|
getPersonInfo() {
|
||||||
this.$http.get(`/api/account/users/${user_id}`).then((response) => {
|
this.$http.get(`/api/account/users/self`).then((response) => {
|
||||||
this.personInfo = response.result;
|
this.personInfo = response.result;
|
||||||
}, (response) => this.$layer_message(response.result))
|
}, (response) => this.$layer_message(response.result))
|
||||||
},
|
},
|
||||||
|
@ -147,24 +147,30 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
modifyPwd: function () {
|
modifyPwd: function () {
|
||||||
this.$http.post(`/api/account/users/modifypwd`, this.pwdInfo).then(response => {
|
if (this.pwdInfo.newpassword !== this.pwdInfo.surepassword) {
|
||||||
|
this.$layer_message('两次输入密码不一致');
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.$http.post(`/api/account/users/setting/password`, this.pwdInfo).then(() => {
|
||||||
this.$layer_message('修改成功', 'success');
|
this.$layer_message('修改成功', 'success');
|
||||||
|
this.logout();
|
||||||
}, response => this.$layer_message(response.result));
|
}, response => this.$layer_message(response.result));
|
||||||
},
|
},
|
||||||
modifyPerson: function () {
|
modifyPerson: function () {
|
||||||
console.log(this.personInfo);
|
this.$http.post(`/api/account/users/setting/info`, this.personInfo).then(() => {
|
||||||
this.$http.put(`/api/account/users/${this.personInfo.id}`, this.personInfo).then(response => {
|
|
||||||
this.$layer_message('保存成功', 'success');
|
this.$layer_message('保存成功', 'success');
|
||||||
localStorage.setItem('nickname', response.result['nickname']);
|
localStorage.setItem('nickname', this.personInfo['nickname']);
|
||||||
}, response => this.$layer_message(response.result));
|
}, response => this.$layer_message(response.result));
|
||||||
},
|
},
|
||||||
getPerson(){
|
logout() {
|
||||||
let user_id = localStorage.getItem('user_id');
|
this.$http.get('/api/account/users/logout/').finally(() => {
|
||||||
this.getPersonInfo(user_id);
|
localStorage.removeItem('token');
|
||||||
|
this.$router.push({name: 'login'})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.getPerson();
|
this.getPersonInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
Loading…
Reference in New Issue