mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 15:01:23 +08:00
Added email and tel verify
This commit is contained in:
@@ -13,8 +13,10 @@ import com.cfive.pinnacle.utils.WebUtil;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -56,6 +58,8 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean modifyStaff(User user) {
|
public boolean modifyStaff(User user) {
|
||||||
|
verifyEmailAndTel(user.getStaff());
|
||||||
|
|
||||||
Long departmentId = user.getDepartmentId();
|
Long departmentId = user.getDepartmentId();
|
||||||
Staff newStaff = user.getStaff();
|
Staff newStaff = user.getStaff();
|
||||||
user = userMapper.getOneById(user.getId());
|
user = userMapper.getOneById(user.getId());
|
||||||
@@ -81,6 +85,8 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean modifySelf(Staff staff) {
|
public boolean modifySelf(Staff staff) {
|
||||||
|
verifyEmailAndTel(staff);
|
||||||
|
|
||||||
User user = WebUtil.getLoginUser().getUser();
|
User user = WebUtil.getLoginUser().getUser();
|
||||||
Staff oldStaff = user.getStaff();
|
Staff oldStaff = user.getStaff();
|
||||||
staff.setUserId(user.getId());
|
staff.setUserId(user.getId());
|
||||||
@@ -94,4 +100,17 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void verifyEmailAndTel(Staff staff) {
|
||||||
|
String email = staff.getEmail();
|
||||||
|
String tel = staff.getTel();
|
||||||
|
String emailPattern = "^\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}$";
|
||||||
|
String telPattern = "0?(13|14|15|17|18|19)[0-9]{9}";
|
||||||
|
if (StringUtils.hasText(email) && !Pattern.matches(emailPattern, email)) {
|
||||||
|
throw new DataValidationFailedException();
|
||||||
|
}
|
||||||
|
if (StringUtils.hasText(tel) && !Pattern.matches(telPattern, tel)) {
|
||||||
|
throw new DataValidationFailedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,6 +200,20 @@ import { ElMessage } from 'element-plus'
|
|||||||
export default {
|
export default {
|
||||||
name: 'StaffManagement',
|
name: 'StaffManagement',
|
||||||
data() {
|
data() {
|
||||||
|
const checkEmail = (rule, value, callback) => {
|
||||||
|
if (value && !/^\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}$/.test(value)) {
|
||||||
|
return callback(new Error('非法邮箱地址'))
|
||||||
|
} else {
|
||||||
|
return callback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const checkTel = (rule, value, callback) => {
|
||||||
|
if (value && !/^0?(13|14|15|17|18|19)[0-9]{9}$/.test(value)) {
|
||||||
|
return callback(new Error('非法手机号码'))
|
||||||
|
} else {
|
||||||
|
return callback()
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
dialogVisible: false,
|
dialogVisible: false,
|
||||||
tableLoading: true,
|
tableLoading: true,
|
||||||
@@ -232,6 +246,18 @@ export default {
|
|||||||
required: true,
|
required: true,
|
||||||
message: '姓氏为必填项'
|
message: '姓氏为必填项'
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
inputEmail: [
|
||||||
|
{
|
||||||
|
validator: checkEmail,
|
||||||
|
message: '非法邮箱地址'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
inputTel: [
|
||||||
|
{
|
||||||
|
validator: checkTel,
|
||||||
|
message: '非法手机号码'
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
departments: [],
|
departments: [],
|
||||||
|
|||||||
Reference in New Issue
Block a user