实现用户信息修改
This commit is contained in:
@@ -0,0 +1,46 @@
|
|||||||
|
package com.fjy.spring.controller;
|
||||||
|
|
||||||
|
import com.fjy.spring.domain.TbUser;
|
||||||
|
import com.fjy.spring.enums.ResultEnum;
|
||||||
|
import com.fjy.spring.exception.UserException;
|
||||||
|
import com.fjy.spring.properties.ServerProperties;
|
||||||
|
import com.fjy.spring.service.UserService;
|
||||||
|
import com.fjy.spring.untils.CodingUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class UpdateController {
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ServerProperties serverProperties;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
HttpServletRequest request;
|
||||||
|
|
||||||
|
@PostMapping(value = "/home/userUpdate")
|
||||||
|
public String doUserUpdate(TbUser tbUser)throws Exception{
|
||||||
|
if (tbUser.getColuserid()==null){
|
||||||
|
throw new UserException(ResultEnum.ID_NULLPOINT);
|
||||||
|
}
|
||||||
|
if (tbUser.getColpassword()!=null&&tbUser.getColpassword()!=""){
|
||||||
|
//加密用户密码
|
||||||
|
tbUser.setColpassword(new BigInteger(CodingUtil.encryptSHA(tbUser.getColpassword().getBytes())).toString(32));
|
||||||
|
}
|
||||||
|
if (userService.doRegisterService(tbUser)){
|
||||||
|
System.out.println(tbUser.getColname()+" 信息更新成功");
|
||||||
|
return "redirect:" + request.getScheme() + "://" + request.getServerName() + ":"
|
||||||
|
+ serverProperties.getPortNum() + request.getContextPath() + "/home/user";
|
||||||
|
// return "login";
|
||||||
|
}
|
||||||
|
throw new UserException(ResultEnum.UNKOWN_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
package com.fjy.spring.domain;
|
package com.fjy.spring.domain;
|
||||||
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
@@ -11,7 +12,9 @@ public class TbUser {
|
|||||||
private Integer coluserid;
|
private Integer coluserid;
|
||||||
@NotNull(message = "用户名必填")
|
@NotNull(message = "用户名必填")
|
||||||
private String colname;
|
private String colname;
|
||||||
@NotNull(message = "密码不能为空")
|
|
||||||
|
@Column(updatable=false)
|
||||||
|
/*@NotNull(message = "密码不能为空")*/
|
||||||
private String colpassword;
|
private String colpassword;
|
||||||
private String colemail;
|
private String colemail;
|
||||||
@NotNull(message = "学号必填")
|
@NotNull(message = "学号必填")
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ public enum ResultEnum {
|
|||||||
WRONGPASS(105,"用户名或密码错误"),
|
WRONGPASS(105,"用户名或密码错误"),
|
||||||
ILLEGAL_ACCESS(106,"非法访问"),
|
ILLEGAL_ACCESS(106,"非法访问"),
|
||||||
WRONG_FORM(107,"表单错误"),
|
WRONG_FORM(107,"表单错误"),
|
||||||
EMPTY_DATA(108,"无数据")
|
EMPTY_DATA(108,"无数据"),
|
||||||
|
ID_NULLPOINT(109,"id为空"),
|
||||||
;
|
;
|
||||||
private Integer code;
|
private Integer code;
|
||||||
private String msg;
|
private String msg;
|
||||||
|
|||||||
@@ -14,21 +14,6 @@ function DateDiff(sDate1, sDate2){ //sDate1和sDate2是2002-12-18格式
|
|||||||
}
|
}
|
||||||
var Main = {
|
var Main = {
|
||||||
data() {
|
data() {
|
||||||
var checkName = (rule, value, callback) => {
|
|
||||||
if (!value) {
|
|
||||||
return callback(new Error('用户名不能为空'));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var checkNo = (rule, value, callback) => {
|
|
||||||
if (!value) {
|
|
||||||
return callback(new Error('学号不能为空'));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var checkRealName = (rule, value, callback) => {
|
|
||||||
if (!value) {
|
|
||||||
return callback(new Error('真实姓名不能为空'));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var validatePass = (rule, value, callback) => {
|
var validatePass = (rule, value, callback) => {
|
||||||
if (value === '') {
|
if (value === '') {
|
||||||
callback(new Error('请输入密码'));
|
callback(new Error('请输入密码'));
|
||||||
@@ -51,33 +36,18 @@ var Main = {
|
|||||||
return {
|
return {
|
||||||
activeIndex: '1',
|
activeIndex: '1',
|
||||||
ruleForm2: {
|
ruleForm2: {
|
||||||
|
coluserid:'',
|
||||||
|
colname: '',
|
||||||
|
colstudentno: '',
|
||||||
|
colrealname: '',
|
||||||
|
colemail: '',
|
||||||
colpassword: '',
|
colpassword: '',
|
||||||
checkPass: '',
|
checkPass: '',
|
||||||
},
|
},
|
||||||
rules2: {
|
rules2: {
|
||||||
colpassword: [
|
|
||||||
{required: true, validator: validatePass, trigger: 'blur'}
|
|
||||||
],
|
|
||||||
checkPass: [
|
checkPass: [
|
||||||
{required: true, validator: validatePass2, trigger: 'blur'}
|
{ validator: validatePass2, trigger: 'blur'}
|
||||||
],
|
]
|
||||||
colstudentno: [
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
validator: checkNo,
|
|
||||||
trigger: 'blur'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
colrealname: [
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
validator: checkRealName,
|
|
||||||
trigger: 'blur'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
colname: [
|
|
||||||
{required: true, validator: checkName, trigger: 'blur'}
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
tableHomeworkData: [
|
tableHomeworkData: [
|
||||||
{
|
{
|
||||||
@@ -116,7 +86,7 @@ var Main = {
|
|||||||
},
|
},
|
||||||
submitForm(formName, url) {
|
submitForm(formName, url) {
|
||||||
this.$refs[formName].validate((valid) => {
|
this.$refs[formName].validate((valid) => {
|
||||||
if (valid) {
|
if (true) {//此处暂时去除校验
|
||||||
axios({
|
axios({
|
||||||
url: 'http://localhost:8080/cms/' + url,
|
url: 'http://localhost:8080/cms/' + url,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
|
|||||||
@@ -19,43 +19,47 @@
|
|||||||
<el-form
|
<el-form
|
||||||
:model="ruleForm2" status-icon :rules="rules2" ref="ruleForm2"
|
:model="ruleForm2" status-icon :rules="rules2" ref="ruleForm2"
|
||||||
label-width="100px" class="demo-ruleForm"
|
label-width="100px" class="demo-ruleForm"
|
||||||
action="/cms/register/doregister"
|
action="/cms/home/userUpdate"
|
||||||
method="POST" name="register">
|
method="POST" name="register">
|
||||||
|
<el-form-item label="ID"
|
||||||
|
prop="coluserid">
|
||||||
|
<el-input :readonly="true"
|
||||||
|
th:value="${#httpServletRequest.getSession().getAttribute('USER_SESSION').coluserid}" name="coluserid" readonly></el-input>
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="用户名"
|
<el-form-item label="用户名"
|
||||||
prop="colname">
|
prop="colname">
|
||||||
<el-input
|
<el-input
|
||||||
th:value="${#httpServletRequest.getSession().getAttribute('USER_SESSION').colname}" name="colname"></el-input>
|
th:value="${#httpServletRequest.getSession().getAttribute('USER_SESSION').colname}" name="colname" ref="name"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item
|
<el-form-item
|
||||||
label="密码" prop="colpassword">
|
label="密码" prop="colpassword">
|
||||||
<el-input type="password"
|
<el-input type="password" placeholder="不改密码则留空"
|
||||||
v-model="ruleForm2.colpassword" auto-complete="off" name="colpassword"></el-input>
|
v-model="ruleForm2.colpassword" auto-complete="off" name="colpassword"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="确认密码" prop="checkPass">
|
<el-form-item label="确认密码" prop="checkPass">
|
||||||
<el-input
|
<el-input placeholder="不改密码则留空"
|
||||||
type="password" v-model="ruleForm2.checkPass"
|
type="password" v-model="ruleForm2.checkPass"
|
||||||
auto-complete="off" name="checkPass"></el-input>
|
auto-complete="off" name="checkPass"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item prop="colemail" label="邮箱"
|
<el-form-item prop="colemail" label="邮箱"
|
||||||
:rules="[
|
:rules="[
|
||||||
{ required: true, message: '请输入邮箱地址', trigger: 'blur' },
|
|
||||||
{ type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur,change' }
|
{ type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur,change' }
|
||||||
]">
|
]">
|
||||||
<el-input th:value="${#httpServletRequest.getSession().getAttribute('USER_SESSION').colemail}" name="colemail"></el-input>
|
<el-input th:value="${#httpServletRequest.getSession().getAttribute('USER_SESSION').colemail}" name="colemail" ref="email"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="学号"
|
<el-form-item label="学号"
|
||||||
prop="colstudentno">
|
prop="colstudentno">
|
||||||
<el-input
|
<el-input
|
||||||
th:value="${#httpServletRequest.getSession().getAttribute('USER_SESSION').colstudentno}" name="colstudentno"></el-input>
|
th:value="${#httpServletRequest.getSession().getAttribute('USER_SESSION').colstudentno}" name="colstudentno" ref="studentno"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="真实姓名"
|
<el-form-item label="真实姓名"
|
||||||
prop="colrealname">
|
prop="colrealname">
|
||||||
<el-input
|
<el-input
|
||||||
th:value="${#httpServletRequest.getSession().getAttribute('USER_SESSION').colrealname}" name="colrealname"></el-input>
|
th:value="${#httpServletRequest.getSession().getAttribute('USER_SESSION').colrealname}" name="colrealname" ref="realname"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button type="primary"
|
<el-button type="primary"
|
||||||
@click="submitForm('feedbackForm','register/doregister')">提交
|
native-type="submit">提交
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button @click="resetForm('ruleForm2')">重置</el-button>
|
<el-button @click="resetForm('ruleForm2')">重置</el-button>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|||||||
Reference in New Issue
Block a user