-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add a status code * EmailIdentifyingException.java feat: add a definition of exception * feat: add a definition of exception * feat: add a tool about email check * feat: add a email check service * feat: add a Reposiroty class to exchange with Redis * feat: definition entity of model html * feat: add email model html * feat: add two api * feat: add a default mail against error * feat: add a annotation * feat: add a validator * feat: add a dependencies * fix: 修复 validate 使用上的一些问题 * feat: add a definition of exception * feat: add predicate of email pattern * feat: add some status code * feat: close a worthless log property * feat: change some properties * fix: adjust some code * fix: 调整代码位置,更改代码逻辑,还有点待做明天搞 * fix: delete some unrelated code * fix: modify the definition of status codes * fix: delete some blank link * fix: adjust the code to separate RedisCache * fix: delete some sensitive properties * feat: add some methods * feat: change to a detail name * extract email verification service * fix: adjust some codes * fix: fix a bug * feat: add a check opportunities for users * fix: code format and location * fix: code reformat * feat: delete a file * fix: add timeout * improve email exception handling * fix: adjust some codes * fix: adjust some codes * feat: add a global exception * fix: remove a file * fix: adjust the code about handling exception * feat: check email pattern because the annotation is invalid * fix: adjust some code * feat: add some commom method * fix: adjust som codes * fix: fix a bug * fix: adjust some codes * feat: move two files * feat: add configuration to prevent errors * fix: remove two files * fix: adjust the overall logic of the code * fix: rename some field and files * feat: add some method * fix: move some files * fix: remove some files * fix: * feat: add a todo mask --------- Co-authored-by: s:103 <mamingsheng103@yeah.net> Co-authored-by: BanTanger <1290288968@qq.com>
- Loading branch information
1 parent
b5d068e
commit e389bf8
Showing
44 changed files
with
859 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/com/achobeta/domain/email/component/EmailValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.achobeta.domain.email.component; | ||
|
||
public class EmailValidator { | ||
|
||
public static final String EMAIL_PATTERN = "^[\\w\\.-]+@[a-zA-Z\\d\\.-]+\\.[a-zA-Z]{2,}$"; | ||
|
||
public static boolean isEmailAccessible(String email) { | ||
return email.matches(EMAIL_PATTERN); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/com/achobeta/domain/email/controller/EmailController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.achobeta.domain.email.controller; | ||
|
||
import com.achobeta.common.SystemJsonResponse; | ||
import com.achobeta.domain.email.service.EmailService; | ||
import com.achobeta.domain.email.util.IdentifyingCodeValidator; | ||
import jakarta.validation.constraints.Email; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Validated | ||
@RequestMapping("/api/v1/email") | ||
public class EmailController { | ||
|
||
private final EmailService emailService; | ||
|
||
/** | ||
* 发送验证码接口 | ||
* | ||
* @param email | ||
* @return | ||
*/ | ||
@PostMapping("/check") | ||
public SystemJsonResponse emailIdentityCheck(@RequestParam("email") @Email String email) { | ||
// 获得随机验证码 | ||
String code = IdentifyingCodeValidator.getIdentifyingCode(); | ||
emailService.sendIdentifyingCode(email, code); | ||
// 能到这一步就成功了 | ||
log.info("发送验证码:{} -> email:{}", code, email); | ||
return SystemJsonResponse.SYSTEM_SUCCESS(); | ||
} | ||
|
||
@PostMapping("/check/{code}") | ||
public SystemJsonResponse checkCode(@RequestParam("email") @Email String email, | ||
@PathVariable("code") @NonNull String code) { | ||
// 验证 | ||
emailService.checkIdentifyingCode(email, code); | ||
// 成功 | ||
log.info("email:{}, 验证码:{} 验证成功", email, code); | ||
return SystemJsonResponse.SYSTEM_SUCCESS(); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/achobeta/domain/email/model/vo/VerificationCodeTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.achobeta.domain.email.model.vo; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
/** | ||
* 生命周期只有一次,成员变量对修改关闭,直接通过 builder 构建对象 | ||
*/ | ||
@Getter | ||
@Builder | ||
public class VerificationCodeTemplate { | ||
|
||
private String code; // 验证码 | ||
|
||
private int minutes; // 过期时间分钟数 | ||
|
||
} |
Oops, something went wrong.