修改注册
parent
e2c185ce66
commit
c5be5020fa
1
pom.xml
1
pom.xml
|
@ -65,6 +65,7 @@
|
||||||
<artifactId>spring-boot-starter-mail</artifactId>
|
<artifactId>spring-boot-starter-mail</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -2,9 +2,8 @@ package com.four.auth.controller;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import com.four.auth.form.HealthRegisterBody;
|
|
||||||
import com.four.auth.service.SysMailService;
|
import com.four.auth.service.SysMailService;
|
||||||
import com.four.common.duck.interrogation.RegistrationInformation;
|
import com.four.common.duck.request.RequestRegistrationInformation;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import com.four.auth.form.LoginBody;
|
import com.four.auth.form.LoginBody;
|
||||||
|
@ -25,8 +24,7 @@ import com.four.system.api.model.LoginUser;
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
public class TokenController
|
public class TokenController {
|
||||||
{
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TokenService tokenService;
|
private TokenService tokenService;
|
||||||
|
|
||||||
|
@ -37,8 +35,7 @@ public class TokenController
|
||||||
private SysMailService sysMailService;
|
private SysMailService sysMailService;
|
||||||
|
|
||||||
@PostMapping("login")
|
@PostMapping("login")
|
||||||
public R<?> login(@RequestBody LoginBody form)
|
public R<?> login(@RequestBody LoginBody form) {
|
||||||
{
|
|
||||||
// 用户登录
|
// 用户登录
|
||||||
LoginUser userInfo = sysLoginService.login(form.getEmail(), form.getPassword());
|
LoginUser userInfo = sysLoginService.login(form.getEmail(), form.getPassword());
|
||||||
// 获取登录token
|
// 获取登录token
|
||||||
|
@ -46,19 +43,17 @@ public class TokenController
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("userLogin")
|
@PostMapping("userLogin")
|
||||||
public R<?> userLogin(@RequestBody LoginBody form){
|
public R<?> userLogin(@RequestBody LoginBody form) {
|
||||||
|
|
||||||
LoginUser loginUser = sysLoginService.userLogin(form.getUsername(),form.getPassword());
|
LoginUser loginUser = sysLoginService.userLogin(form.getUsername(), form.getPassword());
|
||||||
|
|
||||||
return R.ok(tokenService.createToken(loginUser));
|
return R.ok(tokenService.createToken(loginUser));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("logout")
|
@DeleteMapping("logout")
|
||||||
public R<?> logout(HttpServletRequest request)
|
public R<?> logout(HttpServletRequest request) {
|
||||||
{
|
|
||||||
String token = SecurityUtils.getToken(request);
|
String token = SecurityUtils.getToken(request);
|
||||||
if (StringUtils.isNotEmpty(token))
|
if (StringUtils.isNotEmpty(token)) {
|
||||||
{
|
|
||||||
String username = JwtUtils.getUserName(token);
|
String username = JwtUtils.getUserName(token);
|
||||||
// 删除用户缓存记录
|
// 删除用户缓存记录
|
||||||
AuthUtil.logoutByToken(token);
|
AuthUtil.logoutByToken(token);
|
||||||
|
@ -69,11 +64,9 @@ public class TokenController
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("refresh")
|
@PostMapping("refresh")
|
||||||
public R<?> refresh(HttpServletRequest request)
|
public R<?> refresh(HttpServletRequest request) {
|
||||||
{
|
|
||||||
LoginUser loginUser = tokenService.getLoginUser(request);
|
LoginUser loginUser = tokenService.getLoginUser(request);
|
||||||
if (StringUtils.isNotNull(loginUser))
|
if (StringUtils.isNotNull(loginUser)) {
|
||||||
{
|
|
||||||
// 刷新令牌有效期
|
// 刷新令牌有效期
|
||||||
tokenService.refreshToken(loginUser);
|
tokenService.refreshToken(loginUser);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
|
@ -82,28 +75,31 @@ public class TokenController
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("register")
|
@PostMapping("register")
|
||||||
public R<?> register(@RequestBody RegisterBody registerBody)
|
public R<?> register(@RequestBody RegisterBody registerBody) {
|
||||||
{
|
|
||||||
// 用户注册
|
// 用户注册
|
||||||
sysLoginService.register(registerBody.getUsername(), registerBody.getPassword());
|
sysLoginService.register(registerBody.getUsername(), registerBody.getPassword());
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 医生注册
|
||||||
|
*
|
||||||
|
* @param healthRegisterBody
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@PostMapping("healthRegisterBody")
|
@PostMapping("healthRegisterBody")
|
||||||
public R<?> healthRegisterBody(@RequestBody HealthRegisterBody healthRegisterBody){
|
public R<?> healthRegisterBody(@RequestBody RequestRegistrationInformation requestRegistrationInformation) {
|
||||||
|
|
||||||
sysMailService.verifyCode(healthRegisterBody.getEmail(),healthRegisterBody.getCode());
|
sysMailService.verifyCode(requestRegistrationInformation.getEmail(), requestRegistrationInformation.getCode());
|
||||||
|
|
||||||
sysLoginService.healthRegister(healthRegisterBody);
|
sysLoginService.healthRegister(requestRegistrationInformation);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/sendCode/{email}")
|
@GetMapping("/sendCode/{email}")
|
||||||
public R<?> sendCode(@PathVariable String email){
|
public R<?> sendCode(@PathVariable String email) {
|
||||||
sysMailService.sendCode(email);
|
sysMailService.sendCode(email);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,151 +0,0 @@
|
||||||
package com.four.auth.form;
|
|
||||||
|
|
||||||
public class HealthRegisterBody extends LoginBody{
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 邀请码
|
|
||||||
* */
|
|
||||||
private String invitationCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 真实姓名
|
|
||||||
* */
|
|
||||||
private String realName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 个人简历
|
|
||||||
* */
|
|
||||||
private String personalResume;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 形象地址
|
|
||||||
* */
|
|
||||||
private String avatar;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 所属医院
|
|
||||||
*/
|
|
||||||
private String affiliatedHospital;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 擅长领域
|
|
||||||
* */
|
|
||||||
private String areaExpertise;
|
|
||||||
/**
|
|
||||||
* 昵称
|
|
||||||
* */
|
|
||||||
private String nickName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 职称id
|
|
||||||
* */
|
|
||||||
private Long professionalTitleDoctorId;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 性别
|
|
||||||
* */
|
|
||||||
private String sex;
|
|
||||||
|
|
||||||
public HealthRegisterBody(String invitationCode, String realName, String personalResume, String avatar, String affiliatedHospital, String nickName, Long professionalTitleDoctorId, String sex) {
|
|
||||||
this.invitationCode = invitationCode;
|
|
||||||
this.realName = realName;
|
|
||||||
this.personalResume = personalResume;
|
|
||||||
this.avatar = avatar;
|
|
||||||
this.affiliatedHospital = affiliatedHospital;
|
|
||||||
this.nickName = nickName;
|
|
||||||
this.professionalTitleDoctorId = professionalTitleDoctorId;
|
|
||||||
this.sex = sex;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "HealthRegisterBody{" +
|
|
||||||
"invitationCode='" + invitationCode + '\'' +
|
|
||||||
", realName='" + realName + '\'' +
|
|
||||||
", personalResume='" + personalResume + '\'' +
|
|
||||||
", avatar='" + avatar + '\'' +
|
|
||||||
", affiliatedHospital='" + affiliatedHospital + '\'' +
|
|
||||||
", nickName='" + nickName + '\'' +
|
|
||||||
", professionalTitleDoctorId=" + professionalTitleDoctorId +
|
|
||||||
", sex='" + sex + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
public HealthRegisterBody() {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Long getProfessionalTitleDoctorId() {
|
|
||||||
return professionalTitleDoctorId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProfessionalTitleDoctorId(Long professionalTitleDoctorId) {
|
|
||||||
this.professionalTitleDoctorId = professionalTitleDoctorId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSex() {
|
|
||||||
return sex;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSex(String sex) {
|
|
||||||
this.sex = sex;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAreaExpertise() {
|
|
||||||
return areaExpertise;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAreaExpertise(String areaExpertise) {
|
|
||||||
this.areaExpertise = areaExpertise;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInvitationCode(String invitationCode) {
|
|
||||||
this.invitationCode = invitationCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRealName(String realName) {
|
|
||||||
this.realName = realName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPersonalResume(String personalResume) {
|
|
||||||
this.personalResume = personalResume;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAvatar(String avatar) {
|
|
||||||
this.avatar = avatar;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAffiliatedHospital(String affiliatedHospital) {
|
|
||||||
this.affiliatedHospital = affiliatedHospital;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNickName(String nickName) {
|
|
||||||
this.nickName = nickName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getInvitationCode() {
|
|
||||||
return invitationCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRealName() {
|
|
||||||
return realName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPersonalResume() {
|
|
||||||
return personalResume;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAvatar() {
|
|
||||||
return avatar;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAffiliatedHospital() {
|
|
||||||
return affiliatedHospital;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNickName() {
|
|
||||||
return nickName;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +1,5 @@
|
||||||
package com.four.auth.service;
|
package com.four.auth.service;
|
||||||
|
|
||||||
import com.four.auth.form.HealthRegisterBody;
|
|
||||||
import com.four.auth.form.RegisterBody;
|
|
||||||
import org.apache.catalina.Contained;
|
|
||||||
import org.apache.catalina.User;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import com.four.common.core.constant.CacheConstants;
|
import com.four.common.core.constant.CacheConstants;
|
||||||
|
@ -21,9 +17,9 @@ import com.four.common.security.utils.SecurityUtils;
|
||||||
import com.four.system.api.RemoteUserService;
|
import com.four.system.api.RemoteUserService;
|
||||||
import com.four.system.api.domain.SysUser;
|
import com.four.system.api.domain.SysUser;
|
||||||
import com.four.system.api.model.LoginUser;
|
import com.four.system.api.model.LoginUser;
|
||||||
import org.springframework.stereotype.Service;
|
import com.four.common.duck.request.RequestRegistrationInformation;
|
||||||
|
|
||||||
import java.util.GregorianCalendar;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录校验方法
|
* 登录校验方法
|
||||||
|
@ -99,6 +95,7 @@ public class SysLoginService
|
||||||
recordLogService.recordLogininfors(email, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
recordLogService.recordLogininfors(email, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
||||||
throw new ServiceException("对不起,您的账号:" + email + " 已被删除");
|
throw new ServiceException("对不起,您的账号:" + email + " 已被删除");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
|
if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
|
||||||
{
|
{
|
||||||
recordLogService.recordLogininfors(email, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
|
recordLogService.recordLogininfors(email, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
|
||||||
|
@ -149,6 +146,8 @@ public class SysLoginService
|
||||||
recordLogService.recordLogininfor(userName, Constants.REGISTER, "注册成功");
|
recordLogService.recordLogininfor(userName, Constants.REGISTER, "注册成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public LoginUser userLogin(String userName, String password) {
|
public LoginUser userLogin(String userName, String password) {
|
||||||
|
|
||||||
if(StringUtils.isAllBlank(userName,password)){
|
if(StringUtils.isAllBlank(userName,password)){
|
||||||
|
@ -203,55 +202,43 @@ public class SysLoginService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void healthRegister(HealthRegisterBody healthRegisterBody) {
|
/**
|
||||||
|
* 医生注册
|
||||||
|
* @param registrationInformation
|
||||||
|
*/
|
||||||
|
public void healthRegister(RequestRegistrationInformation requestRegistrationInformation) {
|
||||||
|
|
||||||
if(StringUtils.isAllBlank(healthRegisterBody.getUsername(),healthRegisterBody.getPassword())){
|
if(StringUtils.isAllBlank(requestRegistrationInformation.getRealName(),requestRegistrationInformation.getPassword())){
|
||||||
throw new ServiceException("用户/密码必须填写");
|
throw new ServiceException("用户/密码必须填写");
|
||||||
}
|
}
|
||||||
if(healthRegisterBody.getPassword().length() < UserConstants.PASSWORD_MIN_LENGTH
|
if(requestRegistrationInformation.getPassword().length() < UserConstants.PASSWORD_MIN_LENGTH
|
||||||
|| healthRegisterBody.getPassword().length()> UserConstants.PASSWORD_MAX_LENGTH){
|
|| requestRegistrationInformation.getPassword().length()> UserConstants.PASSWORD_MAX_LENGTH){
|
||||||
throw new ServiceException("密码长度必须在5到20个字符");
|
throw new ServiceException("密码长度必须在5到20个字符");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
requestRegistrationInformation.setPassword(SecurityUtils.encryptPassword(requestRegistrationInformation.getPassword()));
|
||||||
|
|
||||||
SysUser sysUser = new SysUser();
|
SysUser sysUser = new SysUser();
|
||||||
sysUser.setRoleId(healthRegisterBody.getRoleId());
|
sysUser.setDeptId(3L);
|
||||||
sysUser.setUserName(healthRegisterBody.getUserName());
|
sysUser.setBindWechatStatus(1);
|
||||||
sysUser.setEmail(healthRegisterBody.getEmail());
|
sysUser.setRealNameAuthenticationStatus(1);
|
||||||
sysUser.setNickName(healthRegisterBody.getNickName());
|
sysUser.setBindBankCardStatus(1);
|
||||||
sysUser.setPassword(SecurityUtils.encryptPassword(healthRegisterBody.getPassword()));
|
sysUser.setDifferentialState(2);
|
||||||
|
sysUser.setStatus("0");
|
||||||
|
sysUser.setUserMoney(new BigDecimal(0));
|
||||||
|
sysUser.setEmail(requestRegistrationInformation.getEmail());
|
||||||
|
sysUser.setNickName(requestRegistrationInformation.getRealName());
|
||||||
|
sysUser.setPassword(SecurityUtils.encryptPassword(requestRegistrationInformation.getPassword()));
|
||||||
|
sysUser.setUserName(requestRegistrationInformation.getRealName());
|
||||||
|
|
||||||
if(healthRegisterBody.getRoleId() == 100){
|
|
||||||
|
|
||||||
//职称Id
|
|
||||||
sysUser.setRoleId(healthRegisterBody.getRoleId());
|
|
||||||
|
|
||||||
//真实姓名
|
|
||||||
sysUser.setNickName(healthRegisterBody.getNickName());
|
|
||||||
|
|
||||||
//个人简历
|
|
||||||
sysUser.setPersonalResume(healthRegisterBody.getPersonalResume());
|
|
||||||
|
|
||||||
//所属医院
|
|
||||||
sysUser.setAffiliatedHospital(healthRegisterBody.getAffiliatedHospital());
|
|
||||||
|
|
||||||
//area_expertise
|
|
||||||
sysUser.setAreaExpertise(healthRegisterBody.getAreaExpertise());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(healthRegisterBody.getRoleId() == 101){
|
|
||||||
/**
|
|
||||||
* 邀请码
|
|
||||||
* */
|
|
||||||
sysUser.setInvitationCode(healthRegisterBody.getInvitationCode());
|
|
||||||
/**
|
|
||||||
* 性别
|
|
||||||
* */
|
|
||||||
sysUser.setSex(healthRegisterBody.getSex());
|
|
||||||
}
|
|
||||||
System.out.println(sysUser);
|
System.out.println(sysUser);
|
||||||
|
|
||||||
R<?> registerResult = remoteUserService.healthRegister(sysUser, SecurityConstants.INNER);
|
R<?> registerResult = remoteUserService.healthRegister(sysUser, SecurityConstants.INNER);
|
||||||
|
|
||||||
if(R.FAIL == registerResult.getCode()){
|
if(R.FAIL == registerResult.getCode()){
|
||||||
throw new ServiceException(registerResult.getMsg());
|
throw new ServiceException(registerResult.getMsg());
|
||||||
}
|
}
|
||||||
recordLogService.recordLogininfor(healthRegisterBody.getEmail(), Constants.REGISTER,"注册成功");
|
recordLogService.recordLogininfor(requestRegistrationInformation.getEmail(), Constants.REGISTER,"注册成功");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class SysMailService {
|
||||||
try {
|
try {
|
||||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
|
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
|
||||||
helper.setFrom("1733802689@qq.com");
|
helper.setFrom("1733802689@qq.com");
|
||||||
helper.setText(verifyCode);
|
helper.setText("验证码为:"+verifyCode);
|
||||||
helper.setTo(email);
|
helper.setTo(email);
|
||||||
helper.setSubject("我来发邮件来了");
|
helper.setSubject("我来发邮件来了");
|
||||||
javaMailSender.send(mimeMessage);
|
javaMailSender.send(mimeMessage);
|
||||||
|
|
Loading…
Reference in New Issue