实现个人中心数据校验,修复个人中心修改姓名和学号不会更新用户列表标识问题
This commit is contained in:
@@ -69,10 +69,21 @@ public class LoginController {
|
|||||||
@PostMapping("/beforeLogin")
|
@PostMapping("/beforeLogin")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public boolean beforeLogin(TbUser tbUser)throws Exception{
|
public boolean beforeLogin(TbUser tbUser)throws Exception{
|
||||||
System.out.println(tbUser.toString());
|
|
||||||
//加密用户密码
|
|
||||||
tbUser.setColpassword(new BigInteger(CodingUtil.encryptSHA(tbUser.getColpassword().getBytes())).toString(32));
|
tbUser.setColpassword(new BigInteger(CodingUtil.encryptSHA(tbUser.getColpassword().getBytes())).toString(32));
|
||||||
TbUser user = userService.doLoginService(tbUser.getColname(),tbUser.getColpassword());
|
TbUser user = userService.doLoginService(tbUser.getColname(),tbUser.getColpassword());
|
||||||
return user!=null;
|
return user!=null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录时判断用户名是否存在,若不存在,则返回false
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@GetMapping("/beforeLoginCheckNameExist")
|
||||||
|
@ResponseBody
|
||||||
|
public boolean beforeLoginCheckNameExist(@RequestParam(value = "name") String name)throws Exception{
|
||||||
|
Optional<TbUser> user = userService.findByColname(name);
|
||||||
|
return user.isPresent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class RegisterController {
|
|||||||
tbUser.setColpassword(new BigInteger(CodingUtil.encryptSHA(tbUser.getColpassword().getBytes())).toString(32));
|
tbUser.setColpassword(new BigInteger(CodingUtil.encryptSHA(tbUser.getColpassword().getBytes())).toString(32));
|
||||||
if (userService.doRegisterService(tbUser)){
|
if (userService.doRegisterService(tbUser)){
|
||||||
//更新用户列表是否注册的标记
|
//更新用户列表是否注册的标记
|
||||||
studentService.UpdateStudentListRegistered(tbUser.getColrealname(),tbUser.getColstudentno());
|
studentService.UpdateStudentListRegistered(tbUser.getColrealname(),tbUser.getColstudentno(),RegisteredEnum.REGISTERED.getCode());
|
||||||
return true;
|
return true;
|
||||||
/*return "redirect:" + request.getScheme() + "://" + request.getServerName() + ":"
|
/*return "redirect:" + request.getScheme() + "://" + request.getServerName() + ":"
|
||||||
+ serverProperties.getPortNum() + request.getContextPath() + "/index";*/
|
+ serverProperties.getPortNum() + request.getContextPath() + "/index";*/
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package com.fjy.spring.controller;
|
package com.fjy.spring.controller;
|
||||||
|
|
||||||
import com.fjy.spring.domain.TbUser;
|
import com.fjy.spring.domain.TbUser;
|
||||||
|
import com.fjy.spring.domain.VUserinfo;
|
||||||
|
import com.fjy.spring.enums.RegisteredEnum;
|
||||||
import com.fjy.spring.enums.ResultEnum;
|
import com.fjy.spring.enums.ResultEnum;
|
||||||
import com.fjy.spring.exception.UserException;
|
import com.fjy.spring.exception.UserException;
|
||||||
import com.fjy.spring.properties.ServerProperties;
|
import com.fjy.spring.properties.ServerProperties;
|
||||||
|
import com.fjy.spring.service.StudentService;
|
||||||
import com.fjy.spring.service.UserService;
|
import com.fjy.spring.service.UserService;
|
||||||
import com.fjy.spring.untils.CodingUtil;
|
import com.fjy.spring.untils.CodingUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -11,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.BindingResult;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -22,6 +26,9 @@ public class UpdateController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StudentService studentService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ServerProperties serverProperties;
|
private ServerProperties serverProperties;
|
||||||
|
|
||||||
@@ -29,20 +36,28 @@ public class UpdateController {
|
|||||||
HttpServletRequest request;
|
HttpServletRequest request;
|
||||||
|
|
||||||
@PostMapping(value = "/home/userUpdate")
|
@PostMapping(value = "/home/userUpdate")
|
||||||
public String doUserUpdate(TbUser tbUser)throws Exception{
|
@ResponseBody
|
||||||
|
public boolean doUserUpdate(TbUser tbUser)throws Exception{
|
||||||
if (tbUser.getColuserid()==null){
|
if (tbUser.getColuserid()==null){
|
||||||
throw new UserException(ResultEnum.ID_NULLPOINT);
|
throw new UserException(ResultEnum.ID_NULLPOINT);
|
||||||
}
|
}
|
||||||
if (tbUser.getColpassword()!=null){
|
if (tbUser.getColpassword()!=null){
|
||||||
userService.updateColpasswordByColname(tbUser.getColpassword(),tbUser.getColname());
|
userService.updateColpasswordByColname(tbUser.getColpassword(),tbUser.getColname());
|
||||||
}
|
}
|
||||||
|
//注销原本的注册标记
|
||||||
|
VUserinfo tempUser = userService.findUserInfo(tbUser.getColuserid());
|
||||||
|
studentService.UpdateStudentListRegistered(tempUser.getColrealname(),tempUser.getColstudentno(),
|
||||||
|
RegisteredEnum.UNREGISTERED.getCode());
|
||||||
if (userService.doRegisterService(tbUser)){
|
if (userService.doRegisterService(tbUser)){
|
||||||
|
studentService.UpdateStudentListRegistered(tbUser.getColrealname(),tbUser.getColstudentno(),
|
||||||
|
RegisteredEnum.REGISTERED.getCode());
|
||||||
log.info(tbUser.getColname()+" 信息更新成功");
|
log.info(tbUser.getColname()+" 信息更新成功");
|
||||||
return "redirect:" + request.getScheme() + "://" + request.getServerName() + ":"
|
return true;
|
||||||
+ serverProperties.getPortNum() + request.getContextPath() + "/home/user";
|
/*return "redirect:" + request.getScheme() + "://" + request.getServerName() + ":"
|
||||||
|
+ serverProperties.getPortNum() + request.getContextPath() + "/home/user";*/
|
||||||
// return "login";
|
// return "login";
|
||||||
}
|
}
|
||||||
log.error(tbUser.getColname()+" 信息更新失败");
|
log.error(tbUser.getColname()+" 信息更新失败");
|
||||||
throw new UserException(ResultEnum.UNKOWN_ERROR);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ public class StudentService {
|
|||||||
return tbStudentListRepository.findByColstudentnoAndColrealname(studentno,realname);
|
return tbStudentListRepository.findByColstudentnoAndColrealname(studentno,realname);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TbStudentlist UpdateStudentListRegistered(String realname,String studentno){
|
public TbStudentlist UpdateStudentListRegistered(String realname,String studentno,Integer code){
|
||||||
TbStudentlist studentlist = new TbStudentlist();
|
TbStudentlist studentlist = new TbStudentlist();
|
||||||
studentlist = findByColstudentnoAndColrealname(studentno,realname);
|
studentlist = findByColstudentnoAndColrealname(studentno,realname);
|
||||||
studentlist.setRegistered(RegisteredEnum.REGISTERED.getCode());
|
studentlist.setRegistered(code);
|
||||||
return tbStudentListRepository.save(studentlist);
|
return tbStudentListRepository.save(studentlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,8 +64,25 @@ var Main = {
|
|||||||
var checkName1 = (rule, value, callback) => {
|
var checkName1 = (rule, value, callback) => {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return callback(new Error('用户名不能为空'));
|
return callback(new Error('用户名不能为空'));
|
||||||
} else {
|
}else {
|
||||||
callback()
|
//判断用户名是否已存在
|
||||||
|
axios.get(getRootPath_web() + '/beforeLoginCheckNameExist', {
|
||||||
|
params: {
|
||||||
|
name: value
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(function (response) {
|
||||||
|
console.log(response.data);
|
||||||
|
if (response.data === true) {
|
||||||
|
callback()
|
||||||
|
} else {
|
||||||
|
return callback(new Error('用户名未注册'));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
console.log(error);
|
||||||
|
that.errorNotify(error.message);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var checkNo = (rule, value, callback) => {
|
var checkNo = (rule, value, callback) => {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
var dt = new Date();
|
var dt = new Date();
|
||||||
let th = this;
|
let th = this;
|
||||||
|
/*let username = this.ruleForm2.colname.value;*/
|
||||||
var month = dt.getMonth()+1;
|
var month = dt.getMonth()+1;
|
||||||
var day = dt.getDate();
|
var day = dt.getDate();
|
||||||
var year = dt.getFullYear();
|
var year = dt.getFullYear();
|
||||||
@@ -30,24 +31,79 @@ var Main = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
var checkName = (rule, value, callback) => {
|
var checkName = (rule, value, callback) => {
|
||||||
|
let that= this;
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return callback(new Error('用户名不能为空'));
|
return callback(new Error('用户名不能为空'));
|
||||||
}else {
|
}else {
|
||||||
callback()
|
//判断用户名是否已存在
|
||||||
|
axios.get(getRootPath_web() + '/CheckUserName', {
|
||||||
|
params: {
|
||||||
|
name: value
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(function (response) {
|
||||||
|
console.log(response.data);
|
||||||
|
if (response.data === true) {
|
||||||
|
callback();
|
||||||
|
} else if(value!==that.ruleForm2.colname){
|
||||||
|
return callback(new Error('用户名已存在'));
|
||||||
|
}else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
console.log(error);
|
||||||
|
that.errorNotify(error.message);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var checkNo = (rule, value, callback) => {
|
var checkNo = (rule, value, callback) => {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return callback(new Error('学号不能为空'));
|
return callback(new Error('学号不能为空'));
|
||||||
}else {
|
} else {
|
||||||
callback()
|
//判断是否为指定班级的合法用户
|
||||||
|
axios.get(getRootPath_web() + '/CheckStudentNo', {
|
||||||
|
params: {
|
||||||
|
studentno: value
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(function (response) {
|
||||||
|
console.log(response.data);
|
||||||
|
if (response.data === true) {
|
||||||
|
callback()
|
||||||
|
} else {
|
||||||
|
return callback(new Error('学号非法'));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
console.log(error);
|
||||||
|
this.errorNotify(error.message);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var checkRealName = (rule, value, callback) => {
|
var checkRealName = (rule, value, callback) => {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return callback(new Error('真实姓名不能为空'));
|
return callback(new Error('真实姓名不能为空'));
|
||||||
}else {
|
} else {
|
||||||
callback()
|
//判断用户名与学号是否匹配
|
||||||
|
axios.get(getRootPath_web() + '/CheckStudent', {
|
||||||
|
params: {
|
||||||
|
realname: value,
|
||||||
|
studentno: this.ruleForm2.colstudentno
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(function (response) {
|
||||||
|
console.log(response.data);
|
||||||
|
if (response.data === false) {
|
||||||
|
return callback(new Error('姓名与学号不匹配或该用户已注册'));
|
||||||
|
} else {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
console.log(error);
|
||||||
|
this.errorNotify(error.message);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var validatePass = (rule, value, callback) => {
|
var validatePass = (rule, value, callback) => {
|
||||||
@@ -157,6 +213,12 @@ var Main = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
errorNotify(content) {
|
||||||
|
this.$notify.error({
|
||||||
|
title: '错误',
|
||||||
|
message: content
|
||||||
|
})
|
||||||
|
},
|
||||||
openNotiSuccess(title, content) {
|
openNotiSuccess(title, content) {
|
||||||
this.$notify({
|
this.$notify({
|
||||||
title: title,
|
title: title,
|
||||||
@@ -176,15 +238,12 @@ var Main = {
|
|||||||
submitForm(formName, url) {
|
submitForm(formName, url) {
|
||||||
this.$refs[formName].validate((valid) => {
|
this.$refs[formName].validate((valid) => {
|
||||||
var that = this;
|
var that = this;
|
||||||
if (valid) {//此处暂时去除校验
|
if (valid) {
|
||||||
axios({
|
axios({
|
||||||
url: getRootPath_web()+'/' + url,
|
url: getRootPath_web()+'/home/userUpdate',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: {
|
data: that.ruleForm2
|
||||||
userid:th.ruleForm3.userid.value,
|
,
|
||||||
question:th.ruleForm3.question.value,
|
|
||||||
answer:th.ruleForm3.answer.value
|
|
||||||
},
|
|
||||||
transformRequest: [function (data) {
|
transformRequest: [function (data) {
|
||||||
// Do whatever you want to transform the data
|
// Do whatever you want to transform the data
|
||||||
let ret = ''
|
let ret = ''
|
||||||
@@ -199,7 +258,7 @@ var Main = {
|
|||||||
}).then(function (response) {
|
}).then(function (response) {
|
||||||
console.log(response.data);
|
console.log(response.data);
|
||||||
if (response.data===true){
|
if (response.data===true){
|
||||||
that.openNotiSuccess("成功", "修改成功!");
|
that.openNotiSuccess("成功", "修改成功,刷新页面即可查看新信息!");
|
||||||
}else if (response.data===false){
|
}else if (response.data===false){
|
||||||
that.openNotiError("失败", "修改失败!");
|
that.openNotiError("失败", "修改失败!");
|
||||||
}else {
|
}else {
|
||||||
@@ -220,6 +279,54 @@ var Main = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
clickToSubmit(formName) {
|
||||||
|
this.$refs[formName].validate((valid) => {
|
||||||
|
var that = this;
|
||||||
|
if (valid) {
|
||||||
|
axios({
|
||||||
|
url: getRootPath_web() + '/beforeLogin',
|
||||||
|
method: 'post',
|
||||||
|
data: {
|
||||||
|
colname: outSideThis.ruleForm1.colname.value,
|
||||||
|
colpassword: outSideThis.ruleForm1.colpassword.value
|
||||||
|
},
|
||||||
|
transformRequest: [function (data) {
|
||||||
|
// Do whatever you want to transform the data
|
||||||
|
let ret = '';
|
||||||
|
for (let it in data) {
|
||||||
|
ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}],
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
}
|
||||||
|
}).then(function (response) {
|
||||||
|
console.log(response.data);
|
||||||
|
if (response.data === true) {
|
||||||
|
//that.$refs[formName].submit;
|
||||||
|
//return true;
|
||||||
|
document.getElementById('ruleForm1').submit();
|
||||||
|
} else if (response.data === false) {
|
||||||
|
that.openNotiError("失败", response.data.message);
|
||||||
|
} else {
|
||||||
|
that.openNotiError("错误", response.data.message);
|
||||||
|
}
|
||||||
|
}).catch(function (error) {
|
||||||
|
console.log(error);
|
||||||
|
that.openNotiError("错误", "服务器错误!");
|
||||||
|
});
|
||||||
|
//console.log(this.$refs.content.value)
|
||||||
|
//this.openNotiSuccess("成功", "修改成功!")
|
||||||
|
//this.$options.methods.openNotiSuccess.bind(this)();
|
||||||
|
//alert('submit!');
|
||||||
|
} else {
|
||||||
|
console.log('error submit!!');
|
||||||
|
that.openNotiError("错误", "表单填写错误!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
resetForm(formName) {
|
resetForm(formName) {
|
||||||
this.$refs[formName].resetFields();
|
this.$refs[formName].resetFields();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -60,7 +60,7 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button type="primary"
|
<el-button type="primary"
|
||||||
native-type="submit">提交
|
@click="submitForm('ruleForm2')">提交
|
||||||
</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