发送电子邮件验证码

This commit is contained in:
swr 2024-05-23 15:02:13 +08:00
parent cc36894089
commit 26e43f434e
1 changed files with 22 additions and 0 deletions

View File

@ -1,5 +1,6 @@
package com.kening.vordm.controller; package com.kening.vordm.controller;
import com.kening.vordm.entity.Email;
import com.kening.vordm.service.DisasterInfoService; import com.kening.vordm.service.DisasterInfoService;
import com.kening.vordm.service.EmailService; import com.kening.vordm.service.EmailService;
import com.kening.vordm.vo.UserVo; import com.kening.vordm.vo.UserVo;
@ -8,6 +9,7 @@ import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import java.util.Random;
@RestController @RestController
@RequiredArgsConstructor @RequiredArgsConstructor
@ -59,4 +61,24 @@ public class LoginController {
public R getBladeUserByEmail(String email) { public R getBladeUserByEmail(String email) {
return R.data(disasterInfoService.getBladeUserByEmail(email)); return R.data(disasterInfoService.getBladeUserByEmail(email));
} }
/**
* 发送电子邮件验证码
* @return
* @throws MessagingException
*/
@GetMapping("/sendEmailVerificationCode")
public R sendEmailVerificationCode(String emailUrl) throws MessagingException {
Email email = new Email();
Random random = new Random();
int randomNumber = random.nextInt(999999);
String formattedNumber = String.format("%06d", randomNumber);
email.setSubject("[VoRDM] Please verify your device");
email.setText("Verification code: "+formattedNumber);
email.setHtmlText(false);
email.setTos(emailUrl.split(","));
emailService.sendMimeMessage(email);
return R.data(formattedNumber);
}
} }