| | |
| | | public class GuideRegistrationService { |
| | | private static final int PENDING = 0; |
| | | private static final int APPROVED = 1; |
| | | private static final String REGISTRATION_SCENE = "registration"; |
| | | private static final Duration TOKEN_TTL = Duration.ofMinutes(30); |
| | | private static final String TOKEN_KEY_PREFIX = "tourguide:guide-registration:token:"; |
| | | private static final DateTimeFormatter APPLICATION_NO_TIME = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); |
| | |
| | | |
| | | public GuideRegistrationTokenResponse verifyPhone(String phone, String code) { |
| | | ensurePhoneCanRegister(phone); |
| | | verificationCodeService.verifyAndConsume(phone, code); |
| | | verificationCodeService.verifyAndConsume(phone, code, REGISTRATION_SCENE); |
| | | String token = UUID.randomUUID().toString().replace("-", ""); |
| | | redisTemplate.opsForValue().set(tokenKey(token), phone, TOKEN_TTL); |
| | | return new GuideRegistrationTokenResponse(token, TOKEN_TTL.getSeconds()); |
| | |
| | | |
| | | public SmsCodeResponse sendCode(String phone) { |
| | | ensurePhoneCanRegister(phone); |
| | | return verificationCodeService.send(phone); |
| | | return verificationCodeService.send(phone, REGISTRATION_SCENE); |
| | | } |
| | | |
| | | public String requireVerifiedPhone(String registrationToken) { |
| | |
| | | } |
| | | if (applicationMapper.selectCount(new LambdaQueryWrapper<GuideApplication>() |
| | | .eq(GuideApplication::getIdCardNo, idCardNo) |
| | | .ne(GuideApplication::getMobile, phone) |
| | | .in(GuideApplication::getAuditStatus, PENDING, APPROVED)) > 0) { |
| | | throw new BusinessException(409, "该身份证号已提交过导游申请"); |
| | | } |
| | |
| | | |
| | | private void ensurePhoneCanRegister(String phone) { |
| | | com.tourguide.modules.user.entity.GuideUser guide = guideUserService.findByPhone(phone); |
| | | if (guide != null && (guide.getStatus() == null || guide.getStatus() != 2)) { |
| | | if (guide != null && (guide.getStatus() == null |
| | | || (guide.getStatus() != GuideUserService.STATUS_PENDING |
| | | && guide.getStatus() != GuideUserService.STATUS_CANCELLED))) { |
| | | throw new BusinessException(409, "该手机号已注册为导游"); |
| | | } |
| | | if (applicationMapper.selectCount(new LambdaQueryWrapper<GuideApplication>() |