发送电子邮件验证码
This commit is contained in:
parent
cc36894089
commit
26e43f434e
|
@ -1,5 +1,6 @@
|
|||
package com.kening.vordm.controller;
|
||||
|
||||
import com.kening.vordm.entity.Email;
|
||||
import com.kening.vordm.service.DisasterInfoService;
|
||||
import com.kening.vordm.service.EmailService;
|
||||
import com.kening.vordm.vo.UserVo;
|
||||
|
@ -8,6 +9,7 @@ import org.springblade.core.tool.api.R;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import java.util.Random;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
|
@ -59,4 +61,24 @@ public class LoginController {
|
|||
public R getBladeUserByEmail(String 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue