修改密码修改头像

pull/23/head
taoshihan1991 4 years ago
parent b4bb3e6381
commit 27f1a7bf4f

@ -10,6 +10,54 @@ import (
"strconv"
)
func PostKefuAvator(c *gin.Context) {
avator := c.PostForm("avator")
if avator == "" {
c.JSON(200, gin.H{
"code": 400,
"msg": "不能为空",
"result": "",
})
return
}
kefuName, _ := c.Get("kefu_name")
models.UpdateUserAvator(kefuName.(string), avator)
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result": "",
})
}
func PostKefuPass(c *gin.Context) {
kefuName, _ := c.Get("kefu_name")
newPass := c.PostForm("new_pass")
confirmNewPass := c.PostForm("confirm_new_pass")
old_pass := c.PostForm("old_pass")
if newPass != confirmNewPass {
c.JSON(200, gin.H{
"code": 400,
"msg": "密码不一致",
"result": "",
})
return
}
user := models.FindUser(kefuName.(string))
if user.Password != tools.Md5(old_pass) {
c.JSON(200, gin.H{
"code": 400,
"msg": "旧密码不正确",
"result": "",
})
return
}
models.UpdateUserPass(kefuName.(string), tools.Md5(newPass))
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result": "",
})
}
func GetKefuInfo(c *gin.Context) {
kefuId, _ := c.Get("kefu_id")
user := models.FindUserById(kefuId)

@ -35,6 +35,18 @@ func UpdateUser(id string, name string, password string, avator string, nickname
}
DB.Model(&User{}).Where("id = ?", id).Update(user)
}
func UpdateUserPass(name string, pass string) {
user := &User{
Password: pass,
}
DB.Model(user).Where("name = ?", name).Update("Password", pass)
}
func UpdateUserAvator(name string, avator string) {
user := &User{
Avator: avator,
}
DB.Model(user).Where("name = ?", name).Update("Avator", avator)
}
func FindUser(username string) User {
var user User
DB.Where("name = ?", username).First(&user)

@ -54,6 +54,8 @@ func InitApiRouter(engine *gin.Engine) {
engine.GET("/kefulist", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.GetKefuList)
engine.GET("/other_kefulist", middleware.JwtApiMiddleware, controller.GetOtherKefuList)
engine.GET("/trans_kefu", middleware.JwtApiMiddleware, controller.PostTransKefu)
engine.POST("/modifypass", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.PostKefuPass)
engine.POST("/modifyavator", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.PostKefuAvator)
//角色列表
engine.GET("/roles", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.GetRoleList)
engine.POST("/role", middleware.JwtApiMiddleware, middleware.RbacAuth, controller.PostRole)

@ -93,6 +93,7 @@
</div>
</el-row>
<el-pagination
v-show="visitorCount>visitorPageSize"
background
@current-change="visitorPage"
:current-page="visitorCurrentPage"

@ -1,10 +1,53 @@
{{template "header" }}
<style>
.avatar-uploader .el-upload {
border: 1px dashed #d9d9d9;
border-radius: 6px;
cursor: pointer;
position: relative;
overflow: hidden;
}
.avatar-uploader .el-upload:hover {
border-color: #409EFF;
}
.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 178px;
height: 178px;
line-height: 178px;
text-align: center;
}
.avatar {
width: 178px;
height: 178px;
display: block;
}
</style>
<div id="app" style="width:100%">
<template>
<el-container>
<el-main class="mainMain">
aaa
<el-form :model="modifyPass" label-width="100px">
<el-form-item label="原头像">
<el-avatar :size="120" :src="avatarUrl"></el-avatar>
</el-form-item>
<el-form-item label="新头像">
<el-upload
class="avatar-uploader"
action="/uploadimg"
:show-file-list="false"
name="imgfile"
:on-success="handleAvatarSuccess"
:before-upload="beforeAvatarUpload">
<i class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="setModifyAvatar()">保存</el-button>
</el-form-item>
</el-form>
</el-main>
</el-container>

@ -94,6 +94,12 @@
html_cn: "",
html_en: "",
},
modifyPass:{
old_pass:"",
new_pass:"",
confirm_new_pass:""
},
avatarUrl:"",
},
methods: {
@ -225,6 +231,11 @@
_this.pageindex=result;
});
}
if(ACTION=="setting_avator"){
this.sendAjax("/kefuinfo","get",{},function(result){
_this.avatarUrl=result.avator;
});
}
},
sendAjax(url,method,params,callback){
let _this=this;
@ -400,6 +411,45 @@
});
});
},
//修改密码
setModifyPass(){
let _this=this;
this.sendAjax("/modifypass","POST",_this.modifyPass,function(result){
_this.$message({
message: "修改成功",
type: 'success'
});
_this.modifyPass.new_pass=_this.modifyPass.old_pass=_this.modifyPass.confirm_new_pass=""
});
},
//修改密码
setModifyAvatar(){
let _this=this;
this.sendAjax("/modifyavator","POST",{avator:_this.avatarUrl},function(result){
_this.$message({
message: "修改成功",
type: 'success'
});
});
},
handleAvatarSuccess(res, file) {
console.log(res,file);
if(res.code!=200){
_this.$message({
message: res.msg,
type: 'error'
});
return;
}
this.avatarUrl = '/'+res.result.path;
},
beforeAvatarUpload(file) {
var isLt2M = file.size / 1024 / 1024 < 1;
if (!isLt2M) {
this.$message.error('上传头像图片大小不能超过 1MB!');
}
return isLt2M;
},
//生成部署js
createDeployJs(){
let domain=window.location.host;

@ -4,7 +4,21 @@
<el-container>
<el-main class="mainMain">
bbb
<el-form :model="modifyPass" label-width="100px">
<el-form-item label="原密码">
<el-input v-model="modifyPass.old_pass"></el-input>
</el-form-item>
<el-form-item label="新密码">
<el-input v-model="modifyPass.new_pass"></el-input>
</el-form-item>
<el-form-item label="重复新密码">
<el-input v-model="modifyPass.confirm_new_pass"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="setModifyPass()">保存</el-button>
<el-button>取消</el-button>
</el-form-item>
</el-form>
</el-main>
</el-container>

Loading…
Cancel
Save