移除用户注册功能,移除相关接口和监听器逻辑
This commit is contained in:
parent
f79445ad0b
commit
39f2de6628
@ -2,7 +2,9 @@
|
||||
<module type="GENERAL_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/log" />
|
||||
</content>
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -2,7 +2,6 @@ package com.example.controller;
|
||||
|
||||
import com.example.entity.RestBean;
|
||||
import com.example.entity.vo.request.ConfirmResetVO;
|
||||
import com.example.entity.vo.request.EmailRegisterVO;
|
||||
import com.example.entity.vo.request.EmailResetVO;
|
||||
import com.example.service.AccountService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@ -39,24 +38,12 @@ public class AuthorizeController {
|
||||
@GetMapping("/ask-code")
|
||||
@Operation(summary = "请求邮件验证码")
|
||||
public RestBean<Void> askVerifyCode(@RequestParam @Email String email,
|
||||
@RequestParam @Pattern(regexp = "(register|reset)") String type,
|
||||
@RequestParam @Pattern(regexp = "(reset)") String type,
|
||||
HttpServletRequest request){
|
||||
return this.messageHandle(() ->
|
||||
accountService.registerEmailVerifyCode(type, String.valueOf(email), request.getRemoteAddr()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 进行用户注册操作,需要先请求邮件验证码
|
||||
* @param vo 注册信息
|
||||
* @return 是否注册成功
|
||||
*/
|
||||
@PostMapping("/register")
|
||||
@Operation(summary = "用户注册操作")
|
||||
public RestBean<Void> register(@RequestBody @Valid EmailRegisterVO vo){
|
||||
return this.messageHandle(() ->
|
||||
accountService.registerEmailAccount(vo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行密码重置确认,检查验证码是否正确
|
||||
* @param vo 密码重置信息
|
||||
|
@ -1,22 +0,0 @@
|
||||
package com.example.entity.vo.request;
|
||||
|
||||
import jakarta.validation.constraints.Email;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
/**
|
||||
* 用户注册表单信息
|
||||
*/
|
||||
@Data
|
||||
public class EmailRegisterVO {
|
||||
@Email
|
||||
String email;
|
||||
@Length(max = 6, min = 6)
|
||||
String code;
|
||||
@Pattern(regexp = "^[a-zA-Z0-9\\u4e00-\\u9fa5]+$")
|
||||
@Length(min = 1, max = 10)
|
||||
String username;
|
||||
@Length(min = 6, max = 20)
|
||||
String password;
|
||||
}
|
@ -32,10 +32,6 @@ public class MailQueueListener {
|
||||
String email = data.get("email").toString();
|
||||
Integer code = (Integer) data.get("code");
|
||||
SimpleMailMessage message = switch (data.get("type").toString()) {
|
||||
case "register" ->
|
||||
createMessage("欢迎注册我们的网站",
|
||||
"您的邮件注册验证码为: "+code+",有效时间3分钟,为了保障您的账户安全,请勿向他人泄露验证码信息。",
|
||||
email);
|
||||
case "reset" ->
|
||||
createMessage("您的密码重置邮件",
|
||||
"你好,您正在执行重置密码操作,验证码: "+code+",有效时间3分钟,如非本人操作,请无视。",
|
||||
|
@ -3,14 +3,12 @@ package com.example.service;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.example.entity.dto.Account;
|
||||
import com.example.entity.vo.request.ConfirmResetVO;
|
||||
import com.example.entity.vo.request.EmailRegisterVO;
|
||||
import com.example.entity.vo.request.EmailResetVO;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
|
||||
public interface AccountService extends IService<Account>, UserDetailsService {
|
||||
Account findAccountByNameOrEmail(String text);
|
||||
String registerEmailVerifyCode(String type, String email, String address);
|
||||
String registerEmailAccount(EmailRegisterVO info);
|
||||
String resetEmailAccountPassword(EmailResetVO info);
|
||||
String resetConfirm(ConfirmResetVO info);
|
||||
}
|
||||
|
@ -1,17 +1,14 @@
|
||||
package com.example.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.example.entity.dto.Account;
|
||||
import com.example.entity.vo.request.ConfirmResetVO;
|
||||
import com.example.entity.vo.request.EmailRegisterVO;
|
||||
import com.example.entity.vo.request.EmailResetVO;
|
||||
import com.example.mapper.AccountMapper;
|
||||
import com.example.service.AccountService;
|
||||
import com.example.utils.Const;
|
||||
import com.example.utils.FlowUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.amqp.core.AmqpTemplate;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
@ -21,7 +18,6 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -87,30 +83,6 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮件验证码注册账号操作,需要检查验证码是否正确以及邮箱、用户名是否存在重名
|
||||
* @param info 注册基本信息
|
||||
* @return 操作结果,null表示正常,否则为错误原因
|
||||
*/
|
||||
public String registerEmailAccount(EmailRegisterVO info){
|
||||
String email = info.getEmail();
|
||||
String code = this.getEmailVerifyCode(email);
|
||||
if(code == null) return "请先获取验证码";
|
||||
if(!code.equals(info.getCode())) return "验证码错误,请重新输入";
|
||||
if(this.existsAccountByEmail(email)) return "该邮件地址已被注册";
|
||||
String username = info.getUsername();
|
||||
if(this.existsAccountByUsername(username)) return "该用户名已被他人使用,请重新更换";
|
||||
String password = passwordEncoder.encode(info.getPassword());
|
||||
Account account = new Account(null, info.getUsername(),
|
||||
password, email, Const.ROLE_DEFAULT, new Date());
|
||||
if(!this.save(account)) {
|
||||
return "内部错误,注册失败";
|
||||
} else {
|
||||
this.deleteEmailVerifyCode(email);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮件验证码重置密码操作,需要检查验证码是否正确
|
||||
* @param info 重置基本信息
|
||||
@ -183,22 +155,4 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
.eq("email", text)
|
||||
.one();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定邮箱的用户是否已经存在
|
||||
* @param email 邮箱
|
||||
* @return 是否存在
|
||||
*/
|
||||
private boolean existsAccountByEmail(String email){
|
||||
return this.baseMapper.exists(Wrappers.<Account>query().eq("email", email));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定用户名的用户是否已经存在
|
||||
* @param username 用户名
|
||||
* @return 是否存在
|
||||
*/
|
||||
private boolean existsAccountByUsername(String username){
|
||||
return this.baseMapper.exists(Wrappers.<Account>query().eq("username", username));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user