提交 8329c655 编写于 作者: 江南一点雨

完善用户个人中心

上级 7ff5d70e
......@@ -26,4 +26,6 @@ public interface HrMapper {
List<Hr> getAllHrs(@Param("hrid") Integer hrid, @Param("keywords") String keywords);
List<Hr> getAllHrsExceptCurrentHr(Integer id);
Integer updatePasswd(@Param("hrid") Integer hrid, @Param("encodePass") String encodePass);
}
\ No newline at end of file
......@@ -161,6 +161,9 @@
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updatePasswd">
update hr set password = #{encodePass} where id=#{hrid};
</update>
<update id="updateByPrimaryKey" parameterType="org.javaboy.vhr.model.Hr">
update hr
set name = #{name,jdbcType=VARCHAR},
......
......@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -64,4 +65,17 @@ public class HrService implements UserDetailsService {
public Integer updateHyById(Hr hr) {
return hrMapper.updateByPrimaryKeySelective(hr);
}
public boolean updateHrPasswd(String oldpass, String pass, Integer hrid) {
Hr hr = hrMapper.selectByPrimaryKey(hrid);
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
if (encoder.matches(oldpass, hr.getPassword())) {
String encodePass = encoder.encode(pass);
Integer result = hrMapper.updatePasswd(hrid, encodePass);
if (result == 1) {
return true;
}
}
return false;
}
}
......@@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* @作者 江南一点雨
* @公众号 江南一点雨
......@@ -37,4 +39,16 @@ public class HrInfoController {
}
return RespBean.error("更新失败!");
}
@PutMapping("/hr/pass")
public RespBean updateHrPasswd(@RequestBody Map<String, Object> info) {
String oldpass = (String) info.get("oldpass");
String pass = (String) info.get("pass");
Integer hrid = (Integer) info.get("hrid");
if (hrService.updateHrPasswd(oldpass, pass, hrid)) {
return RespBean.ok("更新成功!");
}
return RespBean.error("更新失败!");
}
}
......@@ -25,10 +25,32 @@
</div>
<div style="display: flex;justify-content: space-around;margin-top: 10px">
<el-button type="primary" @click="showUpdateHrInfoView">修改信息</el-button>
<el-button type="danger">修改密码</el-button>
<el-button type="danger" @click="showUpdatePasswdView">修改密码</el-button>
</div>
</div>
</el-card>
<el-dialog
title="修改密码"
:visible.sync="passwdDialogVisible"
width="30%">
<div>
<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
<el-form-item label="请输入旧密码" prop="oldpass">
<el-input type="password" v-model="ruleForm.oldpass" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="请输入新密码" prop="pass">
<el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="新确认密码" prop="checkPass">
<el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
<el-button @click="resetForm('ruleForm')">重置</el-button>
</el-form-item>
</el-form>
</div>
</el-dialog>
<el-dialog
title="修改用户信息"
:visible.sync="dialogVisible"
......@@ -65,9 +87,45 @@
export default {
name: "HrInfo",
data() {
var validatePass = (rule, value, callback) => {
if (value === '') {
callback(new Error('请输入密码'));
} else {
if (this.ruleForm.checkPass !== '') {
this.$refs.ruleForm.validateField('checkPass');
}
callback();
}
};
var validatePass2 = (rule, value, callback) => {
if (value === '') {
callback(new Error('请再次输入密码'));
} else if (value !== this.ruleForm.pass) {
callback(new Error('两次输入密码不一致!'));
} else {
callback();
}
};
return {
ruleForm: {
oldpass:'',
pass: '',
checkPass: ''
},
rules: {
oldpass: [
{ validator: validatePass, trigger: 'blur' }
],
pass: [
{ validator: validatePass, trigger: 'blur' }
],
checkPass: [
{ validator: validatePass2, trigger: 'blur' }
]
},
hr: null,
hr2: null,
passwdDialogVisible:false,
dialogVisible:false
}
},
......@@ -75,6 +133,29 @@
this.initHr();
},
methods: {
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
this.ruleForm.hrid = this.hr.id;
this.putRequest("/hr/pass",this.ruleForm).then(resp=>{
if (resp) {
this.getRequest("/logout");
window.sessionStorage.removeItem("user")
this.$store.commit('initRoutes', []);
this.$router.replace("/");
}
})
} else {
return false;
}
});
},
resetForm(formName) {
this.$refs[formName].resetFields();
},
showUpdatePasswdView() {
this.passwdDialogVisible = true;
},
updateHrInfo() {
this.putRequest("/hr/info",this.hr2).then(resp=>{
if (resp) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册