Skip to content

Commit

Permalink
verify
Browse files Browse the repository at this point in the history
  • Loading branch information
Qi-Zhen-xin committed Jun 10, 2024
1 parent 31cc358 commit 3be8628
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import com.qzx.xdupartner.entity.vo.ResultCode;
import com.qzx.xdupartner.exception.APIException;
import com.qzx.xdupartner.service.BlogService;
import com.qzx.xdupartner.service.UserService;
import com.qzx.xdupartner.util.RUtil;
import com.qzx.xdupartner.util.UserHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
Expand Down Expand Up @@ -39,6 +41,8 @@ public class BlogController {

@Resource
private BlogService blogService;
@Resource
private UserService userService;

@ApiOperation("点赞")
@GetMapping("/like/{id}")
Expand All @@ -51,6 +55,9 @@ public R<String> likeBlog(@Validated @PathVariable("id") Long id) {
@ApiOperation("发布帖子")
@PostMapping(value = "/publish", produces = "application/json;charset=utf-8")
public R<String> publishBlogV2(@Validated @RequestBody @NotNull(message = "需要提交帖子") BlogDto blogDto) {
if (!userService.checkUserIsVerified(UserHolder.getUserId())) {
return RUtil.error(ResultCode.UNVERIFIED_ERROR);
}
checkListInBlogDto(blogDto);
Blog blog = convertToBlog(blogDto);
blogService.saveBlog(blog, doExplainTags(blogDto));
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/qzx/xdupartner/controller/VerifyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,28 @@ public R<String> sendEmailCode(@RequestParam String stuId) {
RUtil.error(ResultCode.MAIL_SEND_ERROR);
}

@ApiOperation("")
@GetMapping("/email/verify")
public R<String> verifyEmailCode(@RequestParam String stuId, @RequestParam String code) {
if (!(StrUtil.isNumeric(stuId) && stuId.length() == 11)) {
return new R<>(ResultCode.STU_ID_ERROR);
}
if (userService.checkUserIsVerified(UserHolder.getUserId())) {
return RUtil.error(ResultCode.HAS_VERIFIED_ERROR);
}
//验证邮箱
String realCode = stringRedisTemplate.opsForValue().get(RedisConstant.MAIL_CODE_PREFIX + stuId);
if (!code.equals(realCode)) {
return RUtil.error(ResultCode.MAIL_CODE_ERROR);
}
boolean update = userService.lambdaUpdate().eq(User::getId, UserHolder.getUserId()).set(User::getStuId,
stuId).update();
if (!update) {
return RUtil.error(ResultCode.UNKNOWN_ERROR);
}
return RUtil.success("认证成功");
}

@ApiOperation("")
@GetMapping("/phone/send")
public R<String> sendPhoneVerCode(@RequestParam String phone) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/qzx/xdupartner/entity/vo/ResultCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public enum ResultCode implements StatusCode {
MESSAGE_SEND_ERROR(2011, "发送短信失败,请稍后再试"),
MESSAGE_HAS_SENT_ERROR(2012, "短信5分钟内有效,请勿重复发送"),
VERIFY_TOKEN_ERROR(2013, "token不存在"),
PHONE_VERIFY_ERROR(2014, "验证码错误");
PHONE_VERIFY_ERROR(2014, "验证码错误"),
UNVERIFIED_ERROR(2015, "账号未进行认证,进行认证后才可发帖");
@ApiModelProperty("返回状态码")
private final int code;
@ApiModelProperty("信息-错误时用其内容")
Expand Down

0 comments on commit 3be8628

Please sign in to comment.