| | |
| | | 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) { |